我是yii框架的新手。
以2個字段的形式創建表單(不使用內置小部件)。
time_start,time_end - 鍵入數據庫DATETIME。
數據庫中的所有數據都被正確記錄,但是如果您輸入的是字母而不是寫入的零,則會寫入零。
我試圖在模型中添加一條規則:yii的輸出格式datetime
array ('time_start, time_end', 'type', 'type' => 'datetime', 'datetimeFormat' => 'Y-m-d H:i:s'),
看來格式一樣存儲在數據庫中,但沒有任何反應。 在方法安全()後控制器,寫道:
print_r ($ model-> getErrors());
例如,引入到字段: 2006-12-26 15點00分30秒 獲取的陣列:
Array ([time_start] => Array ([0] => Start must be datetime.) [Time_end] => Array ([0] => End must be datetime.))
等嘗試了不同的格式,但錯誤都是一樣的。 告訴我,我該如何處理,以便只能以 (如數據庫)的格式輸入,而沒有別的。 在此先感謝。
* UPDATE *
在 「視圖/站點/索引」:
<?php $this->widget('zii.widgets.CListView', array(
'dataProvider'=>$modeltask->search(),
'itemView'=>'_viewtask',
)); ?>
viewtask:
<div class="view">
<b><?php echo CHtml::encode($data->getAttributeLabel('id')); ?>:</b>
<?php echo CHtml::link(CHtml::encode($data->id), array('view', 'id'=>$data->id)); ?>
<br />
<b><?php echo CHtml::encode($data->getAttributeLabel('author_id')); ?>:</b>
<?php echo CHtml::encode($data->author_id); ?>
<br />
<b><?php echo CHtml::encode($data->getAttributeLabel('performer_id')); ?>:</b>
<?php echo CHtml::encode($data->performer_id); ?>
<br />
<b><?php echo CHtml::encode($data->getAttributeLabel('parent_task_id')); ?>:</b>
<?php echo CHtml::encode($data->parent_task_id); ?>
<br />
<b><?php echo CHtml::encode($data->getAttributeLabel('project_id')); ?>:</b>
<?php echo CHtml::encode($data->project_id); ?>
<br />
<b><?php echo CHtml::encode($data->getAttributeLabel('hours_plan')); ?>:</b>
<?php echo CHtml::encode($data->hours_plan); ?>
<br />
<b><?php echo CHtml::encode($data->getAttributeLabel('title')); ?>:</b>
<?php echo CHtml::encode($data->title); ?>
<br />
<form action="http://testik.test/index.php?r=site/savec" method="post">
<input type="hidden" value="<?php echo $data->id; ?>" name="id_task">
<input type="hidden" value="<?php echo Yii::app()->user->id ?>" name="id_user">
<input type="text" placeholder="Дата начала" name="time_start">
<input type="text" placeholder="Дата конца" name="time_end">
<input type="submit" value="Challenge accepted">
</form>
</div>
SiteController,方法的actionIndex和actionSaveC:
public function actionIndex()
{
$modeltask=new Task('search');
$modeltask->unsetAttributes();
if(isset($_GET['Task']))
$modeltask->attributes=$_GET['Task'];
$this->render('index', array(
'modeltask'=>$modeltask,
));
}
public function actionSaveC()
{
$model = new Calendar;
$model->unsetAttributes();
if(!empty($_POST))
{
$model->attributes = $_POST;
$model->save();
print_r($model->getErrors());
//$this->redirect(array('index'));
}
型號:加一條線,沒有別的改變
忘了說,所有創建的CRUD
你的意思是有''type''然後''type'=>'datetime'嗎? – Pitchinnate
您必須向我們展示您的控制器,表單模型和視圖才能回答此問題,但如果您未使用表單小部件,則可能失去一些必須自行編寫的功能。 – jmarkmurphy
@Pitchinnate, 我在互聯網尋找規則需要在模型中添加什麼。 要僅記錄所需的格式 – S1ash