English 中文(简体)
Yii框架,在提交表格文本字段之后,数据库中不更新
原标题:Yii framework, after submiting the form text fields are not updated in database
  • 时间:2012-05-23 14:06:29
  •  标签:
  • mysql
  • yii

我对MVC和Yii框架很新奇,因此我的问题很可能很愚蠢。如果是的话,请事先接受我的建议。

我想在网站的行政管理部分有一张表格, 用户可以张贴一些内容。 我跟踪样本博客的教程, 但似乎数据库中定义为文本的字段中添加的内容( 我格式的文本区域) 在提交表格后不会更新( 所有其它内容都很好 ) 。 以下是我表格的 sql 语句 :

CREATE TABLE `tbl_show` (
   `id` bigint(20) NOT NULL AUTO_INCREMENT,
   `presentation` text,
    PRIMARY KEY (`id`),
    KEY `fk_tbl_show_tbl_season1` (`tbl_season_id`)
) ENGINE=InnoDB  DEFAULT CHARSET=latin1 AUTO_INCREMENT=2 ;

我用基伊来制作我的模型和CROUD, 我在这里只添加可能相关的部分:

在我的控制器上:

    public function actionCreate()
{
    $model=new Show;

    if(isset($_POST[ Show ]))
    {
        $model->attributes=$_POST[ Show ];
        if($model->save())
                    {
                        $this->redirect(array( view , id =>$model->id));
                    }   
    }
    $this->render( create ,array(
         model =>$model,
    ));

和我的_form.php:

<div class="form">

 <?php $form=$this->beginWidget( CActiveForm , array(
  id => show-form ,
  enableAjaxValidation =>false,
  )); ?>

<?php echo $form->errorSummary($model); ?>

    <div class="row">
    <?php echo $form->labelEx($model, presentation ); ?>
    <?php echo $form->textArea($model, presentation ,array( rows =>6,  cols =>50)); ?>
    <?php echo $form->error($model, presentation ); ?>
</div>

<div class="row buttons">
    <?php echo CHtml::submitButton($model->isNewRecord ?  Create  :  Save ); ?>
</div>

    <?php $this->endWidget(); ?>

    </div><!-- form -->

示范规则:

return array(
    array( id, presentation ,  safe ,  on => search ),
);

我不明白为什么只有文字内容不更新,

Thank you in advance, Cheers, Mahsa

最佳回答

您必须使属性安全。 将此添加到您的 < code> 显示 模式验证规则中

array( presentation , safe )
问题回答

我发现表格没有正确提交的问题,我在此添加,以防任何人有同样的问题:

我翻了之前的救世主, 但我想完成它以后, 所以它没有重写任何东西:

protected function beforeSave() {
        if(parent::beforeSave())
        {
            if($this->isNewRecord)
            {
               //things that should be added by the system
            }
        }

    }

在评论了这一切之后,一切都很好。同样,正如你们建议的那样,我添加了那些没有安全规则验证的字段。

试试这个...

public function actionCreate()
{
    $model=new Show;

    if(isset($_POST[ Show ]))
    {
        $model->attributes=$_POST[ Show ];

        $save = $model->save(false);      // write like this...
        if($save)
                    {
                        $this->redirect(array( view , id =>$model->id));
                    }   
    }
    $this->render( create ,array(
         model =>$model,
    ));

希望它会为你工作..





相关问题
SQL SubQuery getting particular column

I noticed that there were some threads with similar questions, and I did look through them but did not really get a convincing answer. Here s my question: The subquery below returns a Table with 3 ...

please can anyone check this while loop and if condition

<?php $con=mysql_connect("localhost","mts","mts"); if(!con) { die( unable to connect . mysql_error()); } mysql_select_db("mts",$con); /* date_default_timezone_set ("Asia/Calcutta"); $date = ...

php return a specific row from query

Is it possible in php to return a specific row of data from a mysql query? None of the fetch statements that I ve found return a 2 dimensional array to access specific rows. I want to be able to ...

Character Encodings in PHP and MySQL

Our website was developed with a meta tag set to... <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" /> This works fine for M-dashes and special quotes, etc. However, I ...

Pagination Strategies for Complex (slow) Datasets

What are some of the strategies being used for pagination of data sets that involve complex queries? count(*) takes ~1.5 sec so we don t want to hit the DB for every page view. Currently there are ~...

Averaging a total in mySQL

My table looks like person_id | car_id | miles ------------------------------ 1 | 1 | 100 1 | 2 | 200 2 | 3 | 1000 2 | 4 | 500 I need to ...

热门标签