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

自古美人都是妖i 提交于 2019-12-11 09:04:38

问题


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?


回答1:


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.




回答2:


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 :)



来源:https://stackoverflow.com/questions/15305130/how-to-load-css-and-javascript-files-from-a-module-in-zend-framework-1

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!