php - Changing the order items are retrieved from the DB in CakePHP? -


i've made forum using cakephp while following tutorial , expand it.

currently, in post allows me comment, displayed newest -> oldest, doesn't make sense , reverse this.

this current association have, i'm pretty new php/cake i'm not sure go here, appreciated!

public $hasmany = array(         'post' => array(             'classname' => 'post',             'foreignkey' => 'forum_id',             'dependent' => false,             'conditions' => '',             'fields' => '',             'order' => '',             'limit' => '',             'offset' => '',             'exclusive' => '',             'finderquery' => '',             'counterquery' => ''         ) 

for asking function in controller:

public function add($topicid=null) {         if ($this->request->is('post')) {             $this->request->data['post']['user_id'] = $this->auth->user('id');              if ($this->post->save($this->request->data)) {                 $this->session->setflash(__('post has been created'));                 $this->redirect(array('controller'=>'topics','action'=>'view',$this->request->data['post']['topic_id']));             }          } else {             if (!$this->post->topic->exists($topicid)) {                 throw new notfoundexception(__('invalid topic'));             }              $this->post->topic->recursive = -1;             $topic = $this->post->topic->read(null,$topicid);              $this->post->forum->recursive = -1;             $forum = $this->post->forum->read(null,$topic['topic']['forum_id']);              $this->set('topic',$topic);             $this->set('forum',$forum);         }     } 

something should it:

public $hasmany = array(     'post' => array(         'classname' => 'post',         'foreignkey' => 'forum_id',         'dependent' => false,         'order' => 'post.created asc' //order posts in ascending order based on whe created     ) 

assuming have created column in database table.

edit: can find more info in cakephp documentation http://book.cakephp.org/2.0/en/models/associations-linking-models-together.html


Comments

Popular posts from this blog

powershell Start-Process exit code -1073741502 when used with Credential from a windows service environment -

twig - Using Twigbridge in a Laravel 5.1 Package -

c# - LINQ join Entities from HashSet's, Join vs Dictionary vs HashSet performance -