我是zend框架的新手,我发现了一些关于我的问题的材料,但对我来说没什么用。我试图通过Zend纪念API,所以我决定连接IndexController.php中的indexAction。我可以粘贴代码,但服务器在我写的代码之前停止,在脚本的第三行说:
Debug Error: /imball-reagens/application/controllers/IndexController.php line 4 -
Class 'Zend_Controller_Action' not found
我再次下载了zend框架,并将下载的库文件夹放在我项目的库文件夹中。在我输入的项目的“index.php”文件中:
require_once 'Zend/Controller/Action.php';
但该课程仍无法实现。并且要求不会引起任何异常。
我做错了什么?你通常如何在zend开始一个项目?你不使用IndexAction控制器吗?默认情况下,库不应该包含在zend项目中吗?我用zend studio开始了这个项目,我的index.php说:
if (function_exists('zend_deployment_library_path') && zend_deployment_library_path('Zend Framework 1')) {
$paths[] = zend_deployment_library_path('Zend Framework 1');
}
我正在使用Zend Framework 1.12 谢谢你的帮助
更新:**
index.php
完整文件:
<?php
// Define path to application directory
defined('APPLICATION_PATH')
|| define('APPLICATION_PATH', realpath(dirname(__FILE__) . '/../application'));
// Define application environment
defined('APPLICATION_ENV')
|| define('APPLICATION_ENV', (getenv('APPLICATION_ENV') ? getenv('APPLICATION_ENV') : 'production'));
$paths = array(realpath(APPLICATION_PATH . '/../library'));
if (function_exists('zend_deployment_library_path') && zend_deployment_library_path('Zend Framework 1')) {
$paths[] = zend_deployment_library_path('Zend Framework 1');
}
$paths[] = get_include_path();
set_include_path(implode(PATH_SEPARATOR, $paths));
/** Zend_Application */
require_once 'Zend/Application.php';
require_once 'Zend/Controller/Action.php';
// Create application, bootstrap, and run
$application = new Zend_Application(
APPLICATION_ENV,
APPLICATION_PATH . '/configs/application.ini'
);
$application->bootstrap()
->run();
完成IndexController.php:
<?php
class IndexController extends Zend_Controller_Action
{
public function init()
{
/* Initialize action controller here */
}
public function indexAction()
{
try {
$uri = "http://api.box.com/2.0/folders/0/items?";
$headers = array(
'Authorization: Bearer API_KEY',
);
$config = array(
'adapter' => 'Zend_Http_Client_Adapter_Curl',
'curloptions' => array(CURLOPT_FOLLOWLOCATION => true,
CURLOPT_HTTPHEADER=>$headers,
CURLOPT_SSL_VERIFYPEER=> false
//CURLOPT_USERPWD, "username:password"
),
);
$client = new Zend_Http_Client($uri, $config);
$response = $client->request();
$text= $response->getBody();
$view = new Zend_View();
$view->assign(text, $text);
} catch (Zend_Exception $e) {
echo "Message: " . $e->getMessage() . "\n";
// Other code to recover from the error
}
}
}
答案 0 :(得分:1)
不确定您的index.php代码是否正确。通常你需要这样的东西:
// define path to application directory
defined('APPLICATION_PATH')
|| define('APPLICATION_PATH', __DIR__ . '/../application');
// Define application environment
defined('APPLICATION_ENV')
|| define('APPLICATION_ENV', (getenv('APPLICATION_ENV')
? getenv('APPLICATION_ENV') : 'production'));
// set include path
set_include_path(realpath(APPLICATION_PATH . '/../library')
. PATH_SEPARATOR . get_include_path());
require_once 'Zend/Application.php';
答案 1 :(得分:0)
使用,
require_once 'Zend/Application.php';
在index.php而不是require_once 'Zend/Controller/Action.php';
中输入并尝试。
<强> UPADTE 强>
确保您使用的是zf1.12库,而不是zf&gt; 2 ..
Zf1 downland LINK