2013-12-18 10:57:53 2850次浏览 0条回答 0 悬赏 10 金钱

model:File.php

<?php

class File extends CFormModel {

    public $image;

    public function rules() {
        return array(
            array('image', 'file', 'types' => 'jpg, jpeg, gif, png', 'allowEmpty' => true),
        );
    }

    //这是cfrom的配置文件
    public function getFMConfig() {
        return array(
            'title' => '上传',
            'elements' => array(
                'image' => array(
                    'type' => 'file',
                ),
            ),
            'buttons' => array(
                'upload' => array(
                    'type' => 'submit',
                    'label' => '上传',
                ),
            ),
        );
    }

}
controller FileController.php
<?php

class FileController extends Controller {

    public function actionIndex() {
        $model = new File();
        $form = new CForm($model->getFMConfig(), $model);

        if ($form->submitted('upload') && $form->validate()) {
            echo 'dd';
        }

        $this->render('upload', array('form' => $form));
    }

}
view upload.php
<div class="form">
<?php  echo $form; ?>
</div>
【目前的问题】
1.elements 不显示上传框
2.如果把elements 配置visible能显示上传框
但是,验证直接就过了,即使是错的也过了

    没有找到数据。
您需要登录后才可以回答。登录 | 立即注册
sbfnxk201
见习主管

sbfnxk201

注册时间:2013-09-20
最后登录:2014-02-26
在线时长:30小时0分
  • 粉丝0
  • 金钱0
  • 威望0
  • 积分300

热门问题