<?php $form = $this->beginWidget(‘CActiveForm‘,array(‘htmlOptions‘=>array(‘enctype‘=>‘multipart/form-data‘))) ?> <table class="table"> <tr > <td class="th" colspan="10">发表文章</td> </tr> <tr> <td><?php echo $form->labelEx($articleModel,‘title‘) ?></td> <td> <?php echo $form->textField($articleModel,‘title‘,array(‘maxlength‘=>32)) ?> <?php echo $form->error($articleModel,‘title‘) ?> </td> </tr> <tr> <td><?php echo $form->labelEx($articleModel,‘type‘) ?></td> <td> <?php echo $form->radioButtonList($articleModel,‘type‘,array(0=>‘普通‘,1=>‘热门‘),array(‘separator‘=>‘ ‘)) ?> </td> </tr> <tr> <td><?php echo $form->labelEx($articleModel,‘catid‘) ?></td> <td> <?php echo $form->dropDownList($articleModel,‘catid‘, $categoryArr) ?> <?php echo $form->error($articleModel,‘catid‘) ?> </td> </tr> <tr> <td><?php echo $form->labelEx($articleModel,‘thumb‘) ?></td> <td> <?php echo $form->fileField($articleModel,‘thumb‘) ?> <?php echo $form->error($articleModel,‘thumb‘) ?> </td> </tr> <tr> <td><?php echo $form->labelEx($articleModel,‘description‘) ?></td> <td> <?php echo $form->textArea($articleModel,‘description‘,array(‘rows‘=>5,‘cols‘=>70)) ?> <?php echo $form->error($articleModel,‘description‘) ?> </td> </tr> <tr> <td><?php echo $form->labelEx($articleModel,‘content‘) ?></td> <td> <?php echo $form->textArea($articleModel,‘content‘,array(‘id‘=>‘content‘)) ?> <?php echo $form->error($articleModel,‘content‘) ?> </td> </tr> <tr> <td colspan="10"><input type="submit" class="input_button" value="发布"/></td> </tr> </table> <?php $this->endWidget() ?>
控制器
public function actionAdd(){ $articleModel = new Article(); $categoryModel = Category::model(); $categoryObj = $categoryModel->findAllBySql("select * from {{category}}"); $categoryArr = array(); $categoryArr[] = ‘请选择栏目‘; foreach($categoryObj as $v){ $categoryArr[$v->id] = $v->cname; } if(isset($_POST[‘Article‘])){ $data = $_POST[‘Article‘]; $data[‘inputtime‘] = time(); $data[‘updatetime‘] = time(); $articleModel->attributes = $data; if($articleModel->save()){ $this->redirect(array(‘index‘)); } } $this->render(‘add‘,array(‘articleModel‘=>$articleModel,‘categoryArr‘=>$categoryArr)); }
时间: 2024-10-12 12:58:24