当前位置: 首页>>代码示例>>PHP>>正文


PHP Article::save方法代码示例

本文整理汇总了PHP中Article::save方法的典型用法代码示例。如果您正苦于以下问题:PHP Article::save方法的具体用法?PHP Article::save怎么用?PHP Article::save使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在Article的用法示例。


在下文中一共展示了Article::save方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。

示例1: mm_update

 public static function mm_update()
 {
     // Get the RSS feed from Morning Mail
     $xml = simplexml_load_file('http://morningmail.rpi.edu/rss');
     // Begin the transaction
     Database::beginTransaction();
     $count = 0;
     foreach ($xml->channel->item as $item) {
         // Check for duplicates (no DB-agnostic way
         // to ignore duplicate errors)
         if (self::find($item->link)) {
             continue;
         }
         // Parse data and construct Article objects,
         // save them to the DB
         $date = date_create($item->pubDate);
         $a = new Article($item->title, strip_tags($item->description), $date->format('Y-m-d H:i:s'), $item->link);
         // Increment row count
         $count++;
         if (!$a->save()) {
             Database::rollBack();
             return false;
         }
     }
     // Commit transaction
     Database::commit();
     return $count;
 }
开发者ID:kench,项目名称:websys-final,代码行数:28,代码来源:article.class.php

示例2: restore

 function restore()
 {
     $article = new Article($this->dbcon, $this->getArticleId());
     $article->saveVersion();
     $article->readVersion($this->id);
     return $article->save();
 }
开发者ID:radicaldesigns,项目名称:amp,代码行数:7,代码来源:Version.inc.php

示例3: store

 /**
  * Store a newly created resource in storage.
  * POST /articles
  *
  * @return Response
  */
 public function store()
 {
     $rules = Article::$rules;
     $validator = Validator::make(Input::all(), $rules);
     if ($validator->fails()) {
         $messages = $validator->messages();
         // return Response::json(['error' => $messages], 400);
     }
     $image = Input::file('file');
     if (!$image) {
         return Response::json(['error' => $messages], 400);
     } else {
         $admin = Auth::admin();
         $article = new Article();
         $article->admin_id = Auth::admin()->get()->id;
         $article->title = Input::get('title');
         $article->body = Input::get('body');
         $article->category_id = Input::get('category_id');
         $article->save();
         $thumb = new Photo();
         $filename = time() . '-' . $image->getClientOriginalName();
         $destinationPath = public_path('thumbs/' . $filename);
         $a = Image::make($image->getRealPath())->fit(1280, 720)->save($destinationPath, 50);
         // SAVE TO DB
         $thumb->image = 'thumbs/' . $filename;
         $thumb->article_id = $article->id;
         $thumb->save();
     }
 }
开发者ID:tprifti,项目名称:Blog,代码行数:35,代码来源:ArticlesController.php

示例4: actionCreate

 /**
  * 文章添加
  */
 public function actionCreate()
 {
     $model = new Article();
     $addonarticle = new Addonarticle();
     if (isset($_POST['Article'])) {
         $transaction = Yii::app()->db->beginTransaction();
         try {
             $model->attributes = $_POST['Article'];
             if (!$model->save()) {
                 Tool::logger('article', var_export($model->getErrors(), true));
                 throw new CException('文章生成失败');
             }
             $aid = $model->primaryKey;
             $addonarticle->attributes = $_POST['Addonarticle'];
             if (!$addonarticle->save()) {
                 Tool::logger('article', var_export($addonarticle->getErrors(), true));
                 throw new CException('文章附表生成失败');
             }
             $this->redirect(array('list'));
         } catch (Exception $e) {
             Tool::logger('article', $e->getMessage());
             $transaction->rollback();
         }
     }
     $this->render('create', array('model' => $model, 'addonarticle' => $addonarticle));
 }
开发者ID:njz817,项目名称:ycms,代码行数:29,代码来源:ArticleController.php

示例5: actionCreate

 public function actionCreate()
 {
     $author = $this->_checkAuth();
     $json = file_get_contents('php://input');
     $data = CJSON::decode($json, true);
     switch ($_GET['model']) {
         case 'articles':
             $model = new Article();
             break;
         default:
             Helper::renderJSONErorr('create is not implemented for model ' . $_GET['model']);
     }
     foreach ($data as $var => $value) {
         if ($model->hasAttribute($var)) {
             $model->{$var} = $value;
         } else {
             Helper::renderJSONErorr("Parameter {$var} is not allowed for model " . $_GET['model']);
         }
     }
     if ($model->hasAttribute('author')) {
         $model->author = $author->id;
     }
     // Try to save the model
     if ($model->save()) {
         Helper::renderJSON($model);
     }
     $msg = sprintf("Couldn't create model %s\n", $_GET['model']);
     foreach ($model->errors as $attribute => $attr_errors) {
         $msg .= "Attribute: {$attribute}\n";
         foreach ($attr_errors as $attr_error) {
             $msg .= "- {$attr_error}\n";
         }
     }
     Helper::renderJSONErorr($msg);
 }
开发者ID:Alexnder,项目名称:angular-yii-rest-test,代码行数:35,代码来源:ApiController.php

示例6: create

 public function create()
 {
     $article = new Article();
     if ($this->post) {
         $article->title = $this->PostData('title');
         $article->permalink = $this->PostData('permalink');
         $article->summary = $this->PostData('summary');
         $article->published = $this->PostData('published');
         if ($this->PostData('publish_now') == 1) {
             $article->publish_at = time();
         } else {
             $article->set_publish_at($this->PostData('publish_at'));
         }
         $article->user_id = Site::CurrentUser()->id;
         if ($article->save()) {
             $page = new ArticlePage();
             $page->article_id = $article->id;
             $page->title = $article->title;
             $page->content = $this->PostData('fullbody');
             $page->save();
             Site::Flash("notice", "The article has been added");
             Redirect("admin/articles/{$article->id}");
         }
         $this->assign("body", $this->PostData('fullbody'));
     }
     $this->assign("article", $article);
     $this->tinymce = true;
     $this->title = "Add Article";
     $this->render("article/create.tpl");
 }
开发者ID:ItsHaden,项目名称:epicLanBootstrap,代码行数:30,代码来源:article.controller.php

示例7: backproject

 function backproject()
 {
     $this->load->model("common");
     $old_news = $this->common->getall('mf_project');
     $newscatalogue = new Newscatalogue(21);
     foreach ($old_news as $row) {
         $news = $this->common->getdetaildata('mf_node', array('id' => $row->nid));
         $article = new Article();
         $article->title_vietnamese = $news->title;
         $article->title_none = $news->title_seo;
         $article->full_vietnamese = str_replace('src="/', 'src="', $news->content);
         $article->short_vietnamese = $news->description;
         $article->tag = $news->title;
         $article->old_id = 1;
         $article->dir = "";
         $article->active = 1;
         $article->image = substr($news->img_url, 1, strlen($news->img_url) - 1);
         if (!$article->save($newscatalogue)) {
             foreach ($article->error->all as $error) {
                 echo "<br>" . $error;
             }
         }
         $article->clear();
     }
 }
开发者ID:lxthien,项目名称:batdongsan,代码行数:25,代码来源:backup.php

示例8: addAction

 public function addAction()
 {
     if ($this->request->isPost() == true) {
         $ans = [];
         try {
             $title = $this->request->getPost("title");
             $date = $this->request->getPost("date");
             $body = $this->request->getPost("body");
             $section = $this->request->getPost("section");
             $existArticle = Article::find(array("conditions" => "title=?1", "bind" => array(1 => $title)));
             if (count($existArticle) == 0) {
                 $article = new Article();
                 $article->title = $title;
                 $article->date = $date;
                 $article->body = ${$body};
                 $article->section = $section;
                 if ($article->save()) {
                     $ans['ret'] = $article->id;
                     echo json_encode($ans);
                 } else {
                     foreach ($article->getMessages() as $message) {
                         throw new BaseException($message, 100);
                     }
                 }
             } else {
                 $ans['ret'] = -1;
                 $ans['error'] = 201;
                 echo json_encode($ans);
                 throw new BaseException('同名文章已存在', 201);
             }
         } catch (BaseException $e) {
         }
     }
 }
开发者ID:hyfjjjj,项目名称:HHA-Web,代码行数:34,代码来源:ArticleController.php

示例9: Articlecategory

 function article_create()
 {
     $this->load->library('form_validation');
     $this->form_validation->set_rules('title', 'Titel', 'required|callback_article_unique_title');
     $this->form_validation->set_rules('intro', 'Einführungstext', 'required');
     $this->form_validation->set_rules('category[]', 'Kategorie', 'required');
     $this->form_validation->set_rules('body', 'Text', 'required');
     if ($this->form_validation->run() == TRUE) {
         $articlecategories = new Articlecategory();
         $articlecategories->where_in('id', $this->input->post('category'))->get();
         $article = new Article();
         $article->title = $this->input->post('title');
         $article->alias = $this->_title_to_alias($article->title);
         $article->intro = $this->input->post('intro');
         $article->body = $this->input->post('body');
         $article->state = 1;
         $article->save($articlecategories->all);
         redirect('artikel');
     } else {
         $articlecategories = new Articlecategory();
         $this->template->set('res_articlecategories', $articlecategories->get());
         $this->template->set_block('sidebar', 'content/articles/_sidebar_create');
         $this->template->set('page_name', 'Artikel schreiben');
         $this->template->current_view = 'content/articles/create';
         $this->template->render();
     }
 }
开发者ID:juna,项目名称:notre-menage,代码行数:27,代码来源:articles.php

示例10: postAdd

 public function postAdd()
 {
     $rules = array('title' => 'required|min:4', 'link' => "required|unique:articles", 'description' => 'required|min:20|max:500', 'content' => 'required|min:100', 'published_at' => 'required', 'meta_keywords' => 'required', 'parameters' => 'required');
     $validator = Validator::make(Input::all(), $rules);
     if ($validator->fails()) {
         $parameters = json_decode(Input::get('parameters'));
         return Redirect::to("admin/article/add")->with('uploadfile', isset($parameters->name) ? $parameters->name : '')->withErrors($validator)->withInput(Input::except(''));
     }
     $table = new Article();
     $table->title = Input::get('title');
     $table->link = Input::get('link');
     $table->user_id = Auth::user()->id;
     $table->description = Input::get('description');
     $table->content = Input::get('content');
     $table->meta_title = Input::get('meta_title') ? Input::get('meta_title') : $table->title;
     $table->meta_description = Input::get('meta_description') ? Input::get('meta_description') : $table->description;
     $table->meta_keywords = Input::get('meta_keywords');
     $table->published_at = Article::toDate(Input::get('published_at'));
     $table->active = Input::get('active', 0);
     if ($table->save()) {
         if (Input::get('parameters')) {
             $parameters = json_decode(Input::get('parameters'));
             $img = Image::make($parameters->name);
             $img->crop($parameters->w, $parameters->h, $parameters->x, $parameters->y);
             $img->resize(320, 240);
             $img->save("uploads/images/articles/{$table->id}.jpg");
             File::delete($parameters->tmp);
             $img->resize(200, 150);
             $img->save("uploads/images/articles/{$table->id}_small.jpg");
         }
         $name = trans("name.article");
         return Redirect::to("admin/article")->with('success', trans("message.add", ['name' => $name]));
     }
     return Redirect::to("admin/article")->with('error', trans('message.error'));
 }
开发者ID:Rotron,项目名称:shop,代码行数:35,代码来源:AdminArticleController.php

示例11: actionRandomArticle

 public function actionRandomArticle()
 {
     $n = rand(0, 1000);
     $article = new Article();
     $article->title = "Title #" . $n;
     $article->text = "Text #" . $n;
     $article->save();
     Yii::app()->setGlobalState('article', $article->id);
     echo "OK";
 }
开发者ID:moohwaan,项目名称:yii-application-cookbook-2nd-edition-code,代码行数:10,代码来源:DashboardController.php

示例12: store

 /**
  * Store a newly created resource in storage.
  *
  * @return Response
  */
 public function store()
 {
     //TODO: should move this to service  ( use ioc)
     $article = new Article();
     $article->title = Input::get('title');
     $article->body = Input::get('body');
     $article->published_at = Carbon::now();
     $article->save();
     return Response::make(['id' => $article->id], 201);
 }
开发者ID:nguyentienlong,项目名称:laravel.sandbox,代码行数:15,代码来源:ArticleController.php

示例13: testAdminUser

 public function testAdminUser()
 {
     $user = User::create(array('username' => 'testuser'));
     $user->save();
     $group = Group::create(array('name' => 'An admin group', 'is_admin' => true));
     $user->groups()->attach($group->id);
     $article = new Article();
     $article->body = 'can you access this?';
     $article->save();
     $this->assertTrue($this->redoubt->userCan('edit', $article, $user));
 }
开发者ID:georgebohnisch,项目名称:redoubt-plus,代码行数:11,代码来源:UserTest.php

示例14: actionCreate

 /**
  * Creates a new model.
  * If creation is successful, the browser will be redirected to the 'view' page.
  */
 public function actionCreate()
 {
     $model = new Article();
     $model->attributes = $_POST['Article'];
     if (isset($_POST['Article'])) {
         if ($model->save()) {
             $this->redirect(array('admin'));
         }
     }
     $this->render('create', array('model' => $model));
 }
开发者ID:lhfcainiao,项目名称:basic,代码行数:15,代码来源:ArticleController.php

示例15: post_or_edit

 public function post_or_edit($id = null)
 {
     parent::load('model', 'articles');
     parent::load('model', 'system/contrib/auth');
     $smarty = parent::load('smarty');
     $categories = Category::get_select(User::info());
     if (!$categories) {
         $smarty->display('403');
         Boot::shutdown();
     }
     if ($id) {
         $article = ArticleTable::getInstance()->find($id);
         $has_role = Category::has_role($article->Category->id, User::info());
         if ((!$has_role || $article->author != User::info('id')) && !User::has_role('人力资源') && !User::has_role('总经理')) {
             $this->smarty->display(403);
             Boot::shutdown();
         }
         if (!$article) {
             $smarty->display('404');
             Boot::shutdown();
         }
         $article->content = stripslashes($article->content);
         $smarty->assign('article', $article);
         $smarty->assign('selected_category', $article->category_id);
         $smarty->assign('page_title', '修改文章');
     } else {
         if ($_GET['category']) {
             $smarty->assign('selected_category', $_GET['category']);
         }
         $article = new Article();
         $smarty->assign('page_title', '添加新文章');
     }
     if ($this->is_post()) {
         $category = Category::has_role($_POST['category_id'], User::info());
         if (!$category) {
             $smarty->display('403');
             Boot::shutdown();
         }
         $article->name = trim(strip_tags($_POST['name']));
         $article->content = $_POST['content'];
         $article->Category = $category;
         $search = array('/', ' ', '?', '&');
         $replace = array('_', '-', '.', '-');
         $article->alias = str_replace($search, $replace, strip_tags($_POST['alias']));
         $article->author = User::info('id');
         $article->save();
         import('system/share/network/redirect');
         $act = $id ? '编辑' : '添加新的';
         HTTPRedirect::flash_to('articles/detail/' . $article->id, sprintf('%s %s 成功', $act, $category->name), $smarty);
     } else {
         $smarty->assign('categories', $categories);
         $smarty->display('article/add');
     }
 }
开发者ID:uwitec,项目名称:mgoa,代码行数:54,代码来源:ArticleController.php


注:本文中的Article::save方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。