code_junkie

Using relations for setting in Zend_Db_Table_Row

Nov 14th, 2011
73
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.26 KB | None | 0 0
  1. $contentModel = new Content();
  2. $categoryModel = new Category();
  3.  
  4. $category = $categoryModel->createRow();
  5. $category->setName('Name Category 4');
  6.  
  7. $content = $contentModel->createRow();
  8. $content->setTitle('Title 4');
  9.  
  10. $content->setCategory($category);
  11. $content->save();
  12.  
  13. $contentModel = new Content();
  14. $categoryModel = new Category();
  15.  
  16. $category = $categoryModel->createRow();
  17. $category->setName('Name Category 4');
  18.  
  19. $content = $contentModel->createRow();
  20. $content->setTitle('Title 4');
  21.  
  22. // saving populates the primary key field in the Row object
  23. $category->save();
  24.  
  25. $content->setCategory($category->category_id);
  26. $content->save();
  27.  
  28. protected $_rowClass = 'Db_Table_Row';
  29.  
  30. public function __get($key)
  31. {
  32. $inflector = new Zend_Filter_Word_UnderscoreToCamelCase();
  33.  
  34. $method = 'get' . $inflector->filter($key);
  35.  
  36. if(method_exists($this, $method)) {
  37. return $this->{$method}();
  38. }
  39.  
  40. return parent::__get($key);
  41. }
  42.  
  43. public function __set($key, $value)
  44. {
  45. $inflector = new Zend_Filter_Word_UnderscoreToCamelCase();
  46.  
  47. $method = 'set' . $inflector->filter($key);
  48.  
  49. if(method_exists($this, $method))
  50. return $this->{$method}($value);
  51.  
  52. return parent::__set($key, $value);
  53. }
  54.  
  55. public function setCategory($value)
  56. {
  57. $this->category_id = $value->category_id;
  58. }
Add Comment
Please, Sign In to add comment