Yii Framework Forum: مشکل با Validatorها - Yii Framework Forum

Jump to content

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

مشکل با Validatorها

#1 User is offline   Shahcheraghean 

  • Advanced Member
  • PipPipPip
  • Yii
  • Group: Members
  • Posts: 478
  • Joined: 12-December 12
  • Location:Mashhad, IRAN

Posted 15 December 2012 - 04:50 AM

با سلام.
با همان مثال عمومی blog داشتم با فریمورک Yii آشنا می شدم که با خطای زیر روبرو شدم. هر چی ruleها را چک می کنم متوجه دلیل خطا نمی شوم.
کسی می تونه کمک کنه؟

CException

Post has an invalid validation rule. The rule must specify attributes to be validated and the validator name.

/var/www/yii/framework/base/CModel.php(287)

275      * Creates validator objects based on the specification in {@link rules}.
276      * This method is mainly used internally.
277      * @return CList validators built based on {@link rules()}.
278      */
279     public function createValidators()
280     {
281         $validators=new CList;
282         foreach($this->rules() as $rule)
283         {
284             if(isset($rule[0],$rule[1]))  // attributes, validator name
285                 $validators->add(CValidator::createValidator($rule[1],$this,$rule[0],array_slice($rule,2)));
286             else
287                 throw new CException(Yii::t('yii','{class} has an invalid validation rule. The rule must specify attributes to be validated and the validator name.',
288                     array('{class}'=>get_class($this))));
289         }
290         var_dump($validators);
291         return $validators;
292     }
293 
294     /**
295      * Returns a value indicating whether the attribute is required.
296      * This is determined by checking if the attribute is associated with a
297      * {@link CRequiredValidator} validation rule in the current {@link scenario}.
298      * @param string $attribute attribute name
299      * @return boolean whether the attribute is required

Stack Trace
#0 	
+
 /var/www/yii/framework/base/CModel.php(259): CModel->createValidators()
#1 	
+
 /var/www/yii/framework/web/helpers/CHtml.php(1871): CModel->getValidators("id")
#2 	
+
 /var/www/yii/framework/web/helpers/CHtml.php(1217): CHtml::activeInputField("text", Post, "id", array("name" => "Post[id]", "id" => "Post_id"))
#3 	
+
 /var/www/yii/framework/web/widgets/CActiveForm.php(658): CHtml::activeTextField(Post, "id", array())
#4 	
–
 /var/www/nasr/protected/views/post/_search.php(16): CActiveForm->textField(Post, "id")

11     'method'=>'get',
12 )); ?>
13 
14     <div class="row">
15         <?php echo $form->label($model,'id'); ?>
16         <?php echo $form->textField($model,'id'); ?>
17     </div>
18 
19     <div class="row">
20         <?php echo $form->label($model,'title'); ?>
21         <?php echo $form->textField($model,'title',array('size'=>50,'maxlength'=>50)); ?>

#5 	
+
 /var/www/yii/framework/web/CBaseController.php(127): require("/var/www/nasr/protected/views/post/_search.php")
#6 	
+
 /var/www/yii/framework/web/CBaseController.php(96): CBaseController->renderInternal("/var/www/nasr/protected/views/post/_search.php", array("model" => Post), true)
#7 	
+
 /var/www/yii/framework/web/CController.php(870): CBaseController->renderFile("/var/www/nasr/protected/views/post/_search.php", array("model" => Post), true)
#8 	
–
 /var/www/nasr/protected/views/post/admin.php(40): CController->renderPartial("_search", array("model" => Post))

35 
36 <?php echo CHtml::link('Advanced Search','#',array('class'=>'search-button')); ?>
37 <div class="search-form" style="display:none">
38 <?php $this->renderPartial('_search',array(
39     'model'=>$model,
40 )); ?>
41 </div><!-- search-form -->
42 
43 <?php $this->widget('zii.widgets.grid.CGridView', array(
44 //    'id'=>'post-grid',
45     'dataProvider'=>$model->search(),

#9 	
+
 /var/www/yii/framework/web/CBaseController.php(127): require("/var/www/nasr/protected/views/post/admin.php")
#10 	
+
 /var/www/yii/framework/web/CBaseController.php(96): CBaseController->renderInternal("/var/www/nasr/protected/views/post/admin.php", array("model" => Post), true)
#11 	
+
 /var/www/yii/framework/web/CController.php(870): CBaseController->renderFile("/var/www/nasr/protected/views/post/admin.php", array("model" => Post), true)
#12 	
+
 /var/www/yii/framework/web/CController.php(783): CController->renderPartial("admin", array("model" => Post), true)
#13 	
–
 /var/www/nasr/protected/controllers/PostController.php(149): CController->render("admin", array("model" => Post))

144          // ));
145         $model = new Post('search');
146         if (isset($_GET['Post'])) {
147             $model -> attributes = $_GET['Post'];
148         }
149         $this -> render('admin', array('model' => $model));
150     }
151 
152     /**
153      * Returns the data model based on the primary key given in the GET variable.
154      * If the data model is not found, an HTTP exception will be raised.


www.shgn.ir
www.shgn.ir/yii-framework/
yii2.swsco.ir
In a world without any fences or walls,Who needs Gates or Windows!
0

#2 User is offline   Hesam K 

  • Standard Member
  • PipPip
  • Yii
  • Group: Members
  • Posts: 127
  • Joined: 14-August 11

Posted 15 December 2012 - 06:00 AM


سلام
لطفا کد مربوط به validation های کلاس Post رو هم کپی کنید.

2

#3 User is offline   Shahcheraghean 

  • Advanced Member
  • PipPipPip
  • Yii
  • Group: Members
  • Posts: 478
  • Joined: 12-December 12
  • Location:Mashhad, IRAN

Posted 19 December 2012 - 11:15 AM

آقا این هم کدها:

public function rules()
	{
		// NOTE: you should only define rules for those attributes that
		// will receive user inputs.
		return array(
			array('title,content,status', 'required'),
			array('status, author_id', 'numerical', 'integerOnly'=>true),
			array('title, tags', 'length', 'max'=>50),
			array('content', 'length', 'max'=>1000),
			array('created, update_time', 'safe'),
			array('status','in','range'=>array(1,2,3)),
			array('tags','match','pattern'=>'/^[\w\s,]+$/','message'=>'تگهای فقط می توانند از حروف باشند'),
		    array('tags' => 'normalizeTags'),
			// The following rule is used by search().
			// Please remove those attributes that should not be searched.
			array('title, content, tags, status, created, update_time', 'safe', 'on'=>'search'),
		);
	}
    
    public function normalizeTags($attribute,$params)
    {
        $this->tags = Tag::array2string(array_unique(Tag::string2array($this->tags)));
    }

www.shgn.ir
www.shgn.ir/yii-framework/
yii2.swsco.ir
In a world without any fences or walls,Who needs Gates or Windows!
0

#4 User is offline   Nabi 

  • Standard Member
  • PipPip
  • Yii
  • Group: Members
  • Posts: 208
  • Joined: 22-February 12
  • Location:Ahwaz

Posted 20 December 2012 - 03:59 PM

این کد رو:

array('tags' => 'normalizeTags'),


بدین شکل تغییر دهید:


array('tags', 'normalizeTags'),



ضمناً در این مورد خاص به نظر بنده استفاده از filter مناسبتر است.


وقتی پیغام میذارید، بی زحمت متنتون رو انتخاب کنید و این دو تا کار ناقابل رو هم انجام بدید:
1. از اون بالا RTL رو انتخاب کنید.
2. فونت رو هم Tahoma بگذارید.
که چشمون در نیاد.
دمت گرم!

www.IranPHP.ir
1

#5 User is offline   Shahcheraghean 

  • Advanced Member
  • PipPipPip
  • Yii
  • Group: Members
  • Posts: 478
  • Joined: 12-December 12
  • Location:Mashhad, IRAN

Posted 23 December 2012 - 12:52 PM

آقا ممنون. درست شد :D . جواب داد.
بنده زیاد وارد نیستم. طبق Tutorial خود Yii برای ایجاد blog عمل کردم. چیزیه که توی داکش گفته.

www.shgn.ir
www.shgn.ir/yii-framework/
yii2.swsco.ir
In a world without any fences or walls,Who needs Gates or Windows!
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