0
$value = app\models\SectionTranslation::find()
 ->select(['section_id', 'name'])
 ->where(['=', 'section_id', $iSection['id']])
 ->andWhere(['=', 'language_id', $lang])
 ->one();
$nam = $value->name;

I want to use $value->name but I can't. I get "Trying to get property 'name' of non-object" error. But if I write

var_dump($nam);exit;

after the last line of code, I can show correctly the result on my screen:

string(10) "Tree" 

Any idea of the problem or the solution?

Thanks you.

Daniel
  • 49
  • 1
  • 1
  • 4
  • 1
    Please share all code where it fails. Maybe you overwrite the $value – Aram Grigoryan Jun 07 '18 at 13:01
  • 2
    Possible duplicate of [Reference - What does this error mean in PHP?](https://stackoverflow.com/questions/12769982/reference-what-does-this-error-mean-in-php) – Nigel Ren Jun 07 '18 at 13:03
  • 5
    Seems like you're looking at the wrong line. – Devon Bessemer Jun 07 '18 at 13:03
  • I would simplify the code, because you are trying to get the model object, so `$value = app\models\SectionTranslation::find() ->where(['section_id' => $iSection['id'], 'language_id' => $lang]) ->one();` test if value is not false and then try to use $value->name (or whatever property that object is supposed to have) – Nimer Jun 07 '18 at 20:08
  • @AramGrigoryan is all code shared. var_dump line is just below the first piece of code. – Daniel Jun 12 '18 at 07:04
  • @Nimer I just test it but same problem.. – Daniel Jun 12 '18 at 07:04
  • Ok is solucionated, the problem was that this part of code was into foreach, and first iteration was ok, but in 4th crashed. Thanks you. – Daniel Jun 12 '18 at 08:10

0 Answers0