duan1227 2015-08-07 09:29
浏览 70
已采纳

表格类未找到zend 2.3

I am trying to create a simple form using zendform here is the code of form class:

<?php
namespace admin\Form;

use Zend\Form\Form;

class Addstudent extends Form
{
    public function __construct($name = null)
    {
        // we want to ignore the name passed
        parent::__construct('addstudent');


        $this->add(array(
            'name' => 'fio',
            'type' => 'Text',
            'options' => array(
                'label' => 'Фио',
            ),
        ));
        $this->add(array(
            'name' => 'gender',
            'type' => 'Zend\Form\Element\Radio',
            'options' => array(
                'label' => 'Пол',
                'value_options' => array(
                    '0' => 'М',
                    '1' => 'Ж',
                ),

            ),
        ));
        $this->add(array(
            'name' => 'birthdate',
            'type' => 'Text',
            'options' => array(
                'label' => 'Дата рождения',
            ),
        ));

        $this->add(array(
            'name' => 'edge',
            'type' => 'Text',
            'options' => array(
                'label' => 'Возраст',
            ),
        ));

        $this->add(array(
            'name' => 'university',
            'type' => 'Text',
            'options' => array(
                'label' => 'Вуз',
            ),
        ));
        $this->add(array(
            'name' => 'group',
            'type' => 'Text',
            'options' => array(
                'label' => 'Группа',
            ),
        ));
        $this->add(array(
            'name' => 'department',
            'type' => 'Text',
            'options' => array(
                'label' => 'Факультет',
            ),
        ));
        $this->add(array(
            'name' => 'grate',
            'type' => 'Zend\Form\Element\Radio',
            'options' => array(
                'label' => 'Курс',
                'value_options' => array(
                    '0' => '1',
                    '1' => '2',
                    '2' => '3',
                    '3' => '4',
                    '4' => '5',
                    '5' => '6',

                ),

            ),
        ));
        $this->add(array(
            'name' => 'enterence',
            'type' => 'Text',
            'options' => array(
                'label' => 'год поступления',
            ),
        ));

        $this->add(array(
            'name' => 'financesource',
            'type' => 'Zend\Form\Element\Radio',
            'options' => array(
                'label' => 'Курс',
                'value_options' => array(
                    '0' => 'Бюджет',
                    '1' => 'Контракт',

                ),

            ),
        ));

        $this->add(array(
            'name' => 'studyform',
            'type' => 'Zend\Form\Element\Radio',
            'options' => array(
                'label' => 'Форма обучения',
                'value_options' => array(
                    '0' => 'Дневная',
                    '1' => 'Заочная',

                ),

            ),
        ));

        $this->add(array(
            'name' => 'homeaddress',
            'type' => 'Text',
            'options' => array(
                'label' => 'Домашний адрес',
            ),
        ));

        $this->add(array(
            'name' => 'actualaddress',
            'type' => 'Text',
            'options' => array(
                'label' => 'Фактический адрес',
            ),
        ));
        $this->add(array(
            'name' => 'phone',
            'type' => 'Text',
            'options' => array(
                'label' => 'Телефон',
            ),
        ));

        $this->add(array(
            'name' => 'workplace',
            'type' => 'Text',
            'options' => array(
                'label' => 'Место работы',
            ),
        ));
        $this->add(array(
            'name' => 'services',
            'type' => 'Zend\Form\Element\Textarea',
            'options' => array(
                'label' => 'услуги',
            ),
        ));

        $this->add(array(
            'name' => 'submit',
            'type' => 'Submit',
            'attributes' => array(
                'value' => 'сохранить',
                'id' => 'submitbutton',
            ),
        ));
    }
}

But then I try to show it controller shows fatal error class Addstudent not found. here is how I imported it to a controller

use admin\Model\Admin;
use admin\form\Addstudent;

And here is an action

public function addstudentAction()
{

    $form = new Addstudent();
    $form->get('submit')->setValue('Сохранить');

    $request = $this->getRequest();
    if ($request->isPost()) {
        $admin = new Admin();
        $form->setInputFilter($admin->getInputFilter());
        $form->setData($request->getPost());

        if ($form->isValid()) {
            $admin->exchangeArray($form->getData());
           // $this->getAlbumTable()->saveAlbum($album);

            // Redirect to list of albums
            return $this->redirect()->toRoute('admin');
        }
    }
    return array('form' => $form);


  //  return array();
}

form file is located in module/admin/src/admin/form/addstudent.php

  • 写回答

2条回答 默认 最新

  • dtlygweb2017 2015-08-07 15:18
    关注

    Everything beneath your src folder should use an initial upper case letter, so module/admin/src/admin/form/addstudent.php should be module/admin/src/Admin/Form/Addstudent.php and so on.

    Then you should change your namespace declarations to match this, i.e. namespace Admin\Form; and use Admin\Form\Addstudent;.

    At the moment you are not being consistent about case (e.g. you declare namespace admin\Form; but have use admin\form\Addstudent; in your controller) which is likely the cause of your issue.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?

悬赏问题

  • ¥15 如何让企业微信机器人实现消息汇总整合
  • ¥50 关于#ui#的问题:做yolov8的ui界面出现的问题
  • ¥15 如何用Python爬取各高校教师公开的教育和工作经历
  • ¥15 TLE9879QXA40 电机驱动
  • ¥20 对于工程问题的非线性数学模型进行线性化
  • ¥15 Mirare PLUS 进行密钥认证?(详解)
  • ¥15 物体双站RCS和其组成阵列后的双站RCS关系验证
  • ¥20 想用ollama做一个自己的AI数据库
  • ¥15 关于qualoth编辑及缝合服装领子的问题解决方案探寻
  • ¥15 请问怎么才能复现这样的图呀