'YII ERROR - Trying to get property 'alias' of non-object
I'm new in Yii development and I am getting an error followed by Trying to get property of non-object
Do somebody can help me please ?
1. in /var/www/vhosts/sitename/httpdocs/application/models/Profile.php at line 498
* @param $category
* @return ProfileField|array|mixed
*/
protected function getProfileFields($category)
{
if (!isset($this->_profileFields)) {
$data = [];
$fields = ProfileField::find()->joinWith('category')->visible()->sorted()->all();
foreach ($fields as $field) {
$data[$field->'category'->alias][] = $field;
}
$this->_profileFields = $data;
}
return isset($this->_profileFields[$category]) ? $this->_profileFields[$category] : [];
}
Solution 1:[1]
Change your code to:
foreach ($fields as $field) {
if ($field->category) {
$data[$field->category->alias][] = $field;
}
}
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 | Ahmad |
