简体   繁体   中英

Add js and css files to views in zend framework

I want to add script files and css files to my php view page inside a module, I try to make like this

   <base href="<?php echo $this->baseUrl(); ?>" />
    <link rel="stylesheet" type="text/css"  href="<?php echo $this->baseUrl('style/ui-lightness/jquery-ui-1.8.18.custom.css'); ?>"/>

and like this

    <?php
    $this->headScript()->appendFile('js/jquery-1.7.1.min.js');
    echo $this->headScript();
    ?>

but both of them do not inlucde the files. I put my css and js files inside the helpers folder of view folder.

Your JS and CSS files are in the wrong place.

The helpers folder of the the view folder isn't even in the web root (by default), so you literally cannot request it from the web server.

Put them somewhere under the web root, and then give a path to them in the view script.

As your view script may be a few folders deep, I tend to use absolute paths. (/js/jquery...).

You could alternatively programmatically calculate the absolute or relative path to the file and use it. (If you're at controller1/ you'll need to do ../js/jquery, but if you're at controller1/action/ you'll need to do ../../js/jquery.)

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM