简体   繁体   中英

how to load css and javascript files from a module in Zend Framework 1?

i have the fallowing structure

/app
    application/
        configs/
        modules/
             default/
                   controllers/
                   layouts/
                   views/
                   forms/
             profile/
                   controllers/
                   layouts/
                   views/
                   forms/
                   assets/
                       css/
                       js/
                       images/
    library/
    public/
        css/
        js/
        images/
        uploads/

how can i load js and css files from

/application/modules/profile/assets/... ?

and use something similar with

$this->view->headLink()->appendStylesheet('path/to/file');

any ideas on this issue?

The HeadLink view helper only manages the references to CSS files which are rendered in the section of your HTML page. These stylesheets should have always have a public URL, which means that they'll have to reside somewhere in the 'public' folder.

One solution would be to just move the CSS files there. Another solution would be tohave some kind of PHP script which reads the CSS files from the location outside the 'public' folder and then prints the content of it. Zend Framework does not have a standard component for this though, so I would recommend to reorganise the project, so all the CSS can reside somewhere in the 'public' folder.

Although, I agree with P44T that the style sheets should always be kept inside of the public folder there are some cases where you might need to add some additional styling from your module as you do. One example of doing so is if you want to distribute your module separate from the application and you don't want to add the style sheet separately from adding the module.

Here is one example of how you could that from any view:

<?php $this->headStyle()->captureStart() ?>
    // add plain css or include a file like this:
    <?php include APPLICATION_PATH . 'modules/[modulename]/assets/css/style.css'; ?>
<?php $this->headStyle()->captureEnd() ?>

Hope this helps :)

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