Cake PHP tips for the beginner
So, you have started to use Cake PHP and thought you’d read the seemingly in-depth documentation on their website only to find that some of the basic things aren’t really covered.
A few things that you may find useful are:
Using a model without a database table
Put this code in your model definition at the top
var $useTable = false;
or
var $useTable = 'some_different_table_name';
Creating a controller that references other models
Put this at the top of your controller definition
var $uses = array('Sheep,'Farmer');
Static pages without using a controller and actions
If you just want some quick static html pages put some .thtml files in your /views/pages directory.
These are immediately available in your browser at
http://www.your-site.co.uk/pages/staticpagename
Adjusting the page title when using $title_for_layout
Add this to the static view
$this->pageTitle = 'Title of your page.'
Setting variables to use from your static pages
Put this at the top of your view and you can use it to set a body class or something in your default layout depending on what static page is rendered.
$this->_viewVars['variable_name'] = ‘Data’;
Reference it with $variable_name
Thats it.
Activity