本文整理汇总了PHP中app\modules\shop\models\Category::load方法的典型用法代码示例。如果您正苦于以下问题:PHP Category::load方法的具体用法?PHP Category::load怎么用?PHP Category::load使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类app\modules\shop\models\Category
的用法示例。
在下文中一共展示了Category::load方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: actionEdit
public function actionEdit($parent_id = null, $id = null)
{
if (null === $parent_id) {
throw new NotFoundHttpException();
}
if (null === ($object = Object::getForClass(Category::className()))) {
throw new ServerErrorHttpException();
}
/** @var null|Category|HasProperties $model */
$model = null;
if (null !== $id) {
$model = Category::findById($id, null, null);
} else {
$parent = Category::findById($parent_id, null, null);
if ($parent_id === '0' || !is_null($parent)) {
$model = new Category();
$model->loadDefaultValues();
$model->parent_id = $parent_id;
if ($parent_id !== '0') {
$model->category_group_id = $parent->category_group_id;
}
} else {
throw new ServerErrorHttpException();
}
}
if (null === $model) {
throw new ServerErrorHttpException();
}
$event = new BackendEntityEditEvent($model);
$this->trigger(self::BACKEND_CATEGORY_EDIT, $event);
$post = \Yii::$app->request->post();
if ($event->isValid && $model->load($post) && $model->validate()) {
$saveStateEvent = new BackendEntityEditEvent($model);
$this->trigger(self::BACKEND_CATEGORY_EDIT_SAVE, $saveStateEvent);
$save_result = $model->save();
$model->saveProperties($post);
if (null !== ($view_object = ViewObject::getByModel($model, true))) {
if ($view_object->load($post, 'ViewObject')) {
if ($view_object->view_id <= 0) {
$view_object->delete();
} else {
$view_object->save();
}
}
}
if ($save_result) {
$modelAfterSaveEvent = new BackendEntityEditEvent($model);
$this->trigger(self::BACKEND_CATEGORY_AFTER_SAVE, $modelAfterSaveEvent);
$this->runAction('save-info', ['model_id' => $model->id]);
Yii::$app->session->setFlash('success', Yii::t('app', 'Record has been saved'));
$returnUrl = Yii::$app->request->get('returnUrl', ['index']);
switch (Yii::$app->request->post('action', 'save')) {
case 'next':
return $this->redirect(['edit', 'returnUrl' => $returnUrl, 'parent_id' => Yii::$app->request->get('parent_id', null)]);
case 'back':
return $this->redirect($returnUrl);
default:
return $this->redirect(Url::toRoute(['edit', 'id' => $model->id, 'returnUrl' => $returnUrl, 'parent_id' => $model->parent_id]));
}
} else {
throw new ServerErrorHttpException();
}
}
return $this->render('category-form', ['model' => $model, 'object' => $object]);
}