Lazy loading not working

hello every body

I’m having trouble with lazy loading .

Every thing is working fine on my developpement environement (wamp on widows).

But when i’m putting the projrct in the production environement (wampp on ubuntu) , lazy loading didn’t work .

notice that i’m using auto lazy loading.

please help !

Check file/class names. MyClass.php != myclass.php.

hello every body ,

thanks for reply.

I’ve found in other topic’s that my problem is might be caused by the case sensitive issues.

I’m sure that it’s not my problem because all my classes are generated by Gii.

i’ve now spent two weeks inthis issue , my conclusing is that :

lazy loading is not working at all in wamp seerver 2.2 and it’s working on wamp server 2.1 .

I’ have to make it work with the 2.2 and for now i didn’t find a solution.

Please help me !

this is version of the two servers , both have same php.ini and httpd.conf configuration


Wamp server 2.1 : 

Apache 2.2.17  

Php 5.3.5   

Mysql 5.5.8   

XDebug 2.1.0-5.3 

XDC 1.5  

PhpMyadmin 3.3.9     

SQLBuddy 1.3.2  

webGrind 1.0




Wamp server 2.2 : 

Apache 2.2.21  

Php 5.3.10  

Mysql 5.5.20  

XDebug  2.1.2    

XDC 1.5  

PhpMyadmin 3.4.10.1  

SQLBuddy 1.3.3  

webGrind 1.0



My conclusing is wrong !

lazy loading doesn’t work in both serser in other machine (windows, linux) .

I dont know what is installed in my environement that make it work :(

wath are requirements to lazy loading ? some php extention ? some confiuration ?

Can you post the code you are running ? My experience is that Yii is pretty solid and when things go wrong it is normally down something I did when I was sleep coding ;)

this is an exemple of my code , that might help for diagnostic my problem.

class Toto :




<?php


/**

 * This is the model class for table "toto".

 *

 * The followings are the available columns in table 'toto':

 * @property integer $id

 .

 .

 .

 * @property TotoEatStuf[] $totoEatStufs

 .

 .

 .

 */

class Toto extends CActiveRecord

{

	/**

	 * Returns the static model of the specified AR class.

	 * @return Toto the static model class

	 */

	public static function model($className=__CLASS__)

	{

		return parent::model($className);

	}


	/**

	 * @return string the associated database table name

	 */

	public function tableName()

	{

		return 'toto';

	}


			.

			.

			.


	/**

	 * @return array relational rules.

	 */

	public function relations()

	{

		// NOTE: you may need to adjust the relation name and the related

		// class name for the relations automatically generated below.

		return array(

			.

			.

			'totoEatStufs' => array(self::HAS_MANY, 'TotoEatStuf', 'toto_id'),

			.

			.

		);

	}


			.

			.

			.

}



class stuf





<?php


/**

 * This is the model class for table "stuf".

 *

 * The followings are the available columns in table 'stuf':

 * @property integer $id

 .

 .

 * @property TotoEatStuf[] $totoEatStufs

 .

 .

 */

class Stuf extends CActiveRecord

{

	/**

	 * Returns the static model of the specified AR class.

	 * @return Stuf the static model class

	 */

	public static function model($className=__CLASS__)

	{

		return parent::model($className);

	}


	/**

	 * @return string the associated database table name

	 */

	public function tableName()

	{

		return 'stuf';

	}


			.

			.

			.


	/**

	 * @return array relational rules.

	 */

	public function relations()

	{

		// NOTE: you may need to adjust the relation name and the related

		// class name for the relations automatically generated below.

		return array(

			'totoEatStufs' => array(self::HAS_MANY, 'TotoEatStuf', 'stuf_id'),

			.

			.

		);

	}


			.

			.

			.


}



class TotoEatStuf





<?php


/**

 * This is the model class for table "toto_eat_stuf".

 *

 * The followings are the available columns in table 'toto_eat_stuf':

 * @property integer $toto_id

 * @property integer $stuf_id

 * @property string $date

 * @property integer $quantity

 *

 * The followings are the available model relations:

 * @property Stuf $stuf

 * @property Toto $toto

 */

class TotoEatStuf extends CActiveRecord

{

	/**

	 * Returns the static model of the specified AR class.

	 * @return TotoEatStuf the static model class

	 */

	public static function model($className=__CLASS__)

	{

		return parent::model($className);

	}


	/**

	 * @return string the associated database table name

	 */

	public function tableName()

	{

		return 'toto_eat_stuf';

	}


	/**

	 * @return array validation rules for model attributes.

	 */

	public function rules()

	{

		// NOTE: you should only define rules for those attributes that

		// will receive user inputs.

		return array(

			array('toto_id, stuf_id, date, quantity', 'required'),

			array('toto_id, stuf_id, quantity', 'numerical', 'integerOnly'=>true),

			// The following rule is used by search().

			// Please remove those attributes that should not be searched.

			array('toto_id, stuf_id, date, quantity', 'safe', 'on'=>'search'),

		);

	}


	/**

	 * @return array relational rules.

	 */

	public function relations()

	{

		// NOTE: you may need to adjust the relation name and the related

		// class name for the relations automatically generated below.

		return array(

			'stuf' => array(self::BELONGS_TO, 'Stuf', 'stuf_id'),

			'toto' => array(self::BELONGS_TO, 'Toto', 'toto_id'),

		);

	}


	/**

	 * @return array customized attribute labels (name=>label)

	 */

	public function attributeLabels()

	{

		return array(

			'toto_id' => 'Toto',

			'stuf_id' => 'Stuf',

			'date' => 'Date',

			'quantity' => 'Quantity',

		);

	}


	/**

	 * Retrieves a list of models based on the current search/filter conditions.

	 * @return CActiveDataProvider the data provider that can return the models based on the search/filter conditions.

	 */

	public function search()

	{

		// Warning: Please modify the following code to remove attributes that

		// should not be searched.


		$criteria=new CDbCriteria;


		$criteria->compare('toto_id',$this->toto_id);

		$criteria->compare('stuf_id',$this->stuf_id);

		$criteria->compare('date',$this->date,true);

		$criteria->compare('quantity',$this->quantity);


		return new CActiveDataProvider($this, array(

			'criteria'=>$criteria,

		));

	}

}

in action :




$totos = Toto::model()->findAll();

$i=0;

foreach ($totos as $toto) {

	$toto->totoEatStufs = TotoConsommeAliment::model()->findAllByAttributes(array('toto_id' => $toto->id));

 }

$this->render('index', array(

	'totos' => $totos,

));



and the code that work in windows and not work in ubuntu is :





foreach ($totos as $toto) {

   foreach ($toto->totoEatStufs as $eatStuf) {

		if (in_array($eatStuf->stuf->name, $stufs)) {

			

			$stufs[] = $eatStuf->stuf->name;

			$sommeAliments[$eatStuf->stuf->name] = $eatStuf->quantite;

		} else {

			

			$sommeAliments[$eatStuf->stuf->name]+=$eatStuf->quantite;

		}

	}

}




it’s tell me invalid forech in the second foreach loop

Hi,

I wonder why you are doing this in your action :




foreach ($totos as $toto) {        

  $toto->totoEatStufs = TotoConsommeAliment::model()->findAllByAttributes(array('toto_id' => $toto->id)); 

}



The aim of lazy loading is to load related record… on demand. (and I guess TotoConsommeAliment is a typo and you meant TotoEatStuff :) )

And, for tests, did you try with the eager loading approach




$totos=toto::model()->with('totoEatsStufs')->findAll()



it’s a workround solution fon make it work , you right it’s TotoEatsStufs :P :)

the eager loading also just work in my developement server and don’t work on others servers .

I figure out what is the diference between servers :

it’s in php.ini file :


 error_reporting=  E_ALL ,



in my dev environement it’s set to


error_reporting =E_STRICT



True what you said about E_STRICT and E_ALL.

And what is the solutions on this?

I have this problem:




[b]`models\User.php`[/b]

public function relations() {

   return array(

      'city'=> array(self::BELONGS_TO,'City','cityid'),

      'subscribers'=>array(self::HAS_MANY,'Userssubscribers','follower_id'),

      '_address'=> array(self::BELONGS_TO,'Address','address'),

   );

}


[b]`UserController.php`[/b]

$user = User::model()->with('city')->with('_address')->findByPk($user_id);


$result             = new stdClass;

$result->id         = $user->id;

$result->first_name = $user->first_name;

$result->last_name  = $user->last_name;

$result->address       = new stdClass();

$result->address->id   = isset($user->_address->id) ? $user->_address->id : '';

$result->address->name = isset($user->_address->name) ? $user->_address->name : '';

$result->privileges                  = new stdClass;    

$result->privileges->view_mail       = isset($user->view_mail) ? $user->view_mail : '';

$result->privileges->view_first_name = isset($user->view_first_name) ? $user->view_first_name : '';

<h1>PHP Error [8]</h1>

<p>Undefined property: stdClass::$_address (C:\www\town_rally\src\protected\models\User.php:457)</p>

This line: $result->address->id = isset($user->_address->id) ? $user->_address->id : ‘’;

Actually $user->_address isset, and id has value with var_dump.

Edit later (fixed): Update

In my case, the problem was with lazy loading. My code, actually is a function getFormattedUser(&#036;user, &#036;param) and &#036;user is already an User Object. I needed to get the object again to have it’s values in the function context.