Warning: require_once(../models/Message.php) [​​function.require-once​​]: failed to open stream: No such file or directory in F:\xampp\htdocs\zendfrm\application\controllers\IndexController.php on line 2

Call Stack

#

Time

Memory

Function

Location

1

0.0029

340224

{main}( )

..\index.php:0

2

0.0390

2197240

Zend_Application->run( )

..\index.php:26

3

0.0390

2197240

Zend_Application_Bootstrap_Bootstrap->run( )

..\Application.php:366

4

0.0391

2197296

Zend_Controller_Front->dispatch( ???, ??? )

..\Bootstrap.php:97

5

0.0509

3507920

Zend_Controller_Dispatcher_Standard->dispatch( object(Zend_Controller_Request_Http)[14],object(Zend_Controller_Response_Http)[15]

..\Front.php:954

6

0.0515

3507976

Zend_Controller_Dispatcher_Standard->loadClass( string(15)

..\Standard.php:262

7

0.0526

3526248

include_once( 'F:\xampp\htdocs\zendfrm\application\controllers\IndexController.php'

..\Standard.php:344



( ! ) Fatal error: require_once() [​​function.require​​]: Failed opening required '../models/Message.php' (include_path='F:\xampp\htdocs\zendfrm\application/../library;F:\xampp\htdocs\zendfrm\library;.;F:\xampp\php\PEAR') in F:\xampp\htdocs\zendfrm\application\controllers\IndexController.php on line 2

Call Stack

#

Time

Memory

Function

Location

1

0.0029

340224

{main}( )

..\index.php:0

2

0.0390

2197240

Zend_Application->run( )

..\index.php:26

3

0.0390

2197240

Zend_Application_Bootstrap_Bootstrap->run( )

..\Application.php:366

4

0.0391

2197296

Zend_Controller_Front->dispatch( ???, ??? )

..\Bootstrap.php:97

5

0.0509

3507920

Zend_Controller_Dispatcher_Standard->dispatch( object(Zend_Controller_Request_Http)[14],object(Zend_Controller_Response_Http)[15]

..\Front.php:954

6

0.0515

3507976

Zend_Controller_Dispatcher_Standard->loadClass( string(15)

..\Standard.php:262

7

0.0526

3526248

include_once( 'F:\xampp\htdocs\zendfrm\application\controllers\IndexController.php'

..\Standard.php:344

直接用require_once '../models/Message.php';  报错
//此方法能解决路径不对的错误
 方法1   require_once  dirname(dirname(__FILE__)).'/models/Message.php';

方法2   require_once APPLICATION_PATH.'/models/Message.php';

原因如下:

echo __FILE__ ; // 取得当前文件的绝对地址,结果:D:\www\test.php
echo dirname(__FILE__); // 取得当前文件所在的绝对目录,结果:D:\www\
echo dirname(dirname(__FILE__)); //取得当前文件的上一层目录名,结果:D:\


<?php
require_once '../models/Message.php';
//此方法能解决路径不对的错误
//require_once dirname(dirname(__FILE__)).'/models/Message.php';
class IndexController extends Zend_Controller_Action
{
//这是初始化函数
public function init()
{
/* Initialize action controller here */

file_put_contents("d:/mylog.txt", __FILE__.date('y-m-d h:i:s')."init..\r\n",FILE_APPEND);
} //控制器中的一个函数
public function indexAction()
{
// action body
file_put_contents("d:/mylog.txt", __FILE__.date('y-m-d h:i:s')."index..\r\n",FILE_APPEND);
//如果什么都没有些,相当于有以下一句话;用view/scripts/index/index.phtml
$messageModel=new Message();
$res=$messageModel->fetchAll();
echo '<pre>';
print_r($res);
echo '</pre>';

$this->render('index');
} public function testAction(){
}
}