本文整理汇总了PHP中app\models\News::save方法的典型用法代码示例。如果您正苦于以下问题:PHP News::save方法的具体用法?PHP News::save怎么用?PHP News::save使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类app\models\News
的用法示例。
在下文中一共展示了News::save方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: postSave
public function postSave(Request $request)
{
if (!empty($this->name) && !empty($this->category) && !empty($this->content) && !empty($this->user_id)) {
$table = new Models\News();
$table->name = $this->name;
$table->create_time = date("Y-m-d H:i:s");
$table->group_news_id = $this->category;
$table->images = $this->images;
$table->slug = $this->slug;
$table->description = $this->description;
$table->content = $this->content;
$table->user_id = $this->user_id;
$table->keywords = $this->keywords;
$table->status = 1;
// 2 : không chọn , 1 là được chọn
$rs = $table->save();
$LastInsertId = $table->id;
$data = ['id' => $LastInsertId, 'name' => $this->name, 'create_time' => date("Y-m-d H:i:s"), 'group_news_id' => $this->category, 'images' => $this->image, 'description' => $this->description, 'content' => $this->content, 'status' => 1];
if ($rs) {
return $this->ResponseData($data);
}
$this->error = true;
$this->error_message = "Lỗi truy vấn, vui lòng thử lại sau";
return $this->ResponseData([]);
}
$this->error = true;
$this->error_message = "Dữ liệu gửi lên không đúng, vui lòng thử lại";
return $this->ResponseData([]);
}
示例2: actionCreate
/**
* Creates a new News model.
* If creation is successful, the browser will be redirected to the 'view' page.
* @return mixed
*/
public function actionCreate()
{
$model = new News();
$loaded = $model->load(Yii::$app->request->post());
if ($loaded) {
if ($model->is_published) {
$model->published = date('Y-m-d H:i:s');
}
}
if ($loaded && $model->save()) {
$model->upload();
$category_relations = $_POST['News']['categories'];
foreach ($category_relations as $cat_id) {
$category_relation = new CategoryRelations();
$category_relation->news_id = $model->id;
$category_relation->category_id = $cat_id;
$category_relation->save();
}
return $this->redirect(['view', 'id' => $model->id]);
} else {
$categories_arr = Category::find()->asArray()->all();
foreach ($categories_arr as &$cat) {
$categories[$cat['id']] = $cat['name'];
}
$model->is_published = 1;
return $this->render('create', compact('model', 'categories'));
}
}
示例3: actionUpdatenews
public function actionUpdatenews()
{
$data = [];
if (!empty($_POST['title']) and !empty($_POST['text']) and isset($_GET[id])) {
$data['id'] = $_GET['id'];
$data['title'] = $_POST['title'];
$data['text'] = $_POST['text'];
$data['datatime'] = date('Y-m-d H:i:s');
} else {
$error_report = 'Не указано как и какую новость необходимо обновить';
}
if (isset($data['title']) && isset($data['text']) && isset($data['datatime']) && !isset($eror_report)) {
$news = new NewsModel();
$news->id = $data['id'];
$news->title = $data['title'];
$news->text = $data['text'];
$news->datatime = $data['datatime'];
$news->save();
header('Location: /');
die;
} else {
$view = new View();
$view->error_report = $eror_report;
$view->display('second/error.php');
}
}
示例4: actionNews
public function actionNews()
{
for ($i = 1; $i <= 10; $i++) {
$model = new News();
$model->attributes = ['name' => 'Bài viết số ' . $i, 'title' => 'Title cua bai viet so ' . $i, 'slug' => 'bai-viet-so-' . $i, 'images' => '3.png', 'type_id' => rand(1, 100), 'user_id' => '1', 'created_at' => time(), 'updated_at' => time()];
$model->save();
}
}
示例5: actionSuggest
public function actionSuggest()
{
$model = new News(['status' => News::STATUS_DRAFT, 'scenario' => News::SCENARIO_SUGGEST]);
if ($model->load(Yii::$app->request->post()) && $model->save()) {
Yii::$app->session->setFlash('news.news_successfully_added');
return $this->redirect(['index']);
}
return $this->render('suggest', ['model' => $model]);
}
示例6: actionCreate
/**
* Creates a new News model.
* If creation is successful, the browser will be redirected to the 'view' page.
* @return mixed
*/
public function actionCreate()
{
$model = new News();
if ($model->load(Yii::$app->request->post()) && $model->save()) {
return Json::encode(['success' => true, 'message' => 'Created!']);
} else {
return Json::encode(['success' => false, 'content' => $this->renderPartial('_form', ['model' => $model])]);
}
}
示例7: actionCreate
/**
* Creates a new News model.
* If creation is successful, the browser will be redirected to the 'view' page.
* @return mixed
*/
public function actionCreate()
{
$model = new News();
if ($model->load(Yii::$app->request->post()) && $model->save()) {
return $this->redirect(['view', 'id' => $model->id]);
} else {
return $this->render('create', ['model' => $model]);
}
}
示例8: actionSave_news
public function actionSave_news()
{
$news = new News();
$news->title = $_POST['title'];
$news->content = $_POST['content'];
$news->createTime = date('Y-m-d H:i:s');
$news->tag = 'unnecessary';
$news->save();
echo 1;
}
示例9: actionCreate
protected function actionCreate()
{
try {
$article = new News();
$article->fill([]);
$article->save();
} catch (MultiException $e) {
$this->view->errors = $e;
}
echo $this->view->render(__DIR__ . '/../templates/update.php');
}
示例10: actionCreate
/**
* Creates a new News model.
* If creation is successful, the browser will be redirected to the 'view' page.
* @return mixed
*/
public function actionCreate()
{
$model = new News();
if ($model->load(Yii::$app->request->post())) {
$model->addedat = date("Y-m-d H:i:s");
$model->addedby = Yii::$app->user->identity->username;
$model->save();
return $this->redirect(['view', 'id' => $model->id]);
} else {
return $this->render('create', ['model' => $model]);
}
}
示例11: actionCreate
/**
* Действие для добовления новости
*
*/
protected function actionCreate()
{
if ($this->isPost()) {
try {
$news = new News();
$news->fill($_POST);
$news->save();
$this->redirect('/Admin');
} catch (MultiException $error) {
$this->view->errors = $error;
}
} else {
$this->view->errors = null;
}
$this->view->display(__DIR__ . '/../Templates/News/Create.php');
}
示例12: createNews
public function createNews()
{
if (!$this->checkLogin()) {
return redirect('login');
}
$item = new News();
$item->nTitle = Request::input('title');
$item->catId = Request::input('catId');
if ($item->catId == null) {
$item->catId = 1;
}
$item->nDescrHTML = Request::input('content');
if ($item->nTitle != null && $item->nDescrHTML != null && $item->catId != null) {
$item->save();
}
return redirect('news');
}
示例13: create
public function create(Request $request)
{
$clientId = Authorizer::getClientId();
$operatorId = (int) Authorizer::getResourceOwnerId();
$data = $request->all();
$validator = Validator::make($data, ['content' => 'required', 'link_url' => 'url', 'type' => 'in:0,1']);
if ($validator->fails() === true) {
return response()->json(['error' => $validator->errors()], 400);
}
if (!isset($data['type'])) {
$data['type'] = 0;
}
$data['app_id'] = $clientId;
$data['author_id'] = $operatorId;
$data['content'] = preg_replace('/<(.+?)>|<(\\/.+?)>/', '<$1>', $data['content']);
$news = new News($data);
$news->save();
$news = $this->unfoldNewsInfo($news);
return response()->json($news, 201);
}
示例14: actionKhoahoctv
/**
* This command echoes what you have entered as the message.
* @param string $message the message to be echoed.
*/
public function actionKhoahoctv()
{
for ($i = 16655; $i <= 70000; $i++) {
$crawler = new Crawl();
$crawler->arr_att_clean = array('script', '.thumblock');
$url = 'http://khoahoc.tv/quan-the-tu-vien-meteora-' . $i;
$namepath = '/html/body/div[1]/div[3]/div[1]/h1';
$contentpath = '/html/body/div[1]/div[3]/div[1]/div[3]';
$type_path = '/html/body/div[1]/div[3]/div[1]/div[2]/span[3]/a';
if (!@($name = $crawler->getTitle($url, $namepath))) {
echo 'error_' . $i . "\n";
} else {
$name = rUrl::utf8($crawler->getTitle($url, $namepath));
$content = $crawler->getTitle($url, $contentpath);
$type = $crawler->getTitle($url, $type_path);
$content = $crawler->removeLink($content);
$images = $crawler->getImagesFromMeta($url);
$keywords = $crawler->getKeywords($url);
$descriptionmeta = $crawler->getDescriptionmeta($url);
$type_slug = rUrl::slug($type);
$mType = Type::find()->Where(['LIKE', 'slug', $type_slug])->one();
$id_type = $mType['id'];
$slug = rUrl::slug($name);
if ($id_type !== null) {
$id_type = $mType['id'];
} else {
$id_type = 22;
}
$model = new News();
$model->attributes = ['name' => $name, 'slug' => $slug, 'images' => $images, 'description' => $content, 'seo_keywords' => $keywords, 'view_count' => rand(1000, 10000), 'source' => 'kh', 'seo_title' => $descriptionmeta, 'type_id' => $id_type, 'user_id' => 1, 'hot' => 0, 'post_final' => $i, 'created_at' => time(), 'updated_at' => time()];
$model->save();
echo "ok_" . $i . "\n";
// exit();
}
}
}
示例15: store
/**
* Store a newly created resource in storage.
*
* @param News $news
* @param \Illuminate\Http\Request $request
* @return \Illuminate\Http\Response
*/
public function store(Request $request, News $news)
{
$news->fill($request->all());
$news->save();
return redirect()->route('admin.news.index');
}