我正在 cakePHP 中构建一个应用程序,并希望将 Zend Framework 2 与它一起使用。我特别想使用的 2 个组件是验证码和 lucene(我知道它是单独维护的)
我在 app/vendor 中添加了 ZF2 库文件夹。
我尝试使用在各个站点上找到的两种方法来使用 Zend 类。
在我的控制器方法中添加了行
App::import('Vendor', 'Zend_Captcha_Figlet', true, false, 'Zend/Captcha/Figlet.php');
这给了我一个错误
Error: Class 'Zend\Captcha\AbstractWord' not found
然后我继续添加所有缺失的课程。
App::import('Vendor', 'Zend_Captcha', true, false, 'Zend/Captcha.php');
App::import('Vendor', 'Zend_Validator_ValidatorInterface', true, false, 'Zend/Validator/ValidatorInterface.php');
App::import('Vendor', 'Zend_Validator_Translator_TranslatorAwareInterface', true, false, 'Zend/Validator/Translator/TranslatorAwareInterface.php');
App::import('Vendor', 'Zend_Validator_AbstractValidator', true, false, 'Zend/Validator/AbstractValidator.php');
App::import('Vendor', 'Zend_Stdlib_ArrayObject_PhpReferenceCompatibility', true, false, 'Zend/Stdlib/ArrayObject/PhpReferenceCompatibility.php');
if (version_compare(PHP_VERSION, '5.3.4', 'lt')) {
class_alias('Zend/Stdlib/ArrayObject/PhpLegacyCompatibility', 'Zend/Stdlib/AbstractArrayObject');
} else {
class_alias('Zend_Stdlib_ArrayObject_PhpReferenceCompatibility', 'Zend/Stdlib/AbstractArrayObject');
}
App::import('Vendor', 'Zend\Stdlib\ArrayObject\PhpLegacyCompatibility', true, false, 'Zend/Stdlib/ArrayObject/PhpLegacyCompatibility.php');
App::import('Vendor', 'Zend_Stdlib_AbstractArrayObject',true,false,'Zend/Stdlib/AbstractArrayObject.php');
App::import('Vendor', 'Zend_Stdlib_ArrayObject', true, false, 'Zend/Stdlib/ArrayObject.php');
App::import('Vendor', 'Zend\Session\Container\PhpLegacyCompatibility', true, false, 'Zend/Session/Container/PhpLegacyCompatibility.php');
if (version_compare(PHP_VERSION, '5.3.4', 'lt')) {
class_alias('Zend\Session\AbstractContainer', 'Zend\Session\AbstractBaseContainer');
} else {
class_alias('Zend\Session\Container\PhpReferenceCompatibility', 'Zend\Session\AbstractBaseContainer');
}
App::import('Vendor', 'Zend_Session_Container', true, false, 'Zend/Session/Container.php');
App::import('Vendor', 'Zend_Captcha_Exception_ExceptionInterface', true, false, 'Zend/Captcha/Exception/ExceptionInterface.php');
App::import('Vendor', 'Zend_Captcha_Exception_InvalidArgumentException', true, false, 'Zend/Captcha/Exception/InvalidArgumentException.php');
App::import('Vendor', 'Zend_Captcha_AdapterInterface', true, false, 'Zend/Captcha/AdapterInterface.php');
App::import('Vendor', 'Zend_Captcha_AbstractAdapter', true, false, 'Zend/Captcha/AbstractAdapter.php');
App::import('Vendor', 'Zend_Captcha_AbstractWord', true, false, 'Zend/Captcha/AbstractWord.php');
App::import('Vendor', 'Zend_Text_Figlet_Figlet', true, false,'Zend/Text/Figlet/Figlet.php');
App::import('Vendor', 'Zend_Math_Rand', true, false, 'Zend/Math/Rand.php');
App::import('Vendor', 'Zend_Captcha_Figlet', true, false, 'Zend/Captcha/Figlet.php');
..直到我被困在这里:
Class 'Zend/Stdlib/ArrayObject/PhpReferenceCompatibility' not found
线路错误class_alias('Zend_Stdlib_ArrayObject_PhpReferenceCompatibility', 'Zend/Stdlib/AbstractArrayObject');
在哪里 class_alias('Zend_Stdlib_ArrayObject_PhpReferenceCompatibility', 'Zend/Stdlib/AbstractArrayObject');
解决这个' Error: Class 'Zend\Session\AbstractBaseContainer' not found
'
方法 2 - 抱歉找不到链接
创建组件并添加方法
public function initialize(){
$include = get_include_path();
$include.= PATH_SEPARATOR. APP . 'vendors' . DS;
$successful = set_include_path($include);
if (!$successful) {
throw new Exception('ZendComponent failed to set include path.', E_ERROR);
}
App::import('Vendor', 'Loader',true,false,'Zend/Loader.php');
}
public function loadClass($class, $dirs = null){
Zend_Loader::loadClass($class, $dirs);
}
并在控制器方法中调用 $this->Zend->loadClass('Captcha');
声明组件后。
但它在给出错误后退出:Error: Class 'Zend_Loader' not found
对这两个代码中的任何一个的任何帮助或对最新文档/博客的任何指针都表示赞赏。