Yii Framework Forum: Entity Attribute Value - Yii Framework Forum

Jump to content

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

Entity Attribute Value Rate Topic: -----

#1 User is offline   research4oscar 

  • Newbie
  • Yii
  • Group: Members
  • Posts: 4
  • Joined: 21-October 10

Posted 21 October 2010 - 07:17 PM

I was following the yii blog example and was not sure if I missed a step or if there is another alternative than having to declare constants for the values in the lookup table. As I understand it, the lookup table follows a EAV or OTLT concept. For a table with only a few types such as the lookup table example, declaring constants in the model may be fine but as for a table that may include many values (i.e product attributes), it is impractical to declare all possible values as constants. Any ideas or possible alternative solutions?
0

#2 User is offline   zaccaria 

  • Elite Member
  • PipPipPipPipPip
  • Yii
  • Group: Members
  • Posts: 2,232
  • Joined: 04-October 09
  • Location:Moscow

Posted 22 October 2010 - 01:35 AM

What do you mean with "declare values as constants?"
1

#3 User is offline   research4oscar 

  • Newbie
  • Yii
  • Group: Members
  • Posts: 4
  • Joined: 21-October 10

Posted 22 October 2010 - 08:42 AM

In the Yii blog tutorial under the section, "Customizing Post Model" (link: http://www.yiiframew...1/en/post.model), there is a subsection titled, "4. Representing Status in Text". Within this section the author describes the table, "tbl_lookup" which contains status values for the Comment table and the Post table. After modifying the Lookup model class in order to access the text values(as oppose to the integer values), the author also modifies the class Post extends CActiveRecord with the following:
{
const STATUS_DRAFT=1;
const STATUS_PUBLISHED=2;
const STATUS_ARCHIVED=3;
......
}

This I believe is done to later display the lookup table values within a form with something like:
<?php echo $form->dropDownList($model,'status',Lookup::items('PostStatus')); ?>.

My question above refered to the fact that it looks as if I have to declare constants in order to get a drop down to display the correct values whenever a database table follows an Entity-Attribute-Value format.

In searching other forums, I found the following could possibly work:
<?php echo $form->dropDownList($model,'status', CHtml::listData(Lookup::model()->findAll(), 'id', 'name')); ?>
However, this displays a drop down list with all values within the tbl_lookup table and not just those values where type=PostStatus.

Hope this clears up my question a little better. I am new to both MVC as well as Yii, please let me make myself a little more clear.
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