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?