我是zend框架的新手。我在模型文件夹中创建了 Users.php。模型文件夹的代码如下。
<?php
include("Zend/Db/Table/Abstract.php");
include("Zend/Db/Table/Row/Abstract.php");
class users extends Zend_Db_Table_Abstract {
protected $_name = 'users';
protected $_rowClass = 'Application_Model_DbTable_User';
public function fetchUsers() {
$select = $this->select();
//$select->where('completed = 0');
$select->order(array('date_created DESC', 'user_id ASC'));
return $this->fetchAll($select);
}
public function insert_user1(array $data) {
echo "called";
}
}
class Application_Model_DbTable_User extends Zend_Db_Table_Row_Abstract {
public function insert_user(array $data) {
print_r($data);
//$obj = new users();
}
}
?>
我已经创建了一个表单,并且从控制器中,我将从表单获取的数据传递给模型,以便模型随后将该数据插入数据库中。
但是如果我尝试创建用户类的对象它会产生一个致命错误。
Fatal error: Uncaught exception 'Zend_Controller_Dispatcher_Exception' with message 'Invalid controller specified (error)
如果我尝试创建一个 Application_Model_DbTable_User 类,它可以正常工作,当我调用该类的方法时,它也可以正常工作,但是当我想将数据插入数据库时,它会产生如上所述的致命错误。
这是我的控制器代码。
$data = array('first_name' => $request->getParam('first_name'),
'last_name' => $request->getParam('last_name'),
'country' => $request->getParam('country'),
'address' => $request->getParam('address'),
'username' => $request->getParam('user_name'),
'password' => $request->getParam('password'),
'password' => $request->getParam('address'),
'date_created' => date('Y-m-d H:i:s')
);
//$tasksGateway = new users();
$obj = new Application_Model_DbTable_User();
$obj->insert_user($data);
这是确切的错误:
exception 'Zend_Db_Table_Exception' with message 'No adapter found for users' in C:\wamp\www\alancer\library\Zend\Db\Table\Abstract.php:755 Stack trace: #0 C:\wamp\www\alancer\library\Zend\Db\Table\Abstract.php(739): Zend_Db_Table_Abstract->_setupDatabaseAdapter() #1 C:\wamp\www\alancer\library\Zend\Db\Table\Abstract.php(268): Zend_Db_Table_Abstract->_setup() #2 C:\wamp\www\alancer\application\models\DBTable\Users.php(22): Zend_Db_Table_Abstract->__construct() #3 C:\wamp\www\alancer\application\controllers\UserController.php(55): Application_Model_DbTable_User->insert_user(Array) #4 C:\wamp\www\alancer\library\Zend\Controller\Action.php(516): UserController->processAction() #5 C:\wamp\www\alancer\library\Zend\Controller\Dispatcher\Standard.php(295): Zend_Controller_Action->dispatch('processAction') #6 C:\wamp\www\alancer\library\Zend\Controller\Front.php(954): Zend_Controller_Dispatcher_Standard->dispatch(Object(Zend_Controller_Request_Http), Object(Zend_Controller_Response_Http)) #7 C:\wamp\www\alancer\library\Zend\Controller\Front.php(212): Zend_Controller_Front->dispatch() #8 C:\wamp\www\alancer\web_root\index.php(35): Zend_Controller_Front::run('../application/...') #9 {main}