kwt90 2012-02-27 10:17:01 3910次浏览 2条回复 0 0 0

view

<?php $form=$this->beginWidget('CActiveForm',array('action'=>array('test/add')));?>
<?php 
$model=new Test;
echo CHtml::errorSummary($model); ?>
<div style="width: 900px; height: auto; margin-left: 20%;">
    <div style="text-align: left;">
<!--    <input type="button" value="添加" style="text-align: center; width: 80px;" onclick="show();"></input>-->
    <?php echo CHtml::button('添加', array('onclick'=>'show()','style'=>'width:80px;text-align:center;')) ?>
    <script>
        function show(){
            document.getElementById('screm').style.display='block';
            document.getElementById('screm_1').style.display='block';
        }
    </script>
    </div>
    <div  id="screm"  style="width: 900px; height: 565px; position: absolute; z-index: 99;display: none; background-color: black; filter:alpha(opacity=40); ">
  
    </div>
    <div id="screm_1" style="width: 900px; height: 565px; position: absolute; z-index: 9999;display: none;">

        <div style="width: 200px; height: 150px; border: 2 solid #09f; margin-left: 40%; margin-top: 15%; background-color: white;">
          <br/>
        <div style="width: 200px; height: 50px;">
            title:
            <br/>
                <?php echo $form->labelEx($model,'title'); ?>
		<?php echo $form->textField($model,'title',array('size'=>80,'maxlength'=>128,'style'=>'width:150px;')); ?>
		<?php echo $form->error($model,'title'); ?>
        </div>
        <div style="width: 200px; height: 60px;">
            content:
            <br/>
                <?php echo $form->labelEx($model,'content'); ?>
		<?php echo CHtml::activeTextArea($model,'content',array('rows'=>10, 'cols'=>20)); ?>
		<?php echo $form->error($model,'content'); ?>
        </div>
        <div style="width: 200px; height: 50px;">
            <?php echo CHtml::submitButton('提交'); ?>



            <input type="button" value="关闭" onclick="close_1();"></input>
            <script>
                function close_1(){
                    document.getElementById('screm').style.display='none';
                    document.getElementById('screm_1').style.display='none';
                    
                }
            </script>
        </div>
    </div>
     
    </div>
<div style="width: 900px; height: auto;">
<?php $this->widget('zii.widgets.grid.CGridView', array(
	'dataProvider'=>$model->search(),
	'filter'=>$model,'hideHeader'=>false,
	'columns'=>array(
		array(
			'name'=>'title',
			'type'=>'raw',
			'value'=>'CHtml::link(CHtml::encode($data->title), $data->url)',
		),

		array(
			'name'=>'create_time',
			'type'=>'datetime',
			'filter'=>false,
		),
		array(
			'header'=>'操作',
			'class'=>'CButtonColumn',
		),
	),
)); ?>
 </div>
</div>
<?php $this->endWidget(); ?>[/code]controllor[code]        public function actionAdd(){
            $test=new Test();
            if(isset($_POST['Test'])){
                $model->attributes=$_POST['Test'];
                if(Test::model()->save())
                    $this->redirect (array('index'));
            } 
        }
  • 回复于 2012-02-27 10:18 举报

    各位大侠指点下,为何我表单提交后,action 里面读取不到值

  • 回复于 2012-02-27 11:43 举报
    public function actionAdd()
    {
        $test=new Test();
        if(isset($_POST['Test'])){
            $model->attributes=$_POST['Test'];
            if(Test::model()->save())
            $this->redirect (array('index'));
    } 
    else
    {
        render("controllerID/add",$model);//加上这个
    }
    
    }
    
您需要登录后才可以回复。登录 | 立即注册