Skip to content

Commit

Permalink
fixed one news saving in model
Browse files Browse the repository at this point in the history
  • Loading branch information
tungus28 committed Oct 3, 2015
1 parent edaa66a commit 6d1db18
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 3 deletions.
11 changes: 9 additions & 2 deletions controllers/NewsController.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@
namespace frontend\controllers;

use Yii;
use yii\base\ErrorException;
use yii\db\Expression;
use yii\web\Controller;
use frontend\models\News;
use yii\data\ActiveDataProvider;
Expand Down Expand Up @@ -204,11 +206,16 @@ public function saveOneNews($news)
$oneNews = new News();
$oneNews->title = $news['title'];
$oneNews->content = $news['content'];
$oneNews->created = new \DateTime('now');
$oneNews->created = new Expression('NOW()');
$oneNews->active = 0;
$oneNews->freq = 0;

$oneNews->save();
//echo "<pre>"; print_r($oneNews); exit;

if(!$oneNews->save()) {
$msg = "ошибка записи: " . serialize($oneNews->errors);
throw new ErrorException($msg);
}
}

public function actionClearDb(/*Request $request*/)
Expand Down
2 changes: 1 addition & 1 deletion models/News.php
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ public static function tableName()
public function rules()
{
return [
[['title', 'content', 'active', 'freq', 'id', 'created'], 'required'],
[['title', 'content', 'active', 'freq', 'created'], 'required'],
[['title', 'content'], 'string'],
[['active'], 'boolean'],
[['freq', 'id'], 'integer'],
Expand Down

0 comments on commit 6d1db18

Please sign in to comment.