cakephp - view content from Controller and view on a separate controller and view -


i have a

controller/postscontroller.php model/post.php view/posts/index.ctp 

if has followed cakephp blog tutorial have completed that. hasnt, site lets add title , comment. forum.

now have set , want include new page called home. , on page wont display forum created in smaller container.

i unsure how add view of posts new controller/model/view.

this postscontroller.php:

class postscontroller extends appcontroller {   public function index() {     $this->set('posts', $this->post->find('all')); }  } 

this view/posts/index.ctp

    <table>         <tr>             <th>id</th>             <th>title</th>             <th>actions</th>             <th>created</th>         </tr>      <!-- here's loop through our $posts array, printing out post info -->            <?php foreach ($posts $post): ?>           <tr>               <td><?php echo $post['post']['id']; ?></td>               <td>                   <?php                       echo $this->html->link(                           $post['post']['title']                       );                   ?>               </td>                 <td>                   <?php echo $post['post']['created']; ?>               </td>           </tr>           <?php endforeach; ?>          </table> 

so this, how same posts include on new controller , view, lets say:

homescontroller.php view/homes/index.ctp

edit//edit//edit

right have managed half of adding $this->render('/abouts/index'); postscontroller

but error saying "undefined variable: posts [app\view\abouts\index.ctp, line 12]"

im not sure how define these in abouts view

in 'abouts' action, you'd same thing doing in index:

$this->set('posts', $this->post->find('all')); 

site note: seems worth time go through blog tutorial again refresher. believe kind of thing covered pretty thoroughly.


Comments

Popular posts from this blog

javascript - Jquery show_hide, what to add in order to make the page scroll to the bottom of the hidden field once button is clicked -

javascript - Highcharts multi-color line -

javascript - Enter key does not work in search box -