dor2p0520 2014-01-15 10:40
浏览 23

索引文件中的对象实例化不起作用

I am trying to structure my Slim application like

app
  index.php
  config
  lib
  vendor
  assets
  templates
sys
 Slim

and my index.php looks like

if (!defined('DS')) {
    define('DS', DIRECTORY_SEPARATOR);
}

if (!defined('APP_DIR')) {
    define('APP_DIR', basename(dirname(__FILE__)));
}

if (!defined('ROOT_DIR')) {
    define('ROOT_DIR', dirname(dirname(__FILE__)));
}

if (function_exists('ini_set')) {
    ini_set('include_path', ROOT_DIR . DS . 'sys' . PATH_SEPARATOR . ini_get('include_path'));
}



require '/Slim/Slim.php';
\Slim\Slim::registerAutoloader();  

But can't instanciate Slime object. What I am doing here wrong?

  • 写回答

1条回答 默认 最新

  • du9826 2014-03-04 18:35
    关注

    Your path to "require '/Slim/Slim.php'" is wrong.

    If you want to load Slim.php from index.php then you need to go one step up (to parent folder) then enter sys directory then Slim and Slim.php is located there. It is important to understand this.

    So this should work:

    require '../sys/Slim/Slim.php';
    

    Let's understand code:

    • '..' means move to parent folder. In your case that is "app"
    • '/sys' means enter sys directory
    • '/Slim' we are now in slim directory
    • 'Slim.php' and finally we tell include Slim.php file
    评论

报告相同问题?

悬赏问题

  • ¥100 为什么这个恒流源电路不能恒流?
  • ¥15 有偿求跨组件数据流路径图
  • ¥15 写一个方法checkPerson,入参实体类Person,出参布尔值
  • ¥15 我想咨询一下路面纹理三维点云数据处理的一些问题,上传的坐标文件里是怎么对无序点进行编号的,以及xy坐标在处理的时候是进行整体模型分片处理的吗
  • ¥15 CSAPPattacklab
  • ¥15 一直显示正在等待HID—ISP
  • ¥15 Python turtle 画图
  • ¥15 stm32开发clion时遇到的编译问题
  • ¥15 lna设计 源简并电感型共源放大器
  • ¥15 如何用Labview在myRIO上做LCD显示?(语言-开发语言)