本文整理汇总了PHP中app\models\Category::load方法的典型用法代码示例。如果您正苦于以下问题:PHP Category::load方法的具体用法?PHP Category::load怎么用?PHP Category::load使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类app\models\Category
的用法示例。
在下文中一共展示了Category::load方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: actionCreate
/**
* Creates a new Category model.
* For ajax request will return json object
* and for non-ajax request if creation is successful, the browser will be redirected to the 'view' page.
* @return mixed
*/
public function actionCreate()
{
$request = Yii::$app->request;
$model = new Category();
if ($request->isAjax) {
/*
* Process for ajax request
*/
Yii::$app->response->format = Response::FORMAT_JSON;
if ($request->isGet) {
return ['title' => "Create new Category", 'content' => $this->renderAjax('create', ['model' => $model]), 'footer' => Html::button('Close', ['class' => 'btn btn-default pull-left', 'data-dismiss' => "modal"]) . Html::button('Save', ['class' => 'btn btn-primary', 'type' => "submit"])];
} else {
if ($model->load($request->post()) && $model->save()) {
return ['forceReload' => '#crud-datatable-pjax', 'title' => "Create new Category", 'content' => '<span class="text-success">Create Category success</span>', 'footer' => Html::button('Close', ['class' => 'btn btn-default pull-left', 'data-dismiss' => "modal"]) . Html::a('Create More', ['create'], ['class' => 'btn btn-primary', 'role' => 'modal-remote'])];
} else {
return ['title' => "Create new Category", 'content' => $this->renderAjax('create', ['model' => $model]), 'footer' => Html::button('Close', ['class' => 'btn btn-default pull-left', 'data-dismiss' => "modal"]) . Html::button('Save', ['class' => 'btn btn-primary', 'type' => "submit"])];
}
}
} else {
/*
* Process for non-ajax request
*/
if ($model->load($request->post()) && $model->save()) {
return $this->redirect(['view', 'id' => $model->id]);
} else {
return $this->render('create', ['model' => $model]);
}
}
}
示例2: actionCreate
/**
* Creates a new Category model.
* If creation is successful, the browser will be redirected to the 'view' page.
* @return mixed
*/
public function actionCreate()
{
$model = new Category();
if ($model->load(Yii::$app->request->post()) && $model->save()) {
return $this->redirect(['view', 'id' => $model->ID]);
} else {
return $this->render('create', ['model' => $model]);
}
}
示例3: actionCreate
/**
* Creates a new Category model.
* If creation is successful, the browser will be redirected to the 'view' page.
* @return mixed
*/
public function actionCreate()
{
$model = new Category();
if ($model->load(Yii::$app->request->post()) && $model->save()) {
Yii::$app->session->setFlash('success', "Category <strong>{$model->title}</strong> created.");
return $this->redirect(['index']);
} else {
return $this->render('create', ['model' => $model]);
}
}
示例4: actionCreate
public function actionCreate()
{
$model = new Category();
if ($model->load(Yii::$app->request->post()) && $model->save()) {
return $this->redirect(['list']);
} else {
$model->status = Category::STATUS_ENABLED;
return $this->render('create', ['model' => $model]);
}
}
示例5: actionCreate
/**
* Creates a new Category model.
* If creation is successful, the browser will be redirected to the 'view' page.
* @return mixed
*/
public function actionCreate()
{
$model = new Category();
$categories = Category::find()->all();
if ($model->load(Yii::$app->request->post()) && $model->save()) {
return $this->redirect(['view', 'id' => $model->id]);
} else {
return $this->render('create', array('model' => $model, 'categories' => $categories));
}
}
示例6: actionNew
public function actionNew()
{
$categoryModel = new Category();
$message = '';
if (!empty(Yii::$app->request->post('Category'))) {
if ($categoryModel->load(Yii::$app->request->post()) && $categoryModel->save()) {
$message = 'Category added success';
}
}
return $this->render('new', ['model' => $categoryModel, 'message' => $message]);
}
示例7: actionCreate
public function actionCreate()
{
$model = new Category();
$model->user_id = Yii::$app->user->identity->id;
if ($model->load(Yii::$app->request->post()) && $model->save()) {
Yii::$app->session->setFlash("Category-success", Yii::t("app", "Category successfully included"));
return $this->redirect(['index']);
} else {
return $this->render('create', ['model' => $model]);
}
}
示例8: actionCreate
/**
* Creates a new Category model.
*/
public function actionCreate()
{
$model = new Category();
$model->scenario = 'insert';
if ($model->load(Yii::$app->request->post())) {
MyModel::upload($model);
if ($model->save() && MyModel::updateParents($model)) {
return $this->redirect(['view', 'id' => $model->id]);
}
return $this->render('create', ['model' => $model]);
} else {
return $this->render('create', ['model' => $model]);
}
}
示例9: actionCreate
public function actionCreate()
{
$model = new Category();
if ($model->load(Yii::$app->request->post()) && $model->validate()) {
if ($model->parent == 0) {
$model->saveNode();
} elseif ($model->parent) {
$root = Category::find($model->parent);
$model->appendTo($root);
}
return $this->redirect(['view', 'id' => $model->id]);
} else {
return $this->render('create', ['model' => $model]);
}
}
示例10: actionCreate
/**
* Creates a new Category model.
* If creation is successful, the browser will be redirected to the 'view' page.
* @return mixed
*/
public function actionCreate()
{
$model = new Category();
if ($model->load(Yii::$app->request->post()) && $model->validate()) {
if ($model->parent == 0) {
$model->saveNode();
} else {
if ($model->parent) {
$root = $this->findModel($model->parent);
$model->appendTo($root);
}
}
return $this->render('tree');
} else {
return $this->render('create', ['model' => $model]);
}
}
示例11: actionCreate
/**
* Creates a new Category model.
* If creation is successful, the browser will be redirected to the 'view' page.
* @return mixed
*/
public function actionCreate()
{
if (Yii::$app->user->can('categoryCreate')) {
$model = new Category();
if ($model->load(Yii::$app->request->post()) && $model->save()) {
return $this->redirect(['view', 'id' => $model->id]);
} else {
return $this->render('create', ['model' => $model]);
}
} else {
if (Yii::$app->user->isGuest) {
Yii::$app->user->loginRequired();
} else {
throw new ForbiddenHttpException(Yii::t('yii', 'You are not allowed to perform this action.'));
}
}
}
示例12: actionCreate
/**
* Creates a new Category model.
* If creation is successful, the browser will be redirected to the 'view' page.
* @return mixed
*/
public function actionCreate()
{
if (Yii::$app->user->can("category/create")) {
$model = new Category();
if ($model->load(Yii::$app->request->post()) && $model->save()) {
if ($model->parent == NULL) {
$model->parent = 0;
$model->save();
}
return $this->redirect(['view', 'id' => $model->id]);
} else {
return $this->render('create', ['model' => $model]);
}
} else {
Yii::$app->session->setFlash('error', 'Нет доступа!');
$this->redirect('/');
}
}
示例13: actionCreate
/**
* Creates a new Category model.
* If creation is successful, the browser will be redirected to the 'view' page.
* @return mixed
*/
public function actionCreate()
{
$model = new Category();
$category_array = Category::getAllCategories();
if ($category_array) {
$category_array = ['0' => '顶级分类'] + $category_array;
} else {
$category_array = ['0' => '顶级分类'];
}
if (isset($category_array[1]) && $category_array[1] == '未分类') {
unset($category_array[1]);
}
if ($model->load($_POST)) {
if ($model->save()) {
$this->redirect(['category/view', 'id' => $model->id]);
}
}
return $this->render('create', ['model' => $model, 'category_array' => $category_array]);
}
示例14: actionCreate
/**
* Creates a new Category model.
* If creation is successful, the browser will be redirected to the 'view' page.
* @return mixed
*/
public function actionCreate()
{
$model = new Category();
if ($model->load(Yii::$app->request->post())) {
$model->url = UrlHelp::translateUrl($model->name);
if ($model->validate()) {
$model->imageFile = UploadedFile::getInstance($model, 'imageFile');
if ($model->imageFile) {
if ($imgName = $model->upload($model->url)) {
$model->img = $imgName;
}
}
$model->imageFile = null;
$model->save();
return $this->redirect(['view', 'id' => $model->id]);
}
}
return $this->render('create', ['model' => $model]);
}
示例15: actionCreate
/**
* Creates a new Category model.
* If creation is successful, the browser will be redirected to the 'view' page.
* @return mixed
*/
public function actionCreate()
{
$model = new Category();
if ($model->load(Yii::$app->request->post()) && $model->save()) {
if (isset($_POST['name']) && is_array($_POST['name'])) {
foreach ($_POST['name'] as $lang => $val) {
$model->setName($lang, $val);
}
}
if (isset($_POST['content']) && is_array($_POST['content'])) {
foreach ($_POST['content'] as $lang => $val) {
$model->setContent($lang, $val);
}
}
$model->updateURLCode();
return $this->redirect(['view', 'id' => $model->id]);
} else {
return $this->render('create', ['model' => $model]);
}
}