I hope I understand your question properly. But I believe you’re asking how you would retrieve the data from the database through your activerecord model and pass it to your view for consumption by your javascript. I’m assuming the following:
Database table: tbl_x (two integer columns ‘prebooked’ and ‘booked’)
ActiveRecord model: TblX
To retrieve your data from the database in your controller, you would use something like:
$booked and $prebooked would both contain arrays of the TblX model with data. You would then iterate through the array and build the string you would pass to the view.
You have almost understod my issue (or I have not describe it correct )
In table x I have a column "bookdate" of the type date with the format YYYY-DD-MM
Based on a status column bookdate should be prebooked or booked.
I also need to manipulate the data because the javascript need the data in this format:
[‘23-4-2013’,‘2-4-2013’]
(the sample with two days)
Where would the best place be to convert the date to the format needed by the javascript, and concardinate if there are more than one date in the database?
There’s also many clever ways to concat strings together, especially with the helper functions that Yii offers (such as CHtml::listData), but I’ll give you a simple solution. Assume that $records is an array of your model retrieved by using TblX::model()->findAll():
I have moved the code from the controller to the model, and moved the javascript from create form to the _form, becauase then I also have the date picker at the edit form.