0
votes

i am working on a Cakephp 2.x .. right now i am loading my js and css files like this

View/Layout/default.ctp

<?php echo $this->fetch('css'); ?>
<?php echo $this->fetch('script'); ?>
<?php echo $this->fetch('scriptBottom');?>

and in each view file i am doing this because there are some pages i am loading different css and js files

for example View/users/index.ctp

 echo $this->Html->script('libs/modernizr.custom',array('inline' => false));
  $this->Html->css('reset3860.css', null, array('inline' => false));
  echo $this->Html->script('libs/jquery-1.8.2.min', array('block' => 'scriptBottom'));

now the first problem i am facing right now is when i have to write js at the bottom of view page for example if i am submitting a form through ajax .. i can't write at the bottom of the index page ... because if i write there the js will go at the middle or center of the page so now what i do is i go the default.ctp and write there.. so i want to write at the bottom of the index page so it can easily managable and i can see it well what i am doing

the second question is what is the best way to manage all this ... or is there a way that i can make one file of cs and js ... in which there is only the css and js files are loaded ..and then i include that file in my default . ctp page

2

2 Answers

3
votes

You should place scriptBottom block at the bottom of your layout, after content block:

<body>
    <?php
    echo $this->fetch('script');
    echo $this->fetch('content');
    echo $this->fetch('scriptBottom');
    ?>
</body>

And then in your views (notice - NO echo):

$this->Html->script(
    'libs/jquery-1.8.2.min', 
    array('block' => 'scriptBottom')
);
$this->Html->scriptBlock(
    "alert('Boom!');",
    array('block' => 'scriptBottom')
);
0
votes

here is very good concept and also i have applied in one of my application, it is working very well

it compatible with CakePHP 2.1, and packaged it as a plugin. And also upgraded the CSS compression from CSSTidy to the more recent and better maintained CSS Min.

The plugin is quick and easy to install. The installation instructions are somewhat long - but that's just to provide clarity.

for detail view you can refer Detail link Cakephp.org also you can see the plugin document and how to use it in your appliation