Hey man, there are a few ways to deal with this, I'd strongly recommend
against making a controller for your information pages! CakePHP comes with
a PagesController by default, all you need to do is add a about.ctp to
/app/View/Pages/ and enter /pages/about in the URL to display that page.
You may route it if you want an url like www.mysite.com/about

That fixes the problem of creating pages, a couple of things to look into
would be elements (include small html files in any view or layout) and
requestAction which can be used to get data from any controller from within
the view.

http://book.cakephp.org/2.0/en/views.html#elements

http://book.cakephp.org/2.0/en/controllers.html#Controller::requestAction


On 13 August 2014 13:23, Matthew Smart <[email protected]> wrote:

> New to Cakephp and im struggling a little bit, wonder if you could help...
>
> so ive followed CakePHP blog tutorial and completed it. after making the
> blog, the controller is called PostsController.php the model is Post.php
> and the view is in Posts/index.ctp.
>
> I will provide code(not the full as only the relevent needed to explain)
>
> Controller/PostsController.php is as follows:
>
>     <?php
>     class PostsController extends AppController {
>         public $helpers = array('Html', 'Form');
>
>         public function index() {
>              $this->set('posts', $this->Post->find('all'));
>              $this->set('title_for_layout', 'forums');
>         }
>
>
>
>
>        public function add() {
>             if ($this->request->is('post')) {
>                 $this->Post->create();
>                 if ($this->Post->save($this->request->data)) {
>                     $this->Session->setFlash(__('Your post has been saved.'));
>                     return $this->redirect(array('action' => 'index'));
>                 }
>                 $this->Session->setFlash(__('Unable to add your post.'));
>             }
>         }
>
>
>
>
>
>
>
>     }
>     ?>
>
> View/Posts/index.ctp is as follows:
>
>     <?php echo "<h1>" . $this->Html->link('Add Post', array('action' => 
> 'add')); ?>
>
>     <table style="float: left; margin-left: 100px; display: none; " 
> id="hidethis">
>
>     <!-- Here's where we loop through our $posts array, printing out post 
> info -->
>
>         <?php foreach ($posts as $post): ?>
>         <tr>
>             <td width="22%" style=" font-size: .75em; text-align: left;">
>                 <?php echo $post['Post']['created']; ?>
>
>
>             </td>
>             <td width="78%">
>                  <?php
>                     echo
>                         $post['Post']['title']
>                     ;
>                  ?>
>              </td>
>
>
>         </tr>
>
>         <?php endforeach; ?>
>
>     </table>
>
> Model/Post.php is as follows:
>
>     <?php
>     class Post extends AppModel {
>          public $validate = array(
>             'title' => array(
>                 'rule' => 'notEmpty'
>             ),
>             'body' => array(
>                 'rule' => 'notEmpty'
>             )
>         );
>     }
>     ?>
>
> so this works fine,however i want to have a website with 3 main pages;
> Home, About us, Contact Us.
>
> now on the about us page i will have content and a section i want to be
> the posts that i created as seen in the examples above. However to do this
> i want to be able to have: Controller/AboutsController.php, Model/About.php
> view/Abouts/about.ctp and kind of require/include the whole Posts MVC.
>
> and if i was to just make my about us page the Posts MVC then the names
> wouldnt be really what i wont them to, meaning the pages would be called
> posts instead of about, due to cakephp naming conventions.
>
> I hope this makes sense, can any one help please?
>
> --
> Like Us on FaceBook https://www.facebook.com/CakePHP
> Find us on Twitter http://twitter.com/CakePHP
>
> ---
> You received this message because you are subscribed to the Google Groups
> "CakePHP" group.
> To unsubscribe from this group and stop receiving emails from it, send an
> email to [email protected].
> To post to this group, send email to [email protected].
> Visit this group at http://groups.google.com/group/cake-php.
> For more options, visit https://groups.google.com/d/optout.
>



-- 
Kind Regards
 Stephen Speakman

-- 
Like Us on FaceBook https://www.facebook.com/CakePHP
Find us on Twitter http://twitter.com/CakePHP

--- 
You received this message because you are subscribed to the Google Groups 
"CakePHP" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
To post to this group, send email to [email protected].
Visit this group at http://groups.google.com/group/cake-php.
For more options, visit https://groups.google.com/d/optout.

Reply via email to