本文整理汇总了PHP中common\models\Article::save方法的典型用法代码示例。如果您正苦于以下问题:PHP Article::save方法的具体用法?PHP Article::save怎么用?PHP Article::save使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类common\models\Article
的用法示例。
在下文中一共展示了Article::save方法的7个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: insert
/**
* 将文章插入数据库
* @param $title
* @param $content
* @param $publish_at
* @param $tag
* @return bool
*/
public static function insert($title, $content, $publish_at, $tag = '')
{
//插入标签(搜索的分类)
$article = new Article();
$article->title = $title;
$article->content = $content;
$article->author = 'yang';
$article->status = Article::STATUS_GATHER;
$article->publish_at = $publish_at;
$res = $article->save(false);
if ($tag) {
try {
$tagModel = Tag::find()->where(['name' => $tag])->one();
if (!$tagModel) {
$tagModel = new Tag();
$tagModel->name = $tag;
$tagModel->article_count = 0;
$tagModel->save(false);
}
$articleTag = new ArticleTag();
$articleTag->article_id = $article->id;
$articleTag->tag_id = $tagModel->id;
$articleTag->save(false);
} catch (\Exception $e) {
echo $e->getMessage() . PHP_EOL;
}
}
return $res ? true : false;
}
示例2: actionCreate
/**
* Creates a new Article model.
* If creation is successful, the browser will be redirected to the 'view' page.
* @return mixed
*/
public function actionCreate()
{
$model = new Article();
if ($model->load(Yii::$app->request->post()) && $model->save()) {
return $this->redirect(['index']);
} else {
return $this->render('create', ['model' => $model, 'categories' => ArticleCategory::find()->active()->all(), 'ads' => Ad::find()->all(), 'articles' => Article::find()->all()]);
}
}
示例3: actionCreate
/**
* Creates a new ArticleDownload model.
* If creation is successful, the browser will be redirected to the 'view' page.
* @return mixed
*/
public function actionCreate($cat_id)
{
$model = new ArticleDownload();
$Article = new Article();
$postData = Yii::$app->request->post();
if ($model->load($postData) && $Article->load($postData) && $Article->save() && $model->addData($Article->article_id)) {
Yii::$app->session->setFlash('success', '添加成功');
return $this->redirect(['article/index']);
} else {
Yii::$app->view->params['meta_title'] = '添加文章';
return $this->render('create', ['model' => $model, 'Article' => $Article]);
}
}
示例4: actionCreate
public function actionCreate()
{
//储存视频
if ($video = Yii::$app->request->post()) {
$model = new Article();
$files = Fileupload::upload();
$video['img'] = isset($files[0]) ? $files[0] : './img/default.jpg';
$model->set_video_data($video);
if ($model->save(false)) {
return $this->render('create', ['msg' => '添加视频成功!']);
} else {
return $this->render('create', ['msg' => '添加视频失败,请刷新重试!']);
}
} else {
return $this->render('create');
}
}
示例5: actionCreate
/**
* Creates a new Article model.
* If creation is successful, the browser will be redirected to the 'view' page.
* @return mixed
*/
public function actionCreate()
{
$model = new Article();
$dataModel = new ArticleData();
if ($model->load(Yii::$app->request->post()) && $dataModel->load(Yii::$app->request->post())) {
$isValid = $model->validate();
if ($isValid) {
$model->save(false);
$dataModel->id = $model->id;
$isValid = $dataModel->validate();
if ($isValid) {
$dataModel->save(false);
return $this->redirect(['index']);
}
}
}
return $this->render('create', ['model' => $model, 'dataModel' => $dataModel]);
}
示例6: insert
/**
* 将文章插入数据库
* @param $title 标题
* @param $content 内容
* @param $publish_at 发布时间
* @param string $category 分类名
* @param string $cover 封面
* @return int
*/
public function insert($title, $content, $publish_at, $category = '', $cover = '')
{
//插入标签(搜索的分类)
$categoryId = (new Category())->getCategoryIdByName($category);
if (!$categoryId) {
throw new Exception('该分类不存在');
}
$article = new Article();
$article->title = $title;
$article->author = '匿名';
$article->status = 1;
$article->category = $category;
$article->category_id = $categoryId;
$article->source = $this->config['domain'];
$article->cover = $cover;
$article->created_at = $publish_at;
$article->user_id = 0;
$res = $article->save(false);
if ($res) {
$articleData = new ArticleData();
$articleData->id = $article->id;
$articleData->content = $content;
$res = $articleData->save(false);
}
return $res ? 1 : 0;
}
示例7: actionAddNewsFromParser
public function actionAddNewsFromParser()
{
$result = 0;
$file = Yii::getAlias('@json') . DIRECTORY_SEPARATOR . 'import.json';
if (file_exists($file)) {
$ImportModel = file_get_contents($file);
$obj = json_decode($ImportModel);
//vd($obj);
if ($ImportModel) {
foreach ($obj as $row) {
$duble = Blog::getDublicateByTitle($row->title);
if (!$duble) {
$model = new Article();
$model->title = $row->title;
$model->image = $row->image ? $row->image : '';
$model->content = $row->content;
$model->created_at = $row->created_at;
$model->updated_at = $row->updated_at;
$model->author = $row->author;
$model->save();
$result = 1;
} else {
//echo "It is Dublicate", PHP_EOL;
}
}
}
}
return $result;
}