DB-dependent view?

I want the view for my table system_options to be adjusted automatically everytime I added or edited or deleted a column in the table. Is this doable? Honestly, I haven’t tried to research on this, because I don’t know what it is called.

Anyone has done this already? Could you please give me an example?

Thanks a bunch!

Rather than explicitly listing the items to be displayed, you could specify the view to use ‘attributes’=>$model->attributes. (Assuming you’re using a CDetailView widget)

There are some drawbacks to this method though, which I’m sure you’ll be able to spot if you have any relationships defined that you’re using or want to format any dates/currencies, etc. ;)

Hi Dana,

Thanks for your reply. I have read the class reference for CDetailView, but I don’t think it would help me accomplish what I need (unless,of course, my understanding is not correct).

Let me provide an example.

These are the fields for my table ‘system_options’:

CREATE TABLE `system_options` (

	`name` VARCHAR( 50 ) NOT NULL ,

	`code` VARCHAR( 10 ) NOT NULL ,


) ENGINE = InnoDB;

Then I have generated the model and CRUD codes using gii. Everything is fine, I can add,edit,view or delete a record from this model just fine.

And there’s a need for me to add another column named ‘title’, so I altered the table, edited the model,edited the controller,and then finally the view files. I find it tedious, because I have to edit bunch of files just because of the added column.


I’m new to MVC. But if I am to do it the old way, I would create a different table to contain the table characteristics, and I will create a code that will allow me add,edit,or delete the table fields and its characteristics. And based on that table, I can see what fields should I render in my HTML when I am about to edit or add the record.

I want to use Yii, so I want to breath Yii. I just don’t know how I will be able to do this in MVC and Yii.

Any hints on how I can accomplish that?

Hmm… Maybe you want something like Yii-user extension? The profiles table there has a table that handles the fields.

Try it out,see if that’s what you need.