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.

Use model inside helper class cakephp
Posted on February 23, 2010

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

Cakephp lightbox, cakephp modalbox
Posted on July 13, 2009

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.

  1. Download ModalBox (you also need a prototype + script.aculo.us files there.) extract them all and place the files in webroot folder. (files you should see after extraction are “js/cakemodalbox.js” , “js/modalbox.js”, “css/modalbox.css”, “css/spinner.gif”).
  2. Include  4 javascripts i.e prototype.js, scriptaculos.js, modalbox.js and cakemodalbox.js in your default template file in the same order mentioned here. (Note for cakemodalbox.js coming below modalbox.js)
  3. In your controller include 2 lines of code
    1. var $components = array(’RequestHandler’);   // note for ‘RequestHandler’
    2. var $helpers    = array(’Html’,'Javascript’, ’Ajax’);
  4. There are no changes in model specifically.
  5. Now for example you want to show a view file say your login page with lightbox then just follow the simple steps.
    1. Include var $components = array(’RequestHandler’); and var $helpers    = array(’Html’,'Javascript’, ’Ajax’); in your controller. In my case it is user controller.
    2. Now for example you want to show a view file say your login page with lightbox then just follow the simple steps.echo $html->link(’Login’,array(’action’ => ‘ControllerName/login‘),array(’title’ => ‘Customer details’,'onclick’ => “Modalbox.show(this.href, {title: this.title, width: 400}); return false;”));
  6. 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.

    Algoworks