Confuse about getUserOptions in chapter 6

Hi everybody,

Firstly allowme apologize because of my intro level using frameworks. It’s my first!!!

There are two topics that are making me troubles:

  1. I decide use Oracle because it’s the rdbms used in my company, and i’ve been having problems with case sensibilitiness. I’ve have to change the name of lots of db objets and fields. There are some way to avoid it?

  2. I’m confused with the getUserOptions in the project model file. If the function is inside project controller, $this means the AR related with the table tbl_project, if so, in $usersArray = CHtml::listData($this->USER, ‘ID’, ‘USERNAME’), is incorrect because the fields USER and USERNAME don’t exist in such table. I believe that the right field could be fields that are available in table project.

Thx a lot

Hi piloxo

Check more carefully, there is now variable like $this->user in getUserOptions() method, but there is $this->user[color="#ff0000"]s[/color]. It is a relation that defined in your relations() method:


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(

            ...

            'users' => array(self::MANY_MANY, 'User', 'tbl_project_user_assignment(project_id,user_id)'),

        );

    } 

The same answer, I’ve ever used Oracle so you should check your Models Name, you’ve fixed something so check it again.

When you use Models, it’ll call exactly name of column on your DB.

I think you should show some images or error Code here!

Thank you for your glentle cooperation.

Efectively there was a mistake with the name of the array created in the relations area, I correct it and now it works great.

The case sensibilitiness issue could be created in the model creation process. I’ll add the code created for ISSUE table:

<?php

/**

  • This is the model class for table "TBL_ISSUE".

  • The followings are the available columns in table ‘TBL_ISSUE’:

  • @property double $ID

  • @property string $NAME

  • @property string $DESCRIPTION

  • @property double $PROJECT_ID

  • @property double $TYPE_ID

  • @property double $STATUS_ID

  • @property double $OWNER_ID

  • @property double $REQUESTER_ID

  • @property string $CREATE_TIME

  • @property double $CREATE_USER_ID

  • @property string $UPDATE_TIME

  • @property double $UPDATE_USER_ID

  • The followings are the available model relations:

  • @property USER $oWNER

  • @property PROJECT $pROJECT

  • @property USER $rEQUESTER

*/

class ISSUE extends CActiveRecord

{

    const TYPE_BUG=0;


    const TYPE_FEATURE=1;


    const TYPE_TASK=2;





    public function getTypeOptions() {


      return array( self::TYPE_BUG=&gt;'Bug',


                    self::TYPE_FEATURE=&gt;'Feature',


                    self::TYPE_TASK=&gt;'Task', );


    }





    const TYPE_Not_yet_started=0;


    const TYPE_Started=1;


    const TYPE_Finished=2;





    public function getStatusOptions() {


      return array( self::TYPE_Not_yet_started=&gt;'Not Yet Started',


                    self::TYPE_Started=&gt;'Started',


                    self::TYPE_Finished=&gt;'Finished', );


    }





/**


 * Returns the static model of the specified AR class.


 * @return ISSUE the static model class


 */


public static function model(&#036;className=__CLASS__)


{


	return parent::model(&#036;className);


}





/**


 * @return string the associated database table name


 */


public function tableName()


{


	return 'TBL_ISSUE';


}





/**


 * @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('NAME', 'required'),


		array('PROJECT_ID, TYPE_ID, STATUS_ID, OWNER_ID, REQUESTER_ID, CREATE_USER_ID, UPDATE_USER_ID', 'numerical'),


		array('NAME', 'length', 'max'=&gt;256),


		array('DESCRIPTION', 'length', 'max'=&gt;2000),


		array('CREATE_TIME, UPDATE_TIME', 'safe'),


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


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


		array('ID, NAME, DESCRIPTION, PROJECT_ID, TYPE_ID, STATUS_ID, OWNER_ID, REQUESTER_ID, CREATE_TIME, CREATE_USER_ID, UPDATE_TIME, UPDATE_USER_ID', 'safe', 'on'=&gt;'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(


		'oWNER' =&gt; array(self::BELONGS_TO, 'USER', 'OWNER_ID'),


		'pROJECT' =&gt; array(self::BELONGS_TO, 'PROJECT', 'PROJECT_ID'),


		'rEQUESTER' =&gt; array(self::BELONGS_TO, 'USER', 'REQUESTER_ID'),


	);


}





/**


 * @return array customized attribute labels (name=&gt;label)


 */


public function attributeLabels()


{


	return array(


		'ID' =&gt; 'ID',


		'NAME' =&gt; 'Name',


		'DESCRIPTION' =&gt; 'Description',


		'PROJECT_ID' =&gt; 'Project',


		'TYPE_ID' =&gt; 'Type',


		'STATUS_ID' =&gt; 'Status',


		'OWNER_ID' =&gt; 'Owner',


		'REQUESTER_ID' =&gt; 'Requester',


		'CREATE_TIME' =&gt; 'Create Time',


		'CREATE_USER_ID' =&gt; 'Create User',


		'UPDATE_TIME' =&gt; 'Update Time',


		'UPDATE_USER_ID' =&gt; 'Update User',


	);


}





/**


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





	&#036;criteria=new CDbCriteria;





	&#036;criteria-&gt;compare('ID',&#036;this-&gt;ID);


	&#036;criteria-&gt;compare('NAME',&#036;this-&gt;NAME,true);


	&#036;criteria-&gt;compare('DESCRIPTION',&#036;this-&gt;DESCRIPTION,true);


	&#036;criteria-&gt;compare('PROJECT_ID',&#036;this-&gt;PROJECT_ID);


	&#036;criteria-&gt;compare('TYPE_ID',&#036;this-&gt;TYPE_ID);


	&#036;criteria-&gt;compare('STATUS_ID',&#036;this-&gt;STATUS_ID);


	&#036;criteria-&gt;compare('OWNER_ID',&#036;this-&gt;OWNER_ID);


	&#036;criteria-&gt;compare('REQUESTER_ID',&#036;this-&gt;REQUESTER_ID);


	&#036;criteria-&gt;compare('CREATE_TIME',&#036;this-&gt;CREATE_TIME,true);


	&#036;criteria-&gt;compare('CREATE_USER_ID',&#036;this-&gt;CREATE_USER_ID);


	&#036;criteria-&gt;compare('UPDATE_TIME',&#036;this-&gt;UPDATE_TIME,true);


	&#036;criteria-&gt;compare('UPDATE_USER_ID',&#036;this-&gt;UPDATE_USER_ID);





	return new CActiveDataProvider(&#036;this, array(


		'criteria'=&gt;&#036;criteria,


	));


}

}