doutou7286 2014-11-22 19:37
浏览 26
已采纳

Kohana框架级联文件系统。 如何将文件夹添加到此级联链?

How ussualy KO3 works: 1. Get files from "system" 2. Replace some by each used "module" 3. And finally - replace by "application"

What I must todo to add in these chain one more folder folder? How to extend this cascade ? For example I want to load classes like here:

  1. "/system/"
  2. "/modules/"
  3. "/before-plugins/"
  4. "/plugins/"
  5. "/before-application/"
  6. "/application/"

and I want that "plugins" has the same functionality as "modules" To I can initialize each plugin as module, by:

    Kohana::plugins(array(
         'plugin_1'       => PLUGPATH.'plugin_1',       // Plugin 1
         'plugin_2'       => PLUGPATH.'plugin_2',       // Plugin 2
         // and so on
        ));

And what I must to do to create one more looks-like application folder, which will autoloads before application starts? ("/before-application/" and "/before-plugins/")

I know that must put into application/classes/Kohana/Core.php copy from SYSPATH and do something. But what? Help me please!

  • 写回答

1条回答 默认 最新

  • duanjiaonie6097 2014-11-22 20:26
    关注

    You actually got it wrong. Kohana::auto_load() uses Kohana::find_file('classes', $file) for your classes. The part that applies here is

    foreach (Kohana::$_paths as $dir)
    {
        if (is_file($dir.$path))
        {
            // A path has been found
            $found = $dir.$path;
    
            // Stop searching
            break;
        }
    }
    

    and since Kohana::$_paths is

    array(11) (
        0 => string(32) "/var/www/guides/3.3/application/"
        1 => string(33) "/var/www/guides/3.3/modules/.../"
        9 => string(38) "/var/www/guides/3.3/modules/.../"
        10 => string(27) "/var/www/guides/3.3/system/"
    )
    

    application will be searched first. If nothing is found there, then Kohana will look in modules. And only if there hasn't been an existing class found, the system directory will be looked into.

    Now by editing Kohana::$_paths you can easily control the order Kohana uses for autoloading.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥50 有数据,怎么建立模型求影响全要素生产率的因素
  • ¥50 有数据,怎么用matlab求全要素生产率
  • ¥15 TI的insta-spin例程
  • ¥15 完成下列问题完成下列问题
  • ¥15 C#算法问题, 不知道怎么处理这个数据的转换
  • ¥15 YoloV5 第三方库的版本对照问题
  • ¥15 请完成下列相关问题!
  • ¥15 drone 推送镜像时候 purge: true 推送完毕后没有删除对应的镜像,手动拷贝到服务器执行结果正确在样才能让指令自动执行成功删除对应镜像,如何解决?
  • ¥15 求daily translation(DT)偏差订正方法的代码
  • ¥15 js调用html页面需要隐藏某个按钮