Adding page-specific Javascript to each view in CakePHP

前端 未结 9 1163
余生分开走
余生分开走 2020-12-28 09:35

In an attempt to keep my scripts maintainable, I\'m going to move each into their own file, organised by controller and action:

// scripts which only apply t         


        
9条回答
  •  失恋的感觉
    2020-12-28 09:59

    Very easy to do in your default.ctp layout file:

    An example to automatically include .css files per controller and/or controller/action (because I had this lying around, easily adaptable to .js files):

    
    ...
    params['controller'] . '.css')) {
            echo $html->css($this->params['controller']);
        }
        if (is_file(WWW_ROOT . 'css' . DS . $this->params['controller'] . DS . $this->params['action'] . '.css')) {
            echo $html->css($this->params['controller'] . '/' . $this->params['action']);
        }
    ?>
    ...
    
    

提交回复
热议问题