I have noticed that several people are searching for “How to set page title, Meta keyword/description in Cakephp 1.3” so this is a quick tip for them: -
You can change the title of the page from the controllers function using $pageTitle in CakePHP 1.2.
Your layout needs to include the “$title_for_layout” variable, at least between the <title> and </title> tags in the head of the HTML document.
<?php
class RecipesController extends AppController {
function quickSave() {
$this->pageTitle = ‘My search engine optimized title’;
}
?>
You can also set the page title from the view .CTP file using
$this->pageTitle (‘Algoworks.com’);
But, this has been removed in cakephp 1.3.
Yes it’s possible to set it from controller action, but what about
static pages for Pages controller? Pages controller has only one
action ‘display’. So setting title from controller doesn’t “work” for
many pages!
But.. I found the solution to set title from view (in .ctp file):
<?php $this->viewVars['title_for_layout']=”Page title” ?>
<?php $this->viewVars['meta_keywords']=”Page Keyword” ?>
<?php $this->viewVars['meta_description']=”Page Description” ?>
And Your layout needs to include
<meta name=”keywords” content=”<?php echo $meta_keywords; ?>”>
<meta name=”description” content=”<?php echo $meta_description; ?>”>
lines, at least between the <title> and </title> tags in the head of the HTML document.
Hello All,
Finally after researching for hours we got the solution to call a model inside a helper class. we hope this helps you.
In a method of your helper class just use : $this->ModelName=& ClassRegistry::init(’ModelName’);
And now $this->ModelName has all the property of the model.
Do let us know if you are unable to use the same.
Happy Algo-blogging.
Hello All,
This is something interesting to implement.
Are you bored with .ctp extension in cakephp view file and want to have something interesting which helps to make coding even faster in cake, here is the solution to make .ctp extinsion change to .php
In your controller just add “ var $ext = ‘.php’ ” and make all your template files as .php insted of .ctp.
For example.
class UsersController extends AppController {
var $name = ‘Users’;
var $helpers = array(’Html’, ‘Form’,'Session’,'Javascript’);
var $components = array (’Auth’, ‘Cookie’, ‘RequestHandler’);
var $ext = ‘.php’;
function index() {
// Do something
}
}
Now create a file in app/views/users/index.php
The only use as far as i see of doing this is to make the coding editor friendly as the editor understand .php extension and not .ctp
Hope this tutorial helped you
Thanks and happy Algo blogging
Hello friends getting lightbox/modalbox in to the application is really an addon to the site.
Here are few simple steps to get lightbox/modalbox working on your cakephp site.
change the ‘ControllerName’ as per your need.
Likeways you can show any page in a light box or modalbox.
Do let us know in case of any issue.