【发布时间】:2018-08-12 08:53:42
【问题描述】:
当我想检索我的用户时,我没有个人资料。 我按照约定设置了我的数据库。
我的模型(UserTable)中有以下代码:
<?php
// src/Model/Table/UsersTable.php
namespace App\Model\Table;
use Cake\ORM\Table;
class UsersTable extends Table
{
public function initialize(array $config)
{
$this->addBehavior('Timestamp');
$this->hasOne('Profiles')
->setDependent(true);
}
}
我的控制器是这样的:
<?php
// src/Controller/UsersController.php
namespace App\Controller;
class UsersController extends AppController
{
public function initialize()
{
parent::initialize();
$this->loadComponent('Paginator');
$this->loadComponent('Flash'); // Include the FlashComponent
}
public function index()
{
$query = $this->Users->find();
$results = $query->all();
$this->set(compact('results'));
}
}
调用索引后,我得到了所有用户,这是一件好事。但是没有个人资料。 我想,我在某处遗漏了一行代码。任何帮助表示赞赏。
【问题讨论】:
标签: cakephp-3.x has-one