Yii Framework Forum: I have a white page when I use join 3 tables [SOLVED] - 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 white page when I use join 3 tables [SOLVED] Rate Topic: -----

#1 User is offline   Co-k-ine 

  • Junior Member
  • Pip
  • Yii
  • Group: Members
  • Posts: 97
  • Joined: 29-March 10

Posted 19 June 2010 - 02:01 PM

Hello world,

I apologize for my English but I'm French and I have not mastered much English !


Recently I had a problem to create a model with a join three tables. For more details click here

Here is the schema of my database :

Posted Image



And are the model of tables genered by yiic.


I have renamed "animes_has_animes_genres.php" to "AnimesHasAnimesGenres.php" otherwise I get nothing!

AnimesHasAnimesGenres.php
<?php


class animes_has_animes_genres extends CActiveRecord
{
	/**
	 * The followings are the available columns in table 'animes_has_animes_genres':
	 * @var integer $animes_id
	 * @var integer $animes_genres_id
	 * @var integer $id
	 */

	/**
	 * Returns the static model of the specified AR class.
	 * @return animes_has_animes_genres 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 'animes_has_animes_genres';
	}

	/**
	 * @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(
			// The following rule is used by search().
			// Please remove those attributes that should not be searched.
			array('animes_id, animes_genres_id, id', '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(
			'animes' => array(self::BELONGS_TO, 'Animes', 'animes_id'),
			'animes_genres' => array(self::BELONGS_TO, 'AnimesGenres', 'animes_genres_id'),
		);
	}

	/**
	 * @return array customized attribute labels (name=>label)
	 */
	public function attributeLabels()
	{
		return array(
			'animes_id' => 'Animes',
			'animes_genres_id' => 'Animes Genres',
			'id' => 'Id',
		);
	}

	/**
	 * 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('animes_id',$this->animes_id);

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

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

		return new CActiveDataProvider('animes_has_animes_genres', array(
			'criteria'=>$criteria,
		));
	}
}


animes.php

<?php

class animes extends CActiveRecord
{
	/**
	 * The followings are the available columns in table 'animes':
	 * @var integer $id
	 * @var string $titre
	 * @var string $titre_original
	 * @var string $annee_production
	 * @var string $studio
	 * @var string $duree
	 * @var string $synopsis
	 * @var integer $nb_episode_dispo
	 * @var string $fansub
	 * @var integer $episode_ddl
	 */

	/**
	 * Returns the static model of the specified AR class.
	 * @return animes 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 'animes';
	}

	/**
	 * @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('nb_episode_dispo, episode_ddl', 'numerical', 'integerOnly'=>true),
			array('titre, titre_original', 'length', 'max'=>150),
			array('annee_production, studio', 'length', 'max'=>45),
			array('duree', 'length', 'max'=>7),
			array('fansub', 'length', 'max'=>250),
			array('synopsis', 'safe'),
			// The following rule is used by search().
			// Please remove those attributes that should not be searched.
			array('id, titre, titre_original, annee_production, studio, duree, synopsis, nb_episode_dispo, fansub, episode_ddl', '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(
			'animes_ddls' => array(self::HAS_MANY, 'AnimesDdl', 'animes_id'),
			'animes_has_animes_auteurs' => array(self::HAS_MANY, 'AnimesHasAnimesAuteurs', 'animes_id'),
			'animes_has_animes_genres' => array(self::HAS_MANY, 'AnimesHasAnimesGenres', 'animes_id'),
		);
	}

	/**
	 * @return array customized attribute labels (name=>label)
	 */
	public function attributeLabels()
	{
		return array(
			'id' => 'Id',
			'titre' => 'Titre',
			'titre_original' => 'Titre Original',
			'annee_production' => 'Annee Production',
			'studio' => 'Studio',
			'duree' => 'Duree',
			'synopsis' => 'Synopsis',
			'nb_episode_dispo' => 'Nb Episode Dispo',
			'fansub' => 'Fansub',
			'episode_ddl' => 'Episode Ddl',
		);
	}

	/**
	 * 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('id',$this->id);

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

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

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

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

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

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

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

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

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

		return new CActiveDataProvider('animes', array(
			'criteria'=>$criteria,
		));
	}
}



animes_genres.php


<?php

class animes_genres extends CActiveRecord
{
	/**
	 * The followings are the available columns in table 'animes_genres':
	 * @var integer $id
	 * @var string $titre
	 * @var string $description
	 */

	/**
	 * Returns the static model of the specified AR class.
	 * @return animes_genres 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 'animes_genres';
	}

	/**
	 * @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('titre', 'length', 'max'=>45),
			array('description', 'safe'),
			// The following rule is used by search().
			// Please remove those attributes that should not be searched.
			array('id, titre, description', '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(
			'animes_has_animes_genres' => array(self::HAS_MANY, 'AnimesHasAnimesGenres', 'animes_genres_id'),
		);
	}

	/**
	 * @return array customized attribute labels (name=>label)
	 */
	public function attributeLabels()
	{
		return array(
			'id' => 'Id',
			'titre' => 'Titre',
			'description' => 'Description',
		);
	}

	/**
	 * 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('id',$this->id);

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

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

		return new CActiveDataProvider('animes_genres', array(
			'criteria'=>$criteria,
		));
	}
}





When i use :

<?php

$animes = animes::model()->with('animes_has_animes_genres','animes_genres')->findAll();


foreach($animes as $anime ) {
     echo 'id = '.$anime->id.'<br/>';
     echo 'Titre = '.$anime->titre.'<br/>';
   
        }
?>


I have a white page, no message, nothing !


Thanks for your help !
0

#2 User is offline   imehesz 

  • Master Member
  • PipPipPipPip
  • Yii
  • Group: Members
  • Posts: 706
  • Joined: 13-June 09
  • Location:Jacksonville, FL

Posted 19 June 2010 - 05:15 PM

hello

when I'm in development environment, I like to set these right in the top of my index.php file to catch all the errors:

error_reporting (E_ALL);
ini_set("display_errors", 1);


plus in the protected/config/main.php
...
				// uncomment the following to show log messages on web pages
				array(
					'class'=>'CWebLogRoute',
				),
...


hope this helps a little

--iM
It’s done, the great act of creation.
The maker rests. The wheel’s in motion.
-- Imre Madách

check out Yii Theme Factory at http://yii.themefactory.net
0

#3 User is offline   Co-k-ine 

  • Junior Member
  • Pip
  • Yii
  • Group: Members
  • Posts: 97
  • Joined: 29-March 10

Posted 20 June 2010 - 06:03 AM

Quote

Fatal error: Class 'AnimesHasAnimesGenres' not found in /var/www/yii1.2/framework/db/ar/CActiveRecord.php on line 341

0

#4 User is offline   Co-k-ine 

  • Junior Member
  • Pip
  • Yii
  • Group: Members
  • Posts: 97
  • Joined: 29-March 10

Posted 22 June 2010 - 06:29 AM

UP
0

#5 User is offline   sdietz 

  • Newbie
  • Yii
  • Group: Members
  • Posts: 12
  • Joined: 04-July 09

Posted 22 June 2010 - 07:13 AM

Hello there.

Well it is pretty obvious, that the configuration of the model relations don't match with the name of your classes.

                        'animes_has_animes_genres' => array(self::HAS_MANY, 'AnimesHasAnimesGenres', 'animes_id'),


vs.

class animes_has_animes_genres extends CActiveRecord


Specifically: AnimesHasAnimesGenres vs. animes_has_animes_genres


Hope that helps.
0

#6 User is offline   Dana 

  • Standard Member
  • PipPip
  • Yii
  • Group: Members
  • Posts: 203
  • Joined: 18-February 10
  • Location:Florida, USA

Posted 22 June 2010 - 01:31 PM

The name of the class has to match the name of the file that contains it or the Yii import and autoload won't find the class properly. You renamed the file, but not the class within the file.
0

#7 User is offline   Co-k-ine 

  • Junior Member
  • Pip
  • Yii
  • Group: Members
  • Posts: 97
  • Joined: 29-March 10

Posted 22 June 2010 - 02:08 PM

Thanks for your reply.

This subject is now resolved !
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