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

报告相同问题?

悬赏问题

  • ¥15 任意一个散点图自己下载其js脚本文件并做成独立的案例页面,不要作在线的,要离线状态。
  • ¥15 各位 帮我看看如何写代码,打出来的图形要和如下图呈现的一样,急
  • ¥30 c#打开word开启修订并实时显示批注
  • ¥15 如何解决ldsc的这条报错/index error
  • ¥15 VS2022+WDK驱动开发环境
  • ¥30 关于#java#的问题,请各位专家解答!
  • ¥30 vue+element根据数据循环生成多个table,如何实现最后一列 平均分合并
  • ¥20 pcf8563时钟芯片不启振
  • ¥20 pip2.40更新pip2.43时报错
  • ¥15 换yum源但仍然用不了httpd