• Entries (RSS)
  • Comments (RSS)

CakePHP – link / include JavaScript files in layouts

Posted by | Posted in JavaScript Libraries, OpenSource, PHP, Resources, Tips and Tricks, Tutorials | Posted on 29-Dec-2008

Tagged Under : , , , , , , , , , , ,

Create (or modify the) file

app/app_controller.php

add this code

class AppController extends Controller {
	var $helpers = array('Html', 'Form', 'Javascript');
}

CakePHP 1.2 allows you to define a reference to a Javascript file which is then added to the head section of the generated code. For this purpose the variable $scripts_for_layout has to be added to the layout:

<head>
	< ?php echo $scripts_for_layout; ?>
</head>

In the view you can now link to the Javascript file with:

$javascript->link('script.js', false);
// OR you can simply use $javascript->link('script.js');
Share This:
  • Facebook
  • Digg
  • Google Bookmarks
  • Sphinn
  • del.icio.us
  • Fark
  • LinkedIn
  • Live
  • MySpace
  • StumbleUpon
  • Technorati
  • Yahoo! Buzz
  • RSS

Related Posts (auto suggestions based on tags)

Post a Comment

Get Adobe Flash playerPlugin by wpburn.com wordpress themes