Zend Db Table Abstract add new field to the row
I once posted this question, but had no answer at all, this time, the question is best formated so It will be more easy to understand what I need.
I created a Model with Zend_Db_Table_Abstract
Add the primaryKey and the table name, all ok.
Then, I executed the code to retrieve the fonts.
$db = new App_Model_News();
$news = $db->fetchAll("visible = 1", "published_on DESC");
foreach ($news as $i => $new) {
$images = $this->_helper->News->first_image($new);
}
This method works, but I need to retrieve two view statements:
$this->view->news = $news;
$this->view->images = $images;
What I need is to merge this two results, doing something like this.
$db = new App_Model_News();
$news = $db->fetchAll("visible = 1", "published_on DESC");
foreach ($news as $i => $new) {
$news[$i]->images = $this->_helper->News->first_image($new);
}
$this->view->news = $news;
I'm not able to do it, because the Abstract is array associative, my Model is like this:
class App_Model_News extends Zend_Db_Table_Abstract{
protected $_name = 'news';
protected $_primary = 'id';
protected $_dependentTables = array('ImagesNews');
}
class ImagesNews extends Zend_Db_Table_Abstract{
protected $_name = 'news_imagens';
protected $_primary = 'id_new';
protected $_referenceMap = array(
'Arquivos' => array(
'columns' => 'id_new',
'refTableClass' => 'App_Model_News',
'refColumns' => 'id'
));
}
Is there any way to add the images inside the news rows? Then at the vi开发者_JAVA技巧ew I could loop and print the images.
Thanks and best regard's. Sorry for my bad english.
I think that what you could do is to create your own custom News row class:
class App_Model_Row_News extends Zend_Db_Table_Row_Abstract {
public $images;
}
Then you would tell App_Model_News to use the custom row class:
class App_Model_News extends Zend_Db_Table_Abstract{
protected $_name = 'news';
protected $_primary = 'id';
protected $_rowClass = 'App_Model_Row_News';
protected $_dependentTables = array('ImagesNews');
}
Hope this helps.
精彩评论