Home  >  Article  >  Backend Development  >  Yii实现多按钮保存与提交的方法_PHP

Yii实现多按钮保存与提交的方法_PHP

WBOY
WBOYOriginal
2016-05-31 18:15:54673browse

本文实例讲述了Yii实现多按钮保存与提交并且不冲突的实现方法。这是很多初学都曾遇到但是不知道如何解决的问题,下面分享给大家供大家参考。具体方法如下:

Yii中只有CForm才可以使用submitted() 方法 ,通过if($form->submitted('submit'))来判断是不是点击了buttonName为submit的按钮,比如:
表单:

代码如下:

'buttons'=>array(
        'preview'=>array(
            'type'=>'submit',
            'label'=>yii::t('core','Show preview'),
        ),
        'draft'=>array(
            'type'=>'submit',
            'label'=>yii::t('core','Save draft'),
        ),
        'submit'=>array(
            'type'=>'submit',
            'label'=>yii::t('core','Submit'),
        ),
        CHtml::link(yii::t('core','Cancel'),yii::app()->homeUrl),
),

控制器:

代码如下:

if($form->submitted('submit'))
 $model->status=Post::STATUS_PROPOSED;
else
 $model->status=Post::STATUS_DRAFT;


但是CActiveForm没有这个方法,一个解决方案是采用古典的html写法:

代码如下:

>
if(isset($_POST['submityes']))


就行了。
 
最终运行效果如下图所示:

希望本文所述对大家基于Yii框架的PHP程序设计有所帮助。

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn