/**
  * This function performs the validation work for complex object models.
  *
  * In addition to checking the current object, all related objects will
  * also be validated.  If all pass then <code>true</code> is returned; otherwise
  * an aggreagated array of ValidationFailed objects will be returned.
  *
  * @param      array $columns Array of column names to validate.
  * @return     mixed <code>true</code> if all validations pass; array of <code>ValidationFailed</code> objets otherwise.
  */
 protected function doValidate($columns = null)
 {
     if (!$this->alreadyInValidation) {
         $this->alreadyInValidation = true;
         $retval = null;
         $failureMap = array();
         // We call the validate method on the following object(s) if they
         // were passed to this object by their coresponding set
         // method.  This object relates to these object(s) by a
         // foreign key reference.
         if ($this->aAuthor !== null) {
             if (!$this->aAuthor->validate($columns)) {
                 $failureMap = array_merge($failureMap, $this->aAuthor->getValidationFailures());
             }
         }
         if ($this->aArticle !== null) {
             if (!$this->aArticle->validate($columns)) {
                 $failureMap = array_merge($failureMap, $this->aArticle->getValidationFailures());
             }
         }
         if (($retval = AuthorArticlePeer::doValidate($this, $columns)) !== true) {
             $failureMap = array_merge($failureMap, $retval);
         }
         $this->alreadyInValidation = false;
     }
     return !empty($failureMap) ? $failureMap : true;
 }
 public function actionAddlabel()
 {
     $articleModel = new Article();
     if (isset($_POST['Article'])) {
         /*
          * 这里注意将post的值压入属性中
          * 并向里压入一个userid
          */
         $_POST['Article']['userid'] = Yii::app()->session['uid'];
         $articleModel->attributes = $_POST['Article'];
         if ($articleModel->validate()) {
             if ($articleModel->save()) {
                 //Yii::app()->user->setFlash('success','添加标签成功。(⊙_⊙)');
                 $this->redirect(array('labels'));
             }
         }
     }
     $this->render("addlabel", array('articleModel' => $articleModel));
 }
 /**
  * Store a newly created resource in storage.
  *
  * @return Response
  */
 public function store()
 {
     $data = Input::all();
     $product_id = Input::get('product_id');
     $data['price'] = str_replace(",", ".", $data['price']);
     $validation = Article::validate($data);
     $article = new Article();
     if ($validation->fails()) {
         return Redirect::to('articles/create')->withErrors($validation)->withInput();
     }
     $file = Input::file('image');
     $destinatonPath = 'public/storage/articles';
     $originalName = $file->getClientOriginalName();
     $filename = rand(1, 10000) . $originalName;
     $file->move($destinatonPath, $filename);
     $article->title = $data['title'];
     $article->description = $data['description'];
     $article->price = $data['price'];
     $article->image = $filename;
     $article->save();
     return Redirect::route('articles.index')->with('message', 'Succesfull added article');
 }