在Zend Framework 1.12中未获取表单视图

时间:2018-09-12 09:51:23

标签: php zend-framework

大家好,我是ZF1的新手,我试图显示一个员工添加表格,因此我创建了一个表,名为“ employees”(带有某些字段),并创建了模型和控制器。

这是我的模型:(Application / models / DbTable):

.map()

这是我的控制器(Application / Controllers / EmployeesController.php)

    <?php

/**
 * application/models/DbTable/Employee.php  
 */  

class Employee extends Zend_Db_Table_Abstract  
{  
    protected $_name = 'employees';  
    /**  
    * Our employees' primary key is just 'id'.  
    * If you have another name to that field just use this line below:  
    * protected $_primary = 'emp_id';  
    */

}

这是我的观点(Application / views / scripts / employee / add.phtml):

 <?php

/**
 * controllers/PostsController.php  
 */  

class PostsController extends Zend_Controller_Action  
{  


    public function init() //called always before actions
    {
       $this->posts= new Posts(); //DbTable

    }

    public function addAction()
    {
        $form = $this->getForm(); //getting the post form
        $this->view->form =$form; //assigning the form to view
    }

    public function getForm()  
    {  
        $username = new Zend_Form_Element_Text('username');  

        $username->setLabel('Username')  
            ->setDescription('Just put the username here')  
            ->setRequired(true) // required field  
            ->addValidator('StringLength', false, array(10, 120)) // min 10 max 120  
            ->addFilters(array('StringTrim'));
       $submit = new Zend_Form_Element_Submit('submit');  
        $submit->setLabel('Post') // the button's value  
            ->setIgnore(true); // very usefull -> it will be ignored before insertion

        $form = new Zend_Form();  
        $form->addElements(array($username, $firstname, $empid, $submit));  
            // ->setAction('') // you can set your action. We will let blank, to send the request to the same action
        return $form; // return the form  
    }  


}

所以我的问题是,当我在浏览器<?php echo $this->form;?> 中运行此URL时,我没有从

获取该雇员

任何人都可以帮助我做些什么错误。

谢谢。

0 个答案:

没有答案