Hi, I'm using Doctrine with Codeigniter, I defined my ratings column as $this->hasColumn('ratings','array', 1000);. I'm using
$res = Doctrine::getTable('Resource')->find($resource_id);
$res->ratings = $rating;
$res->save();
but only the $rating gets inserted, overwriting the last value, I want to store the ratings as an array, ex: 1,5,4,2,3,5,1 etc.. How do I add/retrieve values from a table column defined as array with Doctrine? (I'm using mysql)
views:
36answers:
2I'm not familiar with CodeIgniter, but as the Doctrine "array" type is equivalent to MySQL TEXT type, in PHP I would use implode() and explode() functions to create a comma-separated string of values that is stored as a text string. MySQL VARCHAR might be more suitable for your needs. The Doctrine equivalent for this is "string".
Hope that helps.
Managed to do it, I'll post the code below maybe someone will find it usefull public function add_rating() { $rating = (int) $this->uri->segment(3); $resource_id = (int) $this->uri->segment(4); if((is_numeric($rating)) && ($rating > 0) && ($rating <= 5)) { $res = Doctrine::getTable('Resource')->find($resource_id); $ratings = $res->ratings; $ratings[] = $rating; $res->ratings = $ratings; // echo ''; // echo print_r($ratings); $res->save(); } redirect('/home/show/' . $resource_id); }
thanks again for your help/time