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
    评论

报告相同问题?

悬赏问题

  • ¥20 sub地址DHCP问题
  • ¥15 delta降尺度计算的一些细节,有偿
  • ¥15 Arduino红外遥控代码有问题
  • ¥15 数值计算离散正交多项式
  • ¥30 数值计算均差系数编程
  • ¥15 redis-full-check比较 两个集群的数据出错
  • ¥15 Matlab编程问题
  • ¥15 训练的多模态特征融合模型准确度很低怎么办
  • ¥15 kylin启动报错log4j类冲突
  • ¥15 超声波模块测距控制点灯,灯的闪烁很不稳定,经过调试发现测的距离偏大