Yii Framework Forum: I Have A Problem With Php 5.4.3 - Yii Framework Forum

Jump to content

Page 1 of 1
  • You cannot start a new topic
  • You cannot reply to this topic

I Have A Problem With Php 5.4.3 Trying to get property of non-object Rate Topic: -----

#1 User is offline   matthew3 

  • Newbie
  • Yii
  • Group: Members
  • Posts: 6
  • Joined: 14-June 12

Posted 14 February 2013 - 04:17 AM

I have a finished project. Has worked well. In many cases, I get an error message: Trying to get property of non-object

eg:

$this->widget('zii.widgets.grid.CGridView', array(
    'dataProvider' => $true_rows,
    'columns' => array(array('name'=>'id', 'header'=>'Sorszám'), array('name'=>'0', 'header'=>'Amount'), array('name'=>'1', 'header'=>'Operator', 'value' => 'Operators::model()->findByPk($data[1])->name'), array('name'=>'2', 'header'=>'Currency'), array('name'=>'3', 'header'=>'Username', 'value' => 'UsersOperator::model()->findByAttributes(array("userid"=>$data[3]))->fn'), array('name'=>'4', 'header'=>'Nickname', 'value' => 'UsersOperator::model()->findByAttributes(array("userid"=>$data[3]))->nick')),    
));


What is the best solution?

Thanks for the reply!
0

#2 User is offline   mirunho 

  • Standard Member
  • PipPip
  • Yii
  • Group: Members
  • Posts: 170
  • Joined: 19-December 12
  • Location:Gdansk, Poland

Posted 14 February 2013 - 05:25 AM

If you are using something like
UsersOperator::model()->findByAttributes(array("userid"=>$data[3]))->nick

and there is no data to return, error massage will report Trying to get property of non-object. You should replace every of that with expressions for example:

$somedata ? display result : no result to display

0

#3 User is offline   matthew3 

  • Newbie
  • Yii
  • Group: Members
  • Posts: 6
  • Joined: 14-June 12

Posted 14 February 2013 - 05:26 AM

View Postmatthew3, on 14 February 2013 - 04:17 AM, said:

I have a finished project. Has worked well. In many cases, I get an error message: Trying to get property of non-object

eg:

$this->widget('zii.widgets.grid.CGridView', array(
    'dataProvider' => $true_rows,
    'columns' => array(array('name'=>'id', 'header'=>'Sorszám'), array('name'=>'0', 'header'=>'Amount'), array('name'=>'1', 'header'=>'Operator', 'value' => 'Operators::model()->findByPk($data[1])->name'), array('name'=>'2', 'header'=>'Currency'), array('name'=>'3', 'header'=>'Username', 'value' => 'UsersOperator::model()->findByAttributes(array("userid"=>$data[3]))->fn'), array('name'=>'4', 'header'=>'Nickname', 'value' => 'UsersOperator::model()->findByAttributes(array("userid"=>$data[3]))->nick')),    
));


What is the best solution?

Thanks for the reply!


Preblem fixed.
Did not have the array index :)
0

Share this topic:


Page 1 of 1
  • You cannot start a new topic
  • You cannot reply to this topic

1 User(s) are reading this topic
0 members, 1 guests, 0 anonymous users