some questions

Hi all,

I have some questions about yii, can you tell me if these features are available or will be?

1)  Is there a way to make AR classes timestampable (something like: http://www.yiiframew…c,293.0.html)?

For your first question. I added a rule to the 'created' and 'updated' fields that work on the contexts 'insert' and 'update'. This rule sets the file with the right datetime.

Hi dalip, could you please show me how you did this? 


For your first question. I added a rule to the 'created' and 'updated' fields that work on the contexts 'insert' and 'update'. This rule sets the file with the right datetime.
  1. I guess dalip suggested the following way:

public function rules()


      return array(

            // other validation rules

            array('createTime, updateTime', 'filter', 'time', 'on'=>'insert'),



For more details, you can take a look at API about CFilterValidator. You can also assign the attributes inside beforeValidate() or beforeSave()

  1. Currently this is not available, but it is totally possible. You may create a ticket to request for this feature.

  2. This may also be possible, depending on the actual requirements, though.

  3. Well, this is a good idea, but it is at the cost of an additional class file for every model (if you have 50 tables, you would end up with 100 files!) I am not sure if other people would like this approach.

Thanks for the response qiang.

I can write tickets for 2/3. 

For something like 4, how would you handle this?  Would you like discussion on a ticket to see if something like this gets support?  Or is discussion on the forums better for you?

Yii looks very exciting!  Thanks for your time and effort into it.

Yes, please create a ticket about 2. For 3, if you create a ticket, could you please elaborate the requirements?

After more thinking, I think 4 is not really necessary. If you have made modification to a generated model, why would you use "crud model" to regenerate it?

Please use forum to discuss about uncertain features or bugs. This would benefit other users.

Regarding 4:

I also had some situations where the db schema was subject of changes during the development process. It would have been nice to simply re-create the models, but i would have lost my custom code inside them.

Would it be a solution to place the model attributes inside some comment markers?


  public $id;

  public $name;

  // more attributes ..


This is not difficult to implement. It is more about the philosophy of Web development. Like RoR, I think database schema should be considered as part of the data structure of an application. Therefore, changing DB schema would have similar effect as changing variable or class names - we need to be careful.

Sure, re-creating models is nothing you should do, without thinking first :) But in the sense of agile programming, i think, some applications grow over time and their db schemas might get extended or changed rapidly. Issuing a simple model command to update all models would be convinient then.

But i also understand your concerns: This could mess up a lot, if people don't use it whisely.

How about a confirmation message?

There’s already a model file for this table. Your custom changes will be preserved but the attribute list will be overwritten. Are you sure you want to do this?

You see, that's why the current model class is so simple: it specifies nothing but the table name. The available attributes are dependent of the table schema. So you never need to re-run the model command once a model class has been created because re-running the model won't bring in any new information.

I think i don't understand. What if you have table say "company" with company and contact information. During development/customer discussion you find out, that you need to move contact information into a separate table. So the attributes of your company model changed.

Sure, this might not be worth the effort to implement a model update feature. But nevertheless - it still think it could be useful sometimes  ;D

The class generated by the model command won't contain the declaration of 'company' and 'contact'. Therefore, no matter how you change the table definition, your model class remains unchanged unless you explicitly add some code. That's why I said you won't run the model command again once the model class has been created.

Oops, correct.  :-X  Sorry for my ignorance. I always had Prado’s implementation in mind.


Actually, you can still explicitly declare those columns as the model class properties in Yii. For example, if you want to specify some default column values.