【问题标题】:Multiple Paths for img and css in CakePHP 3.4CakePHP 3.4 中 img 和 css 的多个路径
【发布时间】:2019-03-14 07:16:01
【问题描述】:

我正在运行多个蛋糕应用程序,它们共享一个核心/基础应用程序。

基本结构是: www/myapp1 www/myapp2 www/myapp3 www/baseapp

在 app.php 中的每个“myapp”中,我将模板和插件的路径指向 myapp 和 baseapp,以便如果在 myapp 中找不到文件,则使用来自 baseapp 的文件:

'App' => [
        'imageBaseUrl' => 'img/',
        'cssBaseUrl' => 'css/',
        'jsBaseUrl' => 'js/',
        'paths' => [
            'plugins' => [ROOT.DS .'modules'.DS, BASEROOT . DS . 'modules' . DS],
            'templates' => [APP . 'Template' . DS, BASEROOT.'/src/Template'.DS ],
        ],
    ],

(我在 composer.json 中包含来自 baseapp 的类,这可能与这个问题无关)

效果很好。

问题: 如何让它以相同的方式包含 img、css 和 js? 我想拥有一个文件夹,蛋糕应该在其中搜索每个应用程序的文件。

'App' => [ 'imageBaseUrl' => ['img/', BASEROOT. DS . 'webroot/img/'] 

不工作。

【问题讨论】:

    标签: cakephp-3.0


    【解决方案1】:

    我的解决方案:在 webroot 文件夹中,我创建了一个指向 BASEROOT 的链接(名称为“baseroot”),然后创建了文件 src/View/UrlHelper

    class UrlHelper extends CakeUrlHelper{
        public function webroot($file){
            //code
            if (file_exists(\Cake\Core\Configure::read('App.wwwRoot') . $file)) {       
                $webPath = $this->request->getAttribute('webroot') . $asset[0];
            }else{
               $webPath = $this->request->getAttribute('webroot').'baseroot'.DS.$asset[0];
            }
            //more code
        }
    }   
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2018-06-05
      • 1970-01-01
      • 2018-06-18
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多