Yii Framework Forum: Dropdownlist Validation Error - Yii Framework Forum

Jump to content

Page 1 of 1
  • You cannot start a new topic
  • You cannot reply to this topic

Dropdownlist Validation Error Rate Topic: -----

#1 User is offline   Néstor Acevedo 

  • Newbie
  • Yii
  • Group: Members
  • Posts: 11
  • Joined: 08-January 13

Posted 13 January 2013 - 07:15 PM

Buenas...

i'm developing a site. i built a for for upload images according a section id. i put the following:

<?php echo $form->labelEx($model,'Seccion'); ?>
		<?php echo $form->dropDownList($model,'id_seccion',array(1=>"Inicio", 2=>"Nuestra Empresa", 3=>"Servicios", 4=>"Productos", 5=> "Nuestros Clientes")); ?>
                <?php echo $form->error($model,'seccion'); ?>


at the moment to send the form, i get an error

Quote

Seccion cannot be blank.


in the same web site, following the post sample in the tutorial, the same thing works.

setting the tables and relations as made for yii i have:

for post model
/**
	 * @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(
			'author' => array(self::BELONGS_TO, 'User', 'author_id'),
                        'seccion' => array(self::BELONGS_TO, 'Seccion', 'id_seccion'),
		);
	}


for banner model
/**
	 * @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(
			'seccion' => array(self::BELONGS_TO, 'Seccion', 'id_seccion'),
		);
	}


in the rules i have:

for post
return array(
			array('title, content, status, id_seccion', 'required'),
			array('status, id_seccion, create_time, update_time, author_id', 'numerical', 'integerOnly'=>true),
			array('title', 'length', 'max'=>128),
			array('tags', 'safe'),
			// The following rule is used by search().
			// Please remove those attributes that should not be searched.
			array('id, title, content, tags, status, id_seccion, create_time, update_time, author_id', 'safe', 'on'=>'search'),
		);


for banner
return array(
			array('imagen, id_seccion', 'required'),
			array('id_seccion', 'numerical', 'integerOnly'=>true),
                        // this will allow empty field when page is update (remember here i create scenario update)
			array('imagen', 'file','types'=>'jpg, gif, png', 'allowEmpty'=>true, 'on'=>'update'), 
			// The following rule is used by search().
			// Please remove those attributes that should not be searched.
			array('id_banner, id_seccion', 'safe', 'on'=>'search'),
		);


my question is: why i get that validation error in id_seccion if in post model works fine?
0

#2 User is offline   softark 

  • Keep It Simple
  • Yii
  • Group: Moderators
  • Posts: 2,082
  • Joined: 16-February 11
  • Location:Japan

Posted 13 January 2013 - 07:46 PM

Hi Néstor,

Can you show us your controller code? I don't see anything wrong so far.
0

#3 User is offline   Néstor Acevedo 

  • Newbie
  • Yii
  • Group: Members
  • Posts: 11
  • Joined: 08-January 13

Posted 13 January 2013 - 09:29 PM

View Postsoftark, on 13 January 2013 - 07:46 PM, said:

Hi Néstor,

Can you show us your controller code? I don't see anything wrong so far.


thnx for the anwwer

recently checking for another thing, i've found i mistook a code line where to "re-create" the model:


/**
	 * Creates a new model.
	 * If creation is successful, the browser will be redirected to the 'view' page.
	 */
        public function actionCreate()
        {
            $model=new Banner;  // this is my model related to table
            if(isset($_POST['Banner']))
            {
                /*$rnd = rand(0,9999);  // generate random number between 0-9999
                $model->attributes=$_POST['Banner'];// this line i forgot to uncomment xD

                $uploadedFile=CUploadedFile::getInstance($model,'imagen');
                $fileName = "{$rnd}-{$uploadedFile}";  // random number + file name
                $model->image = $fileName;

                if($model->save())
                {
                    $uploadedFile->saveAs(Yii::app()->basePath.'/../images/banner/'.$fileName);  // image will uplode to rootDirectory/banner/
                    $this->redirect(array('admin'));
                }*/
		$model->attributes=$_POST['Banner'];//copy&paste XD
                // file handling
                $imageUploadFile = CUploadedFile::getInstance($model, 'imagen');
                $rnd = rand(0,9999);  // generate random number between 0-9999
                if($imageUploadFile !== null){ // only do if file is really uploaded
                    $imageFileName = $rnd.$imageUploadFile->name;
                    $model->imagen = $imageFileName;
                }           

                if ($model->save()){
					
                    if($imageUploadFile !== null) // validate to save file
                        $imageUploadFile->saveAs(Yii::app()->basePath.'/../images/banner/'.$imageFileName);

                    $this->redirect(array('admin'));//$this->redirect(array('view', 'id' => $model->id));
                } else {
					var_dump($_POST['Banner']);
				}
            }
			
			//Setting the default value
			$model->id_seccion=1;
            $this->render('create',array(
                'model'=>$model,
            ));
        }


but now, re-using this post, how to set the uploaded image size -height & width-?
0

#4 User is offline   softark 

  • Keep It Simple
  • Yii
  • Group: Moderators
  • Posts: 2,082
  • Joined: 16-February 11
  • Location:Japan

Posted 13 January 2013 - 10:09 PM

You can use getimagesize(). :)
http://jp2.php.net/m...etimagesize.php

$sizes = getimagesize($imageUploadFile->tempName);
$model->width = $sizes[0];
$model->height = $sizes[1];

0

#5 User is offline   Néstor Acevedo 

  • Newbie
  • Yii
  • Group: Members
  • Posts: 11
  • Joined: 08-January 13

Posted 14 January 2013 - 01:49 PM

mmm ok

but the controller is who makes the logic in this case, and checking, the saveas method moves or copies the actual image, butdoesn't resize in any moment such as can do with
imagecopyresampled
, so in this case how to rezise the image?

if is needed, i would open a new post XD
0

#6 User is offline   softark 

  • Keep It Simple
  • Yii
  • Group: Moderators
  • Posts: 2,082
  • Joined: 16-February 11
  • Location:Japan

Posted 14 January 2013 - 05:48 PM

Yii doesn't have a built-in support for manipulating images.

If you don't want the controllers to be fat with the codes that manipulate images (load, save, resize, rotate, crop, ...), you can make some helper class to do that. Or, using some extension for images might be a good idea, too.

search for "image" in extension
0

Share this topic:


Page 1 of 1
  • You cannot start a new topic
  • You cannot reply to this topic

1 User(s) are reading this topic
0 members, 1 guests, 0 anonymous users