Relational Models throwing PHP Notice Non-Object with actual results from Database

I have two databases on two different servers. One is a local server, the other is a remote server. The data resides on the remote server, and the models are on the local server. They are connected via the ConnectionService() method in the Model class. Both of the Models are accessing the schemas on the remote server

Now when I do

$id = 1;

$result = MyNameSpace\User::findFirst(['conditions'=>'id=?1','bind'=>[1=>$id]]);

I get my result as expected. However, I have a related model called UserAddress. It has a hasOne relation.

So when I use

$result->{'MyNameSpace\UserAddress'}->street_address

and I ouput it on the view, I get the results as expected. However, in my log files I am recieveing a notice.

PHP Notice: Trying to get property of non-object in /var/www/example/app/views/example_dir/example.phtml

Any one have any ideas on why this would be triggering a PHP notice?



27.4k

Hi,

is, in the error message, no details about the specific line in the phtml file that thrown you this error ?

Otherwise, full relevant code of Model/controller/view files could be helpfull to get any help from the forum users.

edited 13d ago

Probably because it returns null. Just set alias and use alias.