Salvar o resgistro

Ahe galera preciso de uma ajuda,

Estou tentando salvar o resgistro na tabela mais ele nao salva e nem da uma mensagem de erro. eu nao sei mais o que fazer ja deletei criei de novo e nada.

Eu criei este form, model,controler atraves do gii o estranho que é so nesta tabela. alguem pode me ajudar a identificar o erro.

controler


<?php


class NoticiasController extends Controller

{

	/**

	 * @var string the default layout for the views. Defaults to '//layouts/column2', meaning

	 * using two-column layout. See 'protected/views/layouts/column2.php'.

	 */

	/**

	 * @var CActiveRecord the currently loaded data model instance.

	 */

	private $_model;


	/**

	 * @return array action filters

	 */

	public function filters()

	{

		return array(

			'accessControl', // perform access control for CRUD operations

		);

	}


	/**

	 * Specifies the access control rules.

	 * This method is used by the 'accessControl' filter.

	 * @return array access control rules

	 */

	public function accessRules()

	{

                return array(

			array('allow',  // allow all users to perform 'index' and 'view' actions

				'actions'=>array('index','view', 'create','update', 'delete'),

				'users'=>array('@'),

			),

			array('deny',  // deny all users

				'users'=>array('*'),

			),

		);

	}


	/**

	 * Displays a particular model.

	 */

	public function actionView()

	{

		$this->render('view',array(

			'model'=>$this->loadModel(),

		));

	}


	/**

	 * Creates a new model.

	 * If creation is successful, the browser will be redirected to the 'view' page.

	 */

	public function actionCreate()

	{

		$model=new noticias;


		// Uncomment the following line if AJAX validation is needed

		// $this->performAjaxValidation($model);


		if(isset($_POST['noticias']))

		{

			$model->attributes=$_POST['noticias'];

			if($model->save())

				$this->redirect(array('view','id'=>$model->id));

		}


		$this->render('create',array(

			'model'=>$model,

		));

	}


	/**

	 * Updates a particular model.

	 * If update is successful, the browser will be redirected to the 'view' page.

	 */

	public function actionUpdate()

	{

		$model=$this->loadModel();


		// Uncomment the following line if AJAX validation is needed

		// $this->performAjaxValidation($model);


		if(isset($_POST['noticias']))

		{

			$model->attributes=$_POST['noticias'];

			if($model->save())

				$this->redirect(array('view','id'=>$model->id));

		}


		$this->render('update',array(

			'model'=>$model,

		));

	}


	/**

	 * Deletes a particular model.

	 * If deletion is successful, the browser will be redirected to the 'index' page.

	 */

	public function actionDelete()

	{

		if(Yii::app()->request->isPostRequest)

		{

			// we only allow deletion via POST request

			$this->loadModel()->delete();


			// if AJAX request (triggered by deletion via admin grid view), we should not redirect the browser

			if(!isset($_GET['ajax']))

				$this->redirect(isset($_POST['returnUrl']) ? $_POST['returnUrl'] : array('index'));

		}

		else

			throw new CHttpException(400,'Invalid request. Please do not repeat this request again.');

	}


	/**

	 * Lists all models.

	 */


	public function actionIndex()

	{

		$model=new noticias('search');

		$model->unsetAttributes();  // clear any default values

		if(isset($_GET['noticias']))

			$model->attributes=$_GET['noticias'];


		$this->render('index',array(

			'model'=>$model,

		));

	}


	/**

	 * Returns the data model based on the primary key given in the GET variable.

	 * If the data model is not found, an HTTP exception will be raised.

	 */

	public function loadModel()

	{

		if($this->_model===null)

		{

			if(isset($_GET['id']))

				$this->_model=noticias::model()->findbyPk($_GET['id']);

			if($this->_model===null)

				throw new CHttpException(404,'The requested page does not exist.');

		}

		return $this->_model;

	}


	/**

	 * Performs the AJAX validation.

	 * @param CModel the model to be validated

	 */

	protected function performAjaxValidation($model)

	{

		if(isset($_POST['ajax']) && $_POST['ajax']==='noticias-form')

		{

			echo CActiveForm::validate($model);

			Yii::app()->end();

		}

	}

}



model


<?php


/**

 * This is the model class for table "noticias".

 *

 * The followings are the available columns in table 'noticias':

 * @property integer $id

 * @property string $titulo

 * @property string $descricao

 * @property integer $idusuario

 * @property string $data_cadastro

 */

class Noticias extends CActiveRecord

{

	/**

	 * Returns the static model of the specified AR class.

	 * @return Noticias the static model class

	 */

	public static function model($className=__CLASS__)

	{

		return parent::model($className);

	}


	/**

	 * @return string the associated database table name

	 */

	public function tableName()

	{

		return 'noticias';

	}


	/**

	 * @return array validation rules for model attributes.

	 */

	public function rules()

	{

		// NOTE: you should only define rules for those attributes that

		// will receive user inputs.

		return array(

			array('descricao', 'required'),

			array('idusuario', 'numerical', 'integerOnly'=>true),

			array('titulo', 'length', 'max'=>255),

			array('data_cadastro', 'safe'),

			// The following rule is used by search().

			// Please remove those attributes that should not be searched.

			array('id, titulo, descricao, idusuario, data_cadastro', 'safe', 'on'=>'search'),

		);

	}


	/**

	 * @return array relational rules.

	 */

	public function relations()

	{

		// NOTE: you may need to adjust the relation name and the related

		// class name for the relations automatically generated below.

		return array(

		);

	}


	/**

	 * @return array customized attribute labels (name=>label)

	 */

	public function attributeLabels()

	{

		return array(

			'id' => 'ID',

			'titulo' => 'Titulo',

			'descricao' => 'Descricao',

			'idusuario' => 'Idusuario',

			'data_cadastro' => 'Data Cadastro',

		);

	}


	/**

	 * Retrieves a list of models based on the current search/filter conditions.

	 * @return CActiveDataProvider the data provider that can return the models based on the search/filter conditions.

	 */

	public function search()

	{

		// Warning: Please modify the following code to remove attributes that

		// should not be searched.


		$criteria=new CDbCriteria;


		$criteria->compare('id',$this->id);


		$criteria->compare('titulo',$this->titulo,true);


		$criteria->compare('descricao',$this->descricao,true);


		$criteria->compare('idusuario',$this->idusuario);


		$criteria->compare('data_cadastro',$this->data_cadastro,true);


		return new CActiveDataProvider(get_class($this), array(

			'criteria'=>$criteria,

		));

	}

}

no codigo




     	if(isset($_POST['noticias']))

                {

                        $model->attributes=$_POST['noticias'];

                        if($model->save())

                                $this->redirect(array('view','id'=>$model->id));

                }





$model->save(); 

vai tentar validar todos os atributos, tente algo como:


$model->save(false); 

ou


if($model->validate(array('atributo1','atributo2')) ){

$model->save(false) ;

}

Edson faz o seguinte, habilita o $form->errorSummary($model) dentro do CActiveForm,

ai no activeform tu adiciona a validação onsubmit e onchange:




$form = $this->beginWidget('CActiveForm', array(

            ...

            'clientOptions' => array('validateOnSubmit' => true, 'validateOnChange' => true),

            ...

        ));



Se nen isso funcionar verifica o rules() do seu Model, e verifica quais o campos estão no array(‘campo1,campo2’, ‘required’).

Se nen isso também não funcionar, faz o ultimo recurso.




$model=new noticias;


                // Uncomment the following line if AJAX validation is needed

                // $this->performAjaxValidation($model);


                if(isset($_POST['noticias']))

                {

                        $model->attributes=$_POST['noticias'];


$model->getErrors();

exit();

                        if($model->save())

                                $this->redirect(array('view','id'=>$model->id));

                }


                $this->render('create',array(

                        'model'=>$model,

                ));




Observa o $model->getErrors(); exit(); ai tu verifica na hora de submeter quais campo está com erro.