Doesnt validate and not create

My create action:


public function actionCreate() {

        $ritmo = new Ritmo;

        $mp3 = new Document;


        if (isset($_POST['Ritmo'])) {

            $ritmo->attributes = $_POST['Ritmo'];

     

        $ritmo->save();  

    

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

        

        }

       

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

            'ritmo' => $ritmo,

            'mp3' => $mp3

        ));

    }



_form view:


<div class="form">


<?php


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

    'id'=>'ritmo-form',

    'enableAjaxValidation'=>false,

    'method'=>'post',

    'htmlOptions'=>array(

        'enctype'=>'multipart/form-data'

    )

     )); ?>  

    


	<p class="note">Fields with <span class="required">*</span> are required.</p>


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

        

        


	<div class="row">

		<?php echo $form->labelEx($ritmo,'artist'); ?>

		<?php echo $form->textField($ritmo,'artist',array('size'=>45,'maxlength'=>45)); ?>

		<?php echo $form->error($ritmo,'artist'); ?>

	</div>


	<div class="row">

		<?php echo $form->labelEx($ritmo,'title'); ?>

		<?php echo $form->textField($ritmo,'title',array('size'=>45,'maxlength'=>45)); ?>

		<?php echo $form->error($ritmo,'title'); ?>

	</div>


	<div class="row">

		<?php echo $form->labelEx($ritmo,'price'); ?>

		<?php echo $form->textField($ritmo,'price',array('size'=>10,'maxlength'=>10)); ?>

		<?php echo $form->error($ritmo,'price'); ?>

	</div>


	<div class="row">

		<?php echo $form->labelEx($ritmo,'mp3'); ?>

                <?php echo $form->fileField($mp3,'content',array('size'=>60)); ?>

		<?php echo $form->error($ritmo,'mp3'); ?>

	</div>

     <div class="row">

		<?php echo $form->labelEx($ritmo,'youtubeLnk'); ?>

		<?php echo $form->textField($ritmo,'youtubeLnk',array('size'=>60));  ?>

		<?php echo $form->error($ritmo,'youtubeLnk'); ?>

	</div>

	

	<div class="row">

		<?php echo $form->labelEx($ritmo,'categoria'); ?>

               <table style="width:100px"><tr>

                       <td style="padding:0"><?php echo $form->dropdownlist($ritmo,'categoria',$ritmo->Categorias) ?></td>

                       <td style="padding:0"><?php echo CHtml::link(CHtml::image(Yii::app()->request->baseUrl . '/images/add.png','cart'), Yii::app()->createUrl('admin/categoria/create')); ?></td>

                      </tr>

               </table>

		

		<?php echo $form->error($ritmo,'categoria'); ?>

                

	</div>


	<div class="row buttons">

		<?php echo CHtml::submitButton($ritmo->isNewRecord ? 'Create' : 'Save'); ?>

	</div>


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


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

create view


<?php

$this->breadcrumbs=array(

	'Ritmos'=>array('index'),

	'Create',

);


$this->menu=array(

	array('label'=>Yii::t('app','List').' '. Yii::t('app','Style'), 'url'=>array('index')),

	array('label'=>Yii::t('app','Manage').' '. Yii::t('app','Style'), 'url'=>array('admin')),

);

?>


<h1>Create Ritmo</h1>


<?php echo $this->renderPartial('_form', array(

                            'ritmo'=>$ritmo,

                             'mp3'=>$mp3

                                            )); ?>

Why doenst validate the required fields and when i create i get

Error 400

Your request is invalid.

i dont understand

your model ?

Ritmo model:


<?php


/**

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

 *

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

 * @property integer $idritmo

 * @property string $artist

 * @property string $title

 * @property string $price

 * @property integer $mp3

 * @property integer $categoria

 * @property string $youtubeLnk

 * @property integer $image

 *

 * The followings are the available model relations:

 * @property EncomendaLinha[] $encomendaLinhas

 * @property Document $image

 * @property Categoria $categoria

 * @property Document $mp3

 * @property Teclado[] $teclados

 */

class Ritmo extends CActiveRecord

{

	/**

	 * Returns the static model of the specified AR class.

	 * @param string $className active record class name.

	 * @return Ritmo 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 'ritmo';

	}


	/**

	 * @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('artist, title, price,categoria', 'required'),

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

            array('artist, title', 'length', 'max' => 45),

            array('price', 'length', 'max' => 10),

            array('youtubeLnk', 'length', 'max'=>445),

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

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

            array('idritmo, artist, title, price, mp3, categoria,youtubeLnk', 'safe', 'on' => 'search'),

        );

    }

	public function playMp3(){

       // sendFile($this->mp3,$this->mp3,NULL,true);

    }







	/**

	 * @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(

			'encomendaLinhas' => array(self::HAS_MANY, 'EncomendaLinha', 'style'),

			'image' => array(self::BELONGS_TO, 'Document', 'image'),

			'categoriaR' => array(self::BELONGS_TO, 'Categoria', 'categoria'),

			'mp3' => array(self::BELONGS_TO, 'Document', 'mp3'),

			'teclados' => array(self::MANY_MANY, 'Teclado', 'ritmo_teclado(idritmo, idteclado)'),

		);

	}




	public function getCategorias() {

        return CHtml::listData(Categoria::model()->findAll(), 'idcategoria', 'name');

    }


	/**

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

	 */

	public function attributeLabels()

	{

		return array(

			'idritmo' => 'Idritmo',

			'artist' => Yii::t('app','Artist'),

			'title' => Yii::t('app','Title'),

			'price' => Yii::t('app','Price'),

			'mp3' => 'Mp3',

			'categoria' => Yii::t('app','Categoria'),

			'youtubeLnk' => 'Youtube Lnk',

			'image' => 'Image',

		);

	}


	/**

	 * 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('idritmo',$this->idritmo);

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

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

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

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

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

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

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


		return new CActiveDataProvider($this, array(

			'criteria'=>$criteria,

		));

	}

}

and document model:


<?php


/**

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

 *

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

 * @property integer $idbinarios

 * @property string $filename

 * @property string $content

 * @property string $type

 *

 * The followings are the available model relations:

 * @property Ritmo[] $ritmos

 * @property Ritmo[] $ritmos1

 */

class Document extends CActiveRecord

{

	/**

	 * Returns the static model of the specified AR class.

	 * @param string $className active record class name.

	 * @return Document 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 'document';

	}


	/**

	 * @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('filename','required'),

			array('filename', 'length', 'max'=>345),

			array('type', 'length', 'max'=>45),

			array('content', 'safe'),

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

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

			array('idbinarios, filename, content, type', '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(

			'ritmos' => array(self::HAS_MANY, 'Ritmo', 'image'),

			'ritmos1' => array(self::HAS_MANY, 'Ritmo', 'mp3'),

		);

	}


	/**

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

	 */

	public function attributeLabels()

	{

		return array(

			'idbinarios' => 'Idbinarios',

			'filename' => 'Filename',

			'content' => 'Content',

			'type' => 'Type',

		);

	}


	/**

	 * 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('idbinarios',$this->idbinarios);

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

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

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


		return new CActiveDataProvider($this, array(

			'criteria'=>$criteria,

		));

	}

}

Hi there,

Did you manage to solve this? How?

Thanks a lot,

Alejandro.

You have to call the validate methis by :


if ($model->validate()) ... or else if ($model->save())

Perfect, Thank you!