|
|||
|
function viewAction() {
$this->view->title='Příspěvek'; $this->post=new Post(); $select=$this->post->select(); $select->setIntegrityCheck(false); $select->from($this->post,array('id','name','activity','id_no','post', 'attachment','date_format(created,"%d.%m.%Y") AS datum')); $select ->join(array('u'=>'users'),'u.id=posts.user_id') ->join(array('cat'=>'category'),'posts.category_id= cat.id','category') ->join(array('loc'=>'locality'),'loc.id=posts.local ity_id') ->order("created DESC")->limit(1); echo $select; //po->limit(5,5); //Zend_Debug::dump($select); $this->view->post=$this->post->fetchAll(); } creates me a query like this: SELECT `posts`.`id`, `posts`.`name`, `posts`.`activity`, `posts`.`id_no`, `posts`.`post`, `posts`.`attachment`, date_format(created,"%d.%m.%Y") AS `datum`, `u`.*, `cat`.`category`, `loc`.* FROM `posts` INNER JOIN `users` AS `u` ON u.id=posts.user_id INNER JOIN `category` AS `cat` ON posts.category_id=cat.id INNER JOIN `locality` AS `loc` ON loc.id=posts.locality_id ORDER BY `created` DESC LIMIT 1 however, when i vardump $this->view->post i don't get data from joined tables. |
|
||||
|
First off, I recommend moving all of the querying stuff to your model file, and use that method in your Controller.
2nd, you may find that you need to set the results of $this-post-fetchAll(); to another variable, and then set that var to your view for it to give you your data (I'm assuming when you vardump the view var, you're getting metadata about your table, and not the data). Also, vardump in the view, and work on $this->post and not $this->view->post. HTH,
__________________
- xentek |
![]() |
| Thread Tools | |
| Display Modes | |
|
|