本文整理汇总了PHP中app\models\Post::load方法的典型用法代码示例。如果您正苦于以下问题:PHP Post::load方法的具体用法?PHP Post::load怎么用?PHP Post::load使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类app\models\Post
的用法示例。
在下文中一共展示了Post::load方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: actionCreate
/**
* Creates a new Post model.
* If creation is successful, the browser will be redirected to the 'view' page.
* @return mixed
*/
public function actionCreate()
{
$model = new Post();
$currentUser = \Yii::$app->user->identity;
if (!$currentUser->isAuthor()) {
//不是 作者 无权操作
return $this->goHome();
}
if ($model->load(Yii::$app->request->post())) {
if (isset($model->user_id) || $currentUser->id != $model->user_id && !$currentUser->isAdmin()) {
$model->user_id = $currentUser->id;
}
$model->user_id = $currentUser->id;
//处理slug
$title = mb_strlen($model->title, 'utf8') > 6 ? mb_substr($model->title, 0, 5) : $model->title;
$model->slug = \app\helpers\Pinyin::encode($title, 'all');
while (Post::getPostBySlug($model->slug)) {
$model->slug .= '-1';
}
if ($model->save()) {
$this->flash('发布成功!', 'info');
return $this->redirect(['update', 'id' => $model->id]);
}
}
$model->comment_status = Post::COMMENT_STATUS_OK;
$model->user_id = $currentUser->id;
return $this->render('create', ['model' => $model, 'isAdmin' => $currentUser->isAdmin()]);
}
示例2: actionCreate
/**
* create a post
*
* @return null|string|\yii\web\Response
* @throws Exception
* @throws \Exception
*/
public function actionCreate()
{
try {
Yii::trace('Trace :' . __METHOD__, __METHOD__);
$response = null;
$model = new Post(['scenario' => 'create']);
$query = (new Query())->select('name, id')->from('categories')->all();
$categories = ArrayHelper::map($query, 'id', 'name');
if ($model->load($_POST) === true && $model->validate() === true) {
$model->category_id = (int) $model->category_name;
$model->created = Yii::$app->formatter->asDateTime('now', 'php:Y-m-d H:i:s');
$model->user_id = Yii::$app->user->id;
$status = $model->save();
if ($status === true) {
$sidebarCacheName = isset(Yii::$app->params['cache']['sidebar']) ? Yii::$app->params['cache']['sidebar'] : null;
if ($sidebarCacheName !== null) {
Yii::$app->cache->delete($sidebarCacheName);
}
$response = $this->redirect(['/post/view', 'slug' => $model->slug]);
}
}
if ($response === null) {
$response = $this->render('create', ['model' => $model, 'categories' => $categories]);
}
return $response;
} catch (Exception $e) {
Yii::error($e->getMessage(), __METHOD__);
throw $e;
}
}
示例3: actionCreate
/**
* Creates a new Post model.
* If creation is successful, the browser will be redirected to the 'view' page.
* @return mixed
*/
public function actionCreate()
{
$model = new Post();
if ($model->load(Yii::$app->request->post()) && $model->save()) {
return $this->redirect(['view', 'id' => $model->id]);
} else {
return $this->render('create', ['model' => $model]);
}
}
示例4: actionCreate
/**
* Creates a new Post model.
* If creation is successful, the browser will be redirected to the 'view' page.
* @return mixed
*/
public function actionCreate()
{
$model = new Post();
if ($model->load(Yii::$app->request->post()) && $model->save()) {
return $this->redirect(['view', 'id' => $model->id]);
} else {
return $this->render('create', ['model' => $model, 'category' => Category::find()->all(), 'authors' => User::find()->all()]);
}
}
示例5: update
/**
* Update the specified resource in storage.
*
* @param PostFormRequest $request
* @param Post $post
* @return Response
*/
public function update(PostFormRequest $request, $post)
{
$post->fill($request->all());
$post->save();
if ($tags = $request->input('tags')) {
$post->retag($request->input('tags'));
}
return $post->load('tagged');
}
示例6: actionCreate
public function actionCreate()
{
$model = new Post();
if ($model->load(Yii::$app->request->post()) && $model->save()) {
return $this->redirect(['list']);
} else {
$model->status = POST::STATUS_ENABLED;
return $this->render('create', ['model' => $model]);
}
}
示例7: actionCreate
/**
* Creates a new Post model.
* If creation is successful, the browser will be redirected to the 'view' page.
* @return mixed
*/
public function actionCreate()
{
$model = new Post();
$model->author_name = Yii::$app->user->identity->nickname;
if ($model->load(Yii::$app->request->post())) {
$model->author_id = Yii::$app->user->id;
if ($model->save()) {
return $this->redirect(['view', 'id' => $model->id]);
}
}
return $this->render('create', ['model' => $model]);
}
示例8: actionCreate
/**
* Creates a new Post model.
* If creation is successful, the browser will be redirected to the 'view' page.
* @return mixed
*/
public function actionCreate()
{
$model = new Post();
$createdAt = time();
$model->created_at = $createdAt;
$model->updated_at = $createdAt;
if ($model->load(Yii::$app->request->post()) && $model->save()) {
$this->saveCategoriesList($model);
return $this->redirect(['view', 'id' => $model->id]);
} else {
return $this->render('create', ['model' => $model, 'categoriesList' => $this->getCategoriesList()]);
}
}
示例9: actionCreate
/**
* Creates a new Post model.
* If creation is successful, the browser will be redirected to the 'view' page.
* @return mixed
*/
public function actionCreate()
{
$model = new Post();
if ($model->load(Yii::$app->request->post())) {
$model->datetime = date("Y-m-d H:i:s");
$model->Participant_id = Yii::$app->user->id;
if ($model->save()) {
return $this->redirect(['view', 'id' => $model->id]);
}
//die(var_dump($model->getErrors()));
} else {
return $this->render('create', ['model' => $model]);
}
}
示例10: actionCreate
/**
* Creates a new Post model.
* If creation is successful, the browser will be redirected to the 'view' page.
* @return mixed
*/
public function actionCreate()
{
$model = new Post();
if ($model->load(Yii::$app->request->post()) && $model->save()) {
/** @var Category[] $categories */
$categories = Category::find()->where(['id' => $model->categories_id])->all();
foreach ($categories as $category) {
$model->link('categories', $category);
}
return $this->redirect(['view', 'id' => $model->id]);
} else {
return $this->render('create', ['model' => $model, 'category_names' => ArrayHelper::map(Category::find()->all(), 'id', 'name')]);
}
}
示例11: actionCreate
/**
* Creates a new Post model.
* If creation is successful, the browser will be redirected to the 'view' page.
* @return mixed
*/
public function actionCreate()
{
$model = new Post();
$post = Yii::$app->request->post();
if ($model->load($post)) {
$model->user_id = $userId = \Yii::$app->user->identity->id;
if ($model->save()) {
return $this->redirect(Yii::$app->request->referrer);
}
} elseif (Yii::$app->request->isAjax) {
return $this->renderAjax('_form', ['model' => $model]);
} else {
return $this->render('_form', ['model' => $model]);
}
}
示例12: actionCreate
/**
* Creates a new Post model.
* If creation is successful, the browser will be redirected to the 'view' page.
* @return mixed
*/
public function actionCreate()
{
$model = new Post();
$model->create_at = $model->update_at = $model->reply_at = time();
$model->user_id = User::getCurrentId();
if ($model->load(Yii::$app->request->post()) && $model->save()) {
if ($model->point_id > 0) {
$point = Point::findOne($model->point_id);
$point->post_num += 1;
$point->save();
}
return $this->redirect(['view', 'id' => $model->id]);
} else {
return $this->render('create', ['model' => $model, 'point' => Point::findOne(isset($_GET['point']) ? $_GET['point'] : '')]);
}
}
示例13: actionNew
public function actionNew()
{
$postModel = new Post();
$category = new Category();
$categoryList = ArrayHelper::map($category->find()->asArray()->all(), 'id', 'title');
$postList = $postModel->find()->asArray()->all();
$message = '';
if ($postModel->load(Yii::$app->request->post()) && $postModel->save()) {
$selectedCategories = Category::find()->where(['id' => $postModel->categoryIds])->all();
foreach ($selectedCategories as $category) {
$postModel->link('categories', $category);
}
$message = 'Category added success';
}
return $this->render('new', ['model' => $postModel, 'message' => $message, 'categoryList' => $categoryList, 'postList' => $postList]);
}
示例14: actionCreate
/**
* Creates a new Post model.
* If creation is successful, the browser will be redirected to the 'view' page.
* @return mixed
*/
public function actionCreate()
{
$model = new Post();
$pages = Page::find()->all();
$request = Yii::$app->request;
$model->page_id = $request->get('page_id');
$model->create_date = mktime();
$model->update_date = mktime();
if ($model->load(Yii::$app->request->post())) {
$model->create_date = strtotime($model->create_date);
$model->update_date = strtotime($model->update_date);
if ($model->save()) {
return $this->redirect(['view', 'id' => $model->id]);
}
} else {
return $this->render('create', ['model' => $model, 'pages' => $pages]);
}
}
示例15: actionCreate
/**
* Creates a new Post model.
* If creation is successful, the browser will be redirected to the 'view' page.
* @return mixed
*/
public function actionCreate()
{
$model = new Post();
/*if ($model->load(Yii::$app->request->post())) {
$image = UploadedFile::getInstance($model, 'foto_konten');
if ($model->save() && $model->upload()) {
return $this->redirect(['site/index']);
}
} else {
return $this->render('create', [
'model' => $model,
]);
}*/
if ($model->load(Yii::$app->request->post()) && $model->save()) {
return $this->redirect(['site/index']);
} else {
return $this->render('create', ['model' => $model]);
}
}