[ Warning (2) ](javascript:void(0);): Attempt to read property “mobile” on null [in /srv/canteen1/app/templates/Users/index.php, line 29]
error comes on list users
index.php is
user.php in model is
protected $_accessible = [
‘username’ => true,
‘email’ => true,
‘password’ => true,
‘created’ => true,
‘modified’ => true,
‘contact’ => true,
‘skills’ => true,
];
usertable.php in model is
*/
public function initialize(array $config): void
{
parent::initialize($config);
$this->setTable('users');
$this->setDisplayField('id');
$this->setPrimaryKey('id');
$this->addBehavior('Timestamp');
$this->hasOne('Contacts');/*
$this->hasMany('Contacts', [
'foreignKey' => 'user_id',
]); */
$this->hasMany('Skills');
}
/**
userscontroller.php is
public function index()
{
$users = $this->paginate($this->Users);
$this->set(compact('users'));
}
/**
* View method
*
* @param string|null $id User id.
* @return \Cake\Http\Response|null|void Renders view
* @throws \Cake\Datasource\Exception\RecordNotFoundException When record not found.
*/
public function view($id = null)
{
$user = $this->Users->get($id, ['contain' => ['Contacts']]);
$this->set(compact('user'));
}