本文整理汇总了PHP中app\models\Category::save方法的典型用法代码示例。如果您正苦于以下问题:PHP Category::save方法的具体用法?PHP Category::save怎么用?PHP Category::save使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类app\models\Category
的用法示例。
在下文中一共展示了Category::save方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: handle
/**
* Execute the job.
*
* @return bool
*/
public function handle()
{
$this->category->name = $this->request->input('name');
$this->category->options = ['manager' => $this->request->has('manager')];
$this->category->parent_id = $this->request->parent;
return $this->category->save();
}
示例2: 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]);
}
}
}
示例3: create
public function create()
{
$category = new Category();
if (Request::isMethod('post')) {
$rules = array('name' => 'required', 'description' => 'required');
$validator = Validator::make(Input::all(), $rules);
if ($validator->fails()) {
return Redirect::to('admin/category/create/')->withErrors($validator)->withInput();
} else {
if (empty(Input::get('seo_url'))) {
$seo_url = Helper::seo_url(Input::get('name'));
} else {
$seo_url = Input::get('seo_url');
}
// store
$category->name = Input::get('name');
$category->description = Input::get('description');
$category->seo_url = $seo_url;
$category->save();
$directory = $seo_url . '/' . $category->id;
$tmpFilePath = Config::get('constants.IMAGES_ABSOLUTE_URL') . 'categories/' . $directory . '/';
$file = Input::file('file');
if ($file) {
$tmpFileName = time() . '-' . $file->getClientOriginalName();
$file->move($tmpFilePath, $tmpFileName);
$category->thumbnail = $directory . '/' . $tmpFileName;
$category->save();
}
Session::flash('message', 'Successfully created Category');
return Redirect::to('/admin/category');
}
}
return view('Admin.category.create')->with(['category' => $category])->withInput(Input::all());
}
示例4: store
/**
* Store a newly created resource in storage.
*
* @return Response
*/
public function store(Request $request)
{
$this->validate($request, ['cat_name' => 'required|unique:categories|max:255']);
$cat = new Category();
$cat->cat_name = $request->input('cat_name');
//$post->slug = Str::slug(Input::get('title'));
$cat->parent_id = Input::get('parent_id');
$cat->cat_brief = Input::get('cat_brief');
if ($file = Input::file('image')) {
$allowed_extensions = ["png", "jpg", "gif"];
if ($file->getClientOriginalExtension() && !in_array($file->getClientOriginalExtension(), $allowed_extensions)) {
return ['error' => 'You may only upload png, jpg or gif.'];
}
$fileName = $file->getClientOriginalName();
$extension = $file->getClientOriginalExtension() ?: 'png';
$folderName = 'uploads/images/' . date("Ym", time()) . '/' . date("d", time());
$destinationPath = public_path() . '/' . $folderName;
$safeName = str_random(10) . '.' . $extension;
$file->move($destinationPath, $safeName);
$cat->image = $folderName . '/' . $safeName;
}
if ($cat->save()) {
return Redirect::to('admin/goods/cats');
} else {
return Redirect::back()->withInput()->withErrors('保存失败!');
}
}
示例5: actionSave
public function actionSave($id = 0)
{
$form = new \app\models\CategoryForm();
$post = Yii::$app->request->post();
if ($form->load($post) && $form->validate()) {
if ($id > 0) {
$cat_current = Category::findOne($id);
if (!$cat_current) {
throw new HttpException(404, 'Указанный Вами каталог не найден');
}
} else {
$cat_current = new Category();
}
$parent_id = intval($post['CategoryForm']['parent_id']);
if ($parent_id <= 0) {
$depth = 1;
} else {
$parent_cat = Category::findOne($parent_id);
$depth = intval($parent_cat->depth) + 1;
}
$cat_current->name = trim(htmlspecialchars($post['CategoryForm']['name']));
$cat_current->parent_id = $parent_id;
$cat_current->depth = $depth;
$cat_current->save();
return $this->redirect(Url::To(['category/cat', 'id' => $parent_id]));
}
return $this->redirect(Url::To(['category/' . ($id > 0 ? 'update' : 'add'), 'id' => $id]));
}
示例6: handle
/**
* Execute the job.
*
* @return bool
*/
public function handle()
{
$this->category->name = $this->request->input('name');
$this->category->belongs_to = 'inquiries';
$this->category->options = ['manager' => $this->request->has('manager')];
if ($this->request->has('parent')) {
$this->category->parent_id = $this->request->input('parent');
}
if ($this->category->save()) {
if ($this->parent instanceof Category) {
$this->category->parent()->associate($this->parent);
}
return true;
}
return false;
}
示例7: store
public function store($request)
{
$category = new Category();
$category->fill($request);
$category->save();
return $category;
}
示例8: create
/**
* Create page
*
* @param Request $request
* @return \Illuminate\Contracts\View\Factory|\Illuminate\Http\RedirectResponse|\Illuminate\View\View
*/
public function create(Request $request)
{
if ($request->isMethod('post')) {
$rules = ['name' => 'required|unique:categories,name', 'alias' => 'required|unique:categories,alias', 'content' => 'required'];
Validator::make($request->all(), $rules)->validate();
$page = new Category();
$page->name = $request->input('name');
$page->alias = $request->input('alias');
$page->meta_keys = $request->input('meta_keys');
$page->meta_desc = $request->input('meta_desc');
if ($request->has('parent')) {
$page->parent_id = $request->input('parent');
$page->type = 2;
} else {
$page->type = 1;
}
$page->content_type = 2;
$page->publish = $request->has('publish');
$page->save();
$page_content = new PageContent();
$page_content->content = $request->input('content');
$page_content->page_id = $page->id;
$page_content->save();
return redirect()->route('pages');
} else {
$pages = Category::getParentCategories();
return view('admin.page.create', compact('pages'));
}
}
示例9: store
/**
*
* @param Request $request
* @return Response
*/
public function store(StoreCategoryRequest $request)
{
$category = new Category($request->only(['name']));
$category->user()->associate(Auth::user());
$category->save();
return response($category->transform(), Response::HTTP_CREATED);
}
示例10: prosesAdd
public function prosesAdd()
{
$cat = new Category();
$cat->CategoryName = $_POST['name'];
$cat->save();
header("Location: " . base . "/Category");
}
示例11: run
/**
* Run the database seeds.
*
* @return void
*/
public function run()
{
/*Default Category*/
$category = new Category();
$category->user_id = 0;
$category->name = "Food & Drink";
$category->save();
$category = new Category();
$category->user_id = 0;
$category->name = "Bills";
$category->save();
$category = new Category();
$category->user_id = 0;
$category->name = "Transportation";
$category->save();
$category = new Category();
$category->user_id = 0;
$category->name = "Cellular";
$category->save();
$category = new Category();
$category->user_id = 0;
$category->name = "Tax";
$category->save();
$admin = new Admin();
$admin->username = "admin";
$admin->password = "123456";
$admin->secret = "123456";
$admin->save();
}
示例12: addCategory
public static function addCategory($title, $mid)
{
$category = new Category();
$category->title = $title;
$category->mid = $mid;
$category->sort_id = 1;
$category->save();
}
示例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();
if ($model->load(Yii::$app->request->post()) && $model->save()) {
return $this->redirect(['view', 'id' => $model->ID]);
} else {
return $this->render('create', ['model' => $model]);
}
}
示例14: update
/**
* Update the specified resource in storage.
*
* @param int $id
* @return Response
*/
public function update(Category $categories, CategoryRequest $request)
{
$attachment = ImageUploadFacade::image($request->file('attachment'));
$categories->fill($request->all());
if ($attachment) {
$categories->attachment()->associate($attachment);
}
$categories->save();
return redirect()->route('admin.categories.index');
}
示例15: store
/**
* Store a newly created resource in storage.
*
* @param \Illuminate\Http\Request $request
* @return \Illuminate\Http\Response
*/
public function store(Request $request)
{
$input = Input::all();
$restaurant = Restaurant::where('user_id', Auth::user()->id)->first();
$category = new Category();
$category->restaurant_id = $restaurant->id;
$category->category = $input['nombreCategoria'];
$category->save();
return redirect('admin/categories');
}