Created
February 29, 2012 14:25
-
-
Save gautamk/1941194 to your computer and use it in GitHub Desktop.
Auto include Action Specific Css and Javascript CakePHP
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
// Add this to any `view` recommended is View/Layouts/default.ctp | |
/* | |
WWW_ROOT generally refers to your webroot directory | |
DS is usually '/' | |
$this->params['controller'] returns controller name in lowercase | |
$this->params['action'] returns action name in lowercase | |
Refer | |
* http://book.cakephp.org/2.0/en/core-libraries/global-constants-and-functions.html | |
* http://stackoverflow.com/a/1425219 | |
*/ | |
if (is_file( WWW_ROOT . 'js' . DS . $this->params['controller'] . DS . $this->params['action'] . '.js')) { | |
echo $this->Html->script($this->params['controller'].DS.$this->params['action']); | |
} | |
if (is_file(WWW_ROOT . 'css' . DS . $this->params['controller'] . DS . $this->params['action'] . '.css')) { | |
echo $this->Html->css($this->params['controller'].DS.$this->params['action']); | |
} | |
/* | |
Where to place JS and CSS files | |
APP_DIR/webroot/js/<lowercase_controller_name>/<lowercase_action_name>.js | |
APP_DIR/webroot/css/<lowercase_controller_name>/<lowercase_action_name>.css | |
Example | |
APP_DIR/webroot/js/pages/index.js | |
APP_DIR/webroot/css/pages/index.css | |
*/ |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment