我正在尝试构建一个注册和登录过程,我怎么不熟悉Zend我无法实例化一个模型类: 应用程序/模型/ users.php class用户扩展Zend_Db_Table_Abstract {
protected $_name = 'users';
}
在我的bootstrap中我以这种方式执行自动加载
应用/自举
受保护的功能_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;
}
在我的控制器上我有这个
public function 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'; }
答案 0 :(得分:0)
定义模型的最简单方法是使用 zftool 。
或者您可以在此类应用程序中进行更改,以使您的模型正常工作:
<强>应用\模型\ DBTABLE \ users.php 强>
class Application_Model_DbTable_Users extends Zend_Db_Table_Abstract {
protected $_name = 'users';
}
现在,您可以在Controller中访问它:
$users = new Application_Model_DbTable_Users();
zend框架文档中提供了更多详细信息:
仔细阅读以找出实施它的完美方式: