Answer the question
In order to leave comments, you need to log in
Why is Zend Framework throwing a 500 error when submitting a form?
Hello!
I wrote a form using zend framework
class Application_Form_User extends Zend_Form{
function __construct() {
$this->setName('form_user');
parent::__construct();
$username=new Zend_Form_Element_Text('username');
$username->setLabel('Имя');
$password=new Zend_Form_Element_Password('password');
$password->setLabel('Пароль');
$email=new Zend_Form_Element_Text('email');
$email->setLabel('Почта')
->addValidator('EmailAddress');
$submit=new Zend_Form_Element_Submit('submit');
$submit->setLabel('Регистрация');
$this->addElements(array($username,$password,$email,$submit));
}
}
class UsersController extends Zend_Controller_Action{
public function indexAction(){
$this->view->title='Список пользователей';
$this->view->headTitle($this->view->title,'PREPEND');
}
public function addAction(){
$this->view->title='Добавить нового пользователя';
$this->view->headTitle($this->view->title,'PREPEND');
$form=new Application_Form_User();
if($this->getRequest()->isPost()){
if($form->isValid($this->getRequest()->getPost())){
$user=new Application_Model_Users();
$user->fill($this->getValues());
$user->save();
}
}
$this->view->form=$form;
}
}
class Application_Model_Users{
protected $_dbTable;
protected $_row;
public function __construct($id=null){
$this->_dbTable=new Application_Model_DbTable_Users();
if($id){
$this->_row=$this->_dbTable->find($id)->current();
}else{
$this->_row=$this->_dbTable->createRow();
}
}
public function fill($data){
foreach($data as $kay=>$value){
if(isset($this->_row->$key)){
$this->_row->$key=$value;
}
}
}
public function save(){
$this->_row->save();
}
public function __set($name,$val){
if(isset($this->_row->$name)){
$this->_row->$name=$val;
}
}
public function __get($name){
if(isset($this->_row->$name)){
return $this->_row->$name;
}
}
$user=new Application_Model_Users($id);
}
class Application_Model_DbTable_Users extends Zend_Db_Table_Abstract{
protected $_name = 'users';
}
Answer the question
In order to leave comments, you need to log in
But when submitting this form, the data does not get into the table, but the 500th error just falls out and that's it!
Yes. in apache log
[client 127.0.0.1] PHP Parse error: syntax error, unexpected T_VARIABLE, expecting T_FUNCTION in Z:\\home\\zend.local\\application\\models\\Users.php on line 39, referer: zend .local/users/add
, that is, it swears at this line in the model ... But it's not clear why (
I deleted it and it's still 500, only now it doesn't write anything in the log
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question