Yii Framework Forum: Lazy loading not working - Yii Framework Forum

Jump to content

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

Lazy loading not working [LAZY] [LOADING] Rate Topic: -----

#1 User is offline   yiiesss 

  • Newbie
  • Yii
  • Group: Members
  • Posts: 17
  • Joined: 10-August 11

Posted 26 February 2012 - 07:30 AM

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 !
0

#2 User is offline   andy_s 

  • Random Member Title
  • Yii
  • Group: Moderators
  • Posts: 1,526
  • Joined: 22-June 09
  • Location:Russia, Kostroma

Posted 26 February 2012 - 08:17 AM

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

#3 User is offline   yiiesss 

  • Newbie
  • Yii
  • Group: Members
  • Posts: 17
  • Joined: 10-August 11

Posted 29 February 2012 - 06:41 AM

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.

This post has been edited by yiiesss: 13 March 2012 - 05:23 AM

0

#4 User is offline   yiiesss 

  • Newbie
  • Yii
  • Group: Members
  • Posts: 17
  • Joined: 10-August 11

Posted 12 March 2012 - 08:44 AM

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 !
0

#5 User is offline   yiiesss 

  • Newbie
  • Yii
  • Group: Members
  • Posts: 17
  • Joined: 10-August 11

Posted 12 March 2012 - 09:24 AM

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

0

#6 User is offline   yiiesss 

  • Newbie
  • Yii
  • Group: Members
  • Posts: 17
  • Joined: 10-August 11

Posted 13 March 2012 - 05:21 AM

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 ?

This post has been edited by yiiesss: 13 March 2012 - 05:23 AM

0

#7 User is offline   talby101 

  • Junior Member
  • Pip
  • Yii
  • Group: Members
  • Posts: 36
  • Joined: 26-August 10
  • Location:Wales

Posted 13 March 2012 - 05:38 AM

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 ;)



View Postyiiesss, on 13 March 2012 - 05:21 AM, said:

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 ?

0

#8 User is offline   yiiesss 

  • Newbie
  • Yii
  • Group: Members
  • Posts: 17
  • Joined: 10-August 11

Posted 14 March 2012 - 06:11 AM

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
0

#9 User is offline   tof 

  • Junior Member
  • Pip
  • Yii
  • Group: Members
  • Posts: 29
  • Joined: 07-October 08
  • Location:Sophia Antipolis - French Riviera

Posted 14 March 2012 - 07:15 AM

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()

0

#10 User is offline   yiiesss 

  • Newbie
  • Yii
  • Group: Members
  • Posts: 17
  • Joined: 10-August 11

Posted 14 March 2012 - 09:30 AM

View Posttof, on 14 March 2012 - 07:15 AM, said:

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 .
0

#11 User is offline   yiiesss 

  • Newbie
  • Yii
  • Group: Members
  • Posts: 17
  • Joined: 10-August 11

Posted 16 March 2012 - 06:32 AM

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

0

#12 User is offline   strategy 

  • Newbie
  • Yii
  • Group: Members
  • Posts: 1
  • Joined: 28-November 12

Posted 22 February 2013 - 04:55 AM

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($user, $param)` and `$user` is already an User Object. I needed to get the object again to have it's values in the function context.
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