【发布时间】:2014-11-19 20:22:31
【问题描述】:
我正在尝试构建一个注册和登录过程,但是我是 Zend 的新手,但我无法实例化模型类: 应用程序/模型/users.php 用户类扩展 Zend_Db_Table_Abstract {
protected $_name = 'users';
}
在我的引导程序中,我以这种方式执行自动加载
应用程序/引导程序
受保护的函数_initAutoload()
{
//Add autoloader empty namespace
require_once 'Zend/Loader/Autoloader.php';
$autoLoader = Zend_Loader_Autoloader::getInstance();
$resourceLoader = new Zend_Loader_Autoloader_Resource(array(
'basePath' => APPLICATION_PATH,
'namespace' => '',
'resourceTypes' => array(
'form' => array(
'path' => 'forms/',
'namespace' => 'Form_'
),
'model' => array(
'path' => 'models/',
'namespace' => 'Model_'
)
)
)
);
//Return it so that it can be stored by the bootstrap
return $autoLoader;
}
在我的控制器上我有这个
公共函数 indexAction() {
$frmuser = new Application_Form_Contact;
$users = new Application_Model_Users;
$this->view->form = $frmuser;
// action body
}
我有一个可以在 application\forms\contact.php 中正常工作的表单
Application_Form_Contact 类扩展 Zend_Form
{
public function init()
{
$this->setMethod('post');
/* Form Elements & Other Definitions Here ... */
$this->addElement('text', 'username',array('filters' => array('StringTrim'), 'required' => true,'label' => 'Enter a Username:', 'validators' => array
(array('StringLength', false, array(2, 50)))));
$this->addElement('text', 'firstname',array('filters' => array('StringTrim'), 'required' => true,'label' => 'Enter your Firstname:', 'validators' =>
array(array('StringLength', false, array(2, 50)))));
$this->addElement('text', lastname, array('filters' => array('StringTrim'), 'required' => true,'label' => 'Enter your Lastname:', 'validators' => array
(array('StringLength', false, array(2, 50)))));
$this->addElement('text', 'email', array('filters' => array('StringTrim'), 'required' => true,'label' => 'Enter your Email:', 'validators' => array
('EmailAddress', array
('StringLength', false, array(2, 50)))));
$this->addElement('text', 'emailagain', array('filters' => array('StringTrim'), 'required' => true,'label' => 'Confirm your Email:', 'validators' =>
array('EmailAddress', array('StringLength', false, array(2, 50)))));
$this->addElement('password', 'password', array('filters' => array('StringTrim'), 'required' => true,'label' => 'Enter a password:', 'validators' =>
array(array('StringLength', false, array(2, 50)))));
$this->addElement('password', 'passwordagain', array('filters' => array('StringTrim'), 'required' => true,'label' => 'Confirm your password:',
'validators'=> array(array('StringLength', false, array(2, 50)))));
$this->addElement('submit', 'contact');
$this->view->form = $form;
}
}
如果我注释掉 $users = new Application_Model_Users 表单会显示良好,但如果未注释, 指向 Internet Explorer 浏览器中的 url 将显示如下代码:
用户类扩展 Zend_Db_Table_Abstract { protected $_name = 'users'; }
【问题讨论】:
-
我只是像以前一样按照您的步骤 Indrasinh Bihola,但是当我调用实例化类的控制器的 url 时,我的浏览器上出现了 http 错误 500。
标签: zend-framework