我的應用程序模型有問題。它應該在mysql數據庫中保存一個新用戶。Zend_Db_Abstract子類(模型)
應用/配置/的application.ini
[production]
phpSettings.display_startup_errors = 1
phpSettings.display_errors = 1
includePaths.library = APPLICATION_PATH "/../library"
bootstrap.path = APPLICATION_PATH "/Bootstrap.php"
bootstrap.class = "Bootstrap"
appnamespace = "Application"
resources.frontController.params.displayExceptions = 1
resources.frontController.controllerDirectory = APPLICATION_PATH "/controllers"
resources.layout.layoutPath = APPLICATION_PATH "/layouts"
resources.frontController.params.displayExceptions = 0
resources.db.adapter = "pdo_mysql"
resources.db.params.host = "localhost"
resources.db.params.username = "root"
resources.db.params.password = "pass"
resources.db.params.dbname = "cms"
resources.db.isDefaultTableAdapter = true
[staging : production]
[testing : production]
phpSettings.display_startup_errors = 1
phpSettings.display_errors = 1
[development : production]
phpSettings.display_startup_errors = 1
phpSettings.display_errors = 1
resources.frontController.params.displayExceptions = 1
應用/控制器/ MemberController.php:
public function newAction()
{
$frmNewMember = new Form_MemberRegisterationForm();
$frmNewMember->setMethod('post');
$frmNewMember->setAction('/member/new');
if ($this->getRequest()->isPost())
{
if ($frmNewMember->isValid($_POST))
{
$memberModel = new Model_Members();
// process the data
$result = true;
$result = $memberModel->createMember(
$frmNewMember->getValue('name'),
$frmNewMember->getValue('lastName'),
$frmNewMember->getValue('uid'),
$frmNewMember->getValue('email'),
$frmNewMember->getValue('password'));
if ($result)
{
$this->_forward('confirm');
}
}
}
$this->view->form = $frmNewMember;
}
應用/模型/ Members.php:
public function createMember($name, $lastName, $uid, $email, $password)
{
// Create row data
$row = $this->createRow();
$row->name = $name;
$row->lastName = $lastName;
$row->uid = $uid;
$row->email = $email;
$row->pasword = md5($password);
// Save the row
$row->save();
$id = $this->_db->lastInsertId();
return $id;
}
當我點擊發送按鈕此錯誤發生:
Fatal error: Undefined class constant 'EXCEPTION_NO_ROUTE'
in /var/www/project/application/controllers/ErrorController.php on line 11
我知道問題是關於$row = $this->createRow();
的代碼。因爲當我用return $true
替換整個createMember
方法的正文時,沒有錯誤。
UPDATE:
這是我在Bootsreap.php _initAutoload()
。我應該添加一些配置數據庫?
protected function _initAutoload()
{
// Add autoloader empty namespace
$autoLoader = Zend_Loader_Autoloader::getInstance();
$autoLoader->registerNamespace('CMS_');
$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;
}
月2日更新: 引發的異常是:
異常 'Zend_Db_Adapter_Exception' 有消息 'SQLSTATE [HY000] [2002]無法通過socket連接到本地MySQL服務器' 的/ tmp//usr/local/zend/share/ZendFramework/library/Zend/Db/Adapter/Pdo/Abstract.php:138中的mysql.sock'(2)'堆棧跟蹤:#0/usr/local/zend/share/ZendFramework /library/Zend/Db/Adapter/Pdo/Mysql.php(96):Zend_Db_Adapter_Pdo_Abstract - > _ connect()#1 /usr/local/zend/share/ZendFramework/library/Zend/Db/Adapter/Abstract.php(444) ):Zend_Db_Adapter_Pdo_Mysql - > _ connect()#2/usr/local/zend/share/ZendFramework/libra ry/Zend/Db/Adapter/Pdo/Abstract.php(232):Zend_Db_Adapter_Abstract-> query('DESCRIBE cms
....',Array)#3/usr/local/zend/share/ZendFramework/library/Zend/Db/Adapter/Pdo/Mysql.php(156):Zend_Db_Adapter_Pdo_Abstract-> query('DESCRIBE cms
....')#4/usr/local/zend/share/ZendFramework/library/Zend/Db/Table/Abstract。 php(727):Zend_Db_Adapter_Pdo_Mysql-> describeTable('members','cms')#5 /usr/local/zend/share/ZendFramework/library/Zend/Db/Table/Abstract.php(753):Zend_Db_Table_Abstract - > _ setupMetadata ()#6 /usr/local/zend/share/ZendFramework/library/Zend/Db/Table/Abstract.php(1297):Zend_Db_Table_Abstract - > _ getCols()#7/var/www/project/application/models /成員.php(33):Zend_Db_Table_Abstract-> createRow(Array,NULL,true)#8 /var/www/project/application/controllers/MemberController.php(32):Model_Members-> createMember('1','1', '1','soroush.rabiei @ ...',NULL)#9 /usr/local/zend/share/ZendFramework/library/Zend/Controller/Action.php(512):MemberCo (#)/ 11/usr/local/zend/share/ZendFramework/library/Zend/Controller/Front.php(945):Zend_Controller_Dispatcher_Standard-> dispatch(Object(Zend_Controller_Request_Http),Object(Zend_Controller_Response_Http))#12/usr/local/zend/share/ZendFramework/library/Zend /Application/Bootstrap/Bootstrap.php(77):Zend_Controller_Front-> dispatch()#13 /usr/local/zend/share/ZendFramework/library/Zend/Application.php(328):Zend_Application_Bootstrap_Bootstrap-> run()#14在/ var/WWW /工程/公共/指數。PHP(26):Zend_Application->的run()#{15}主要
你在ErrorController使用上線11級有什麼描述?它是「Zend_Controller_Plugin_ErrorHandler :: EXCEPTION_NO_ROUTE」嗎?問題出在ErrorController中。解決這個問題,你會看到模型拋出的錯誤。 –
好的,我這樣做了,現在結果是'發生了錯誤 應用程序錯誤' –