drd43058 2017-03-30 11:26
浏览 45
已采纳

如何在Laravel中设置CodeIgniter中的assets文件夹

like the public folder given by laravel default i tried to create something like that for easy make up of my css, js, picture and so on. I tried configuring it like this. In my application/helpers/utility_helpers.php

    <?php
    function asset_url()
    {
  return base_url().'assets/';
    }
     ?>

I have my assests folder along with application, system, user_guide etc. i confugured the autoload function of application/config as :

    $autoload['helper'] = array('url','utility');

when i hit any url in browser now, it says

    An Error Was Encountered

    Unable to load the requested file: helpers/utility_helper.php

how can i make it and can you explain me if i need to specify root for that helpers also.And if not can i simply access the assets like this:

    <img src="assets/base_components/build/banner.png">

in my view

  • 写回答

3条回答 默认 最新

  • duanke6057 2017-04-20 17:58
    关注

    In fact the answer is very simple, you only need to put ../ before every file that is under assets folder, because the root of the codeigniter is in application folder, but how you can't put the assets folder there and for the best practices, let the structure of the project like below and apply this solution to the path of the files:

    Website Folder structure
    |---|application\
    |-------(CodeIgniter application folders...)
    |---|assets\
    |-------css\
    |-------images\
    |-------js\
    |-------robots.txt
    |---|system
    |-----(CodeIgniter system folder...)
    |index.php

    Path of the files
    ex.:
    CSS

    <link href="../assets/css/bootstrap.min.css" rel="stylesheet">
    
    <link href="../assets/css/plugins/font-awesome.css" rel="stylesheet">
    

    IMAGES and others

    <img src="../assets/images/build/banner.png">
    

    JAVASCRIPT

    <script src="../assets/js/jquery-2.1.4.js"></script>
    
    <script src="../assets/js/plugins/jquery.scrollSpeed.js"></script>
    

    Note.:
    Always remember to applay the best practices to the code too (this will help for the performance of the the page too), like below:

    <html>
        <head>
            meta tags
            favicons
            css files styles
        </head>
        <body>
            page structure code
    
            javascript files
        </body>
    </html>
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(2条)

报告相同问题?

悬赏问题

  • ¥100 求三轴之间相互配合画圆以及直线的算法
  • ¥100 c语言,请帮蒟蒻写一个题的范例作参考
  • ¥15 名为“Product”的列已属于此 DataTable
  • ¥15 安卓adb backup备份应用数据失败
  • ¥15 eclipse运行项目时遇到的问题
  • ¥15 关于#c##的问题:最近需要用CAT工具Trados进行一些开发
  • ¥15 南大pa1 小游戏没有界面,并且报了如下错误,尝试过换显卡驱动,但是好像不行
  • ¥15 自己瞎改改,结果现在又运行不了了
  • ¥15 链式存储应该如何解决
  • ¥15 没有证书,nginx怎么反向代理到只能接受https的公网网站