A
A
Alexander Sharomet2014-04-07 20:07:23
Zend Framework
Alexander Sharomet, 2014-04-07 20:07:23

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));
  }
}

Controller
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;
  }
}

Then created a model
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';
}

But when submitting this form, the data does not get into the table, but the 500th error just falls out and that's it!
How can this be fixed?
Thanks!)

Answer the question

In order to leave comments, you need to log in

2 answer(s)
F
ForestHeart, 2014-04-08
@sharomet

But when submitting this form, the data does not get into the table, but the 500th error just falls out and that's it!

The 500th error can never just fall out, there are not always reasons.
In order to understand what kind of error you need to set up error display + error trace
Check the settings of php and Zend of the project so that it always shows you a detailed error message on the local, after that it will be very easy to understand what the reason is.
check your application.ini configs for any:
phpSettings.display_startup_errors = 1
phpSettings.display_errors = 1

A
Alexander Sharomet, 2014-04-08
@sharomet

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 question

Ask a Question

731 491 924 answers to any question