I'm working on an invoicing system using CakePHP, its fairly basic to start off with. I've used the Blog Tutorial (http://book.cakephp.org/2.0/en/getting-started.html) as the basis for my project. I've also installed Twitter's Bootstrap framework.
I'm using tabs for navigation. So at the moment the user will have the following tab options:
Summary - Invoices - Expenses - Banking - Contacts - More
In the Apps->View folder I have a Contacts folder and an Invoices folder, these folders have the following files:
index.ctp - this is the general layout of the page i.e. for invoices and contacts its just a table listing all the entries from the database.
view.ctp - this displays a detailed view when the user clicks on a table entry.
add.ctp - each view has an add button and this script is the layout of the add page.
In the Apps->View->Elements folder I have the code for the tabbed navigation (tabs.ctp). I have the following line of code in Apps->View->Contacts->index.ctp & Apps->View->Invoices->index.ctp:
<? echo $this->element('tabs'); ?>
This displays the tabbed navigation in each view.
In my App->Config->routes.php I have the following code:
Router::connect('/', array('controller' => 'invoices', 'action' => 'index'));
obviously this makes Apps->View->Invoices->index.ctp the initial page the user views.
But when the application loads, I can see the Invoices page with no issues, but when I try and click on the Contacts tab nothing happens. When I look at the source code, the contacts view code is not loaded.
I may have laid out the project incorrectly, so any help appreciated.
UPDATE: Code from ContactsController.php:
<?php
class ContactsController extends AppController {
public $helpers = array('Html', 'Form', 'Session');
public $components = array('Session');
public function index() {
$this->set('contacts', $this->Contact->find('all'));
}
public function view($id) {
if (!$id) {
throw new NotFoundException(__('Invalid contact'));
}
$contact = $this->Contact->findById($id);
if (!$contact) {
throw new NotFoundException(__('Invalid contact'));
}
$this->set('contact', $contact);
}
public function add() {
if ($this->request->is('contact')) {
$this->Contact->create();
if ($this->Contact->save($this->request->data)) {
$this->Session->setFlash('Your contact has been saved.');
$this->redirect(array('action' => 'index'));
} else {
$this->Session->setFlash('Unable to add your contact.');
}
}
}
}
UPDATE Sample code from routes.php:
/**
* Here, we are connecting '/' (base path) to controller called 'Pages',
* its action called 'display', and we pass a param to select the view file
* to use (in this case, /app/View/Pages/home.ctp)...
*/
//Router::connect('/', array('controller' => 'pages', 'action' => 'display', 'home'));
Router::connect('/', array('controller' => 'invoices', 'action' => 'index'));
/**
* ...and connect the rest of 'Pages' controller's urls.
*/
Router::connect('/pages/*', array('controller' => 'pages', 'action' => 'display'));
/**
* Load all plugin routes. See the CakePlugin documentation on
* how to customize the loading of plugin routes.
*/
CakePlugin::routes();
/**
* Load the CakePHP default routes. Only remove this if you do not want to use
* the built-in default routes.
*/
require CAKE . 'Config' . DS . 'routes.php';
Regards, Stephen
<? echo
with<?php echo
. Short opening tags are disabled on most servers and discouraged – thaJeztahapp/Config/core.php
look for this line inside that file:Config::write('debug', 2);
the 2 is the debug level. Even better: install the official Debugkit plugin; it gives a lot more configuration that help debugging your code. It's possible that there's some error in your application (e.g. Missing Model or database table), but that this error is not showing because debug messages are disabled – thaJeztahContactsController
insideapp/Controllers/ContactsController.php
? Does it have aindex()
method and does it extend theAppController
? Also, did you keep the 'default' CakePHP routes inside your routes.php? – thaJeztah