Temporary attributes

I’m a newbie here and I’ve stuck. I would like to create temporary attributes in forms, but don’t know how. To be more specific:

I have a database column that represents 24-hour time, HH:MM:SS format. In a view file, form is made of 2 text fields, one is 12-hour representation of hours and the other one of minutes, and one dropdown menu with am/pm options. When the 24-hour is converted to 12-hour time in PHP, how to display those values in the view file using model? Also, how to gather those 3 attributes when saving into one and to save it?

(I have 28 24-hour columns and I’m trying to avoid 28*3 columns)

Thanks in advance!

Take a look at virtual attributes.

In the form create/update you can put the fulltime parts from $_POST together and assign the full time to your db-attribute.




    //build the value for the db-field something like this

    //hour, minute, second are your virtual attributes

    //you can add a method 'setTimeFromPOST' to the model for this

    $model->fullTime = mktime($_POST['hour'],$_POST['minute'],$_POST['second']); 




And here is an article with another approach about setting virtual attribute values (I didn’t test).

Thanks, it works!

[s]Can you also please explain me how to create an object in model using DAO? How to populate attributes?

This is what I have in a model:

private $_cmdSelect;

public $user;

sql = ‘SELECT * FROM periods WHERE user=:user LIMIT 1’;

$this->_cmdSelect = Yii::app()->db->createCommand($sql);

$this->_cmdSelect->bindParam(’:user’, $this->user, PDO::PARAM_STR);

$this->_attributes = $this->_cmdSelect->queryRow();

I’m 110% sure I’m doing it wrong.[/s]


/* When asking a different question, please create a new thread with a suitable title */