I have a problem with my application's model. it should save a new user in a mysql database.
application/config/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
application/controllers/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;
}
application/models/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;
}
When I click on send button this error occures:
Fatal error: Undefined class constant 'EXCEPTION_NO_ROUTE'
in /var/www/project/application/controllers/ErrorController.php on line 11
I know the problem is about $row = $this->createRow();
code. because when I replace whole createMember
method's body with return $true
there is no error.
UPDATE:
this is my _initAutoload()
in the Bootsreap.php. should I add something to configure database?
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;
}
2nd UPDATE: The exception thrown is:
exception 'Zend_Db_Adapter_Exception' with message 'SQLSTATE[HY000] [2002] Can't connect to local MySQL server through socket '/tmp/mysql.sock' (2)' in /usr/local/zend/share/ZendFramework/library/Zend/Db/Adapter/Pdo/Abstract.php:138 Stack trace: #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/library/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/Members.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): MemberController->newAction() #10 /usr/local/zend/share/ZendFramework/library/Zend/Controller/Dispatcher/Standard.php(288): Zend_Controller_Action->dispatch('newAction') #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/project/public/index.php(26): Zend_Application->run() #15 {main}
Zend_Controller_Plugin_ErrorHandler::EXCEPTION_NO_ROUTE
? The problem is in the ErrorController. Fix that and you will see the error the model is throwing. – brady.vitranoAn error occurred Application error
– sorush-r