本文整理汇总了PHP中Category::save方法的典型用法代码示例。如果您正苦于以下问题:PHP Category::save方法的具体用法?PHP Category::save怎么用?PHP Category::save使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Category
的用法示例。
在下文中一共展示了Category::save方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: actionCreate
/**
* Creates a new model.
* If creation is successful, the browser will be redirected to the 'view' page.
*/
public function actionCreate()
{
$model = new Category();
$catlist = Category::getDropList(0);
$model->orderid = 1;
// Uncomment the following line if AJAX validation is needed
// $this->performAjaxValidation($model);
if (isset($_POST['Category'])) {
$model->attributes = $_POST['Category'];
$model->create_uid = Yii::app()->user->id;
$model->create_time = date('Y-m-d H:i:s');
$model->orderid = 1;
if ($model->save()) {
$id = $model->attributes['id'];
if ($model->pid == 0) {
$model->path = $id;
$model->level = 1;
$model->save();
} else {
$parent = Category::getParent($model->pid);
$model->path = $parent->path . '/' . $id;
$model->level = $parent->level + 1;
$model->save();
}
//$this->redirect(array('view','id'=>$model->id));
Yii::app()->user->setFlash('success', '信息提交成功!');
} else {
Yii::app()->user->setFlash('success', '信息提交失败!');
}
}
$this->render('create', array('model' => $model, 'catlist' => $catlist));
}
示例2: testSaveCustomFile
public function testSaveCustomFile()
{
// create custom file first
$this->request->set('file', 'theme/sometheme/test.tpl');
$this->request->set('code', 'test code');
$response = $this->controller->save();
// edit the file
$this->request->set('file', 'theme/sometheme/test.tpl');
$this->request->set('code', 'test code');
$response = $this->controller->save();
$template = new Template('test.tpl', 'sometheme');
$this->assertEquals($template->getCode(), 'test code');
$this->assertEquals($template->getFileName(), 'theme/sometheme/test.tpl');
$template->restoreOriginal();
}
示例3: updateCategory
public function updateCategory()
{
if (!Request::ajax()) {
return App::abort(404);
}
if (Input::has('pk')) {
return self::updateQuickEdit();
}
$arrReturn = ['status' => 'error'];
$category = new Category();
$category->name = Input::get('name');
$category->short_name = Str::slug($category->name);
$category->description = Input::get('description');
$category->parent_id = (int) Input::get('parent_id');
$category->order_no = (int) Input::get('order_no');
$category->active = Input::has('active') ? 1 : 0;
$pass = $category->valid();
if ($pass) {
$category->save();
$arrReturn = ['status' => 'ok'];
$arrReturn['message'] = $category->name . ' has been saved';
$arrReturn['data'] = $category;
} else {
$arrReturn['message'] = '';
$arrErr = $pass->messages()->all();
foreach ($arrErr as $value) {
$arrReturn['message'] .= "{$value}\n";
}
}
return $arrReturn;
}
示例4: actionCreate
/**
* Создает новую модель категории.
* Если создание прошло успешно - перенаправляет на просмотр.
*
* @return void
*/
public function actionCreate()
{
$model = new Category();
if (($data = Yii::app()->getRequest()->getPost('Category')) !== null) {
$model->setAttributes($data);
if ($model->save()) {
Yii::app()->user->setFlash(yupe\widgets\YFlashMessages::SUCCESS_MESSAGE, Yii::t('CategoryModule.category', 'Record was created!'));
$this->redirect((array) Yii::app()->getRequest()->getPost('submit-type', ['create']));
}
}
$languages = $this->yupe->getLanguagesList();
//если добавляем перевод
$id = (int) Yii::app()->getRequest()->getQuery('id');
$lang = Yii::app()->getRequest()->getQuery('lang');
if (!empty($id) && !empty($lang)) {
$category = Category::model()->findByPk($id);
if (null === $category) {
Yii::app()->user->setFlash(yupe\widgets\YFlashMessages::ERROR_MESSAGE, Yii::t('CategoryModule.category', 'Targeting category was not found!'));
$this->redirect(['create']);
}
if (!array_key_exists($lang, $languages)) {
Yii::app()->user->setFlash(yupe\widgets\YFlashMessages::ERROR_MESSAGE, Yii::t('CategoryModule.category', 'Language was not found!'));
$this->redirect(['create']);
}
Yii::app()->user->setFlash(yupe\widgets\YFlashMessages::SUCCESS_MESSAGE, Yii::t('CategoryModule.category', 'You are adding translate in to {lang}!', ['{lang}' => $languages[$lang]]));
$model->lang = $lang;
$model->slug = $category->slug;
$model->parent_id = $category->parent_id;
$model->name = $category->name;
} else {
$model->lang = Yii::app()->language;
}
$this->render('create', ['model' => $model, 'languages' => $languages]);
}
示例5: postCategory
public function postCategory()
{
$category = new Category();
$category->name = Input::get('name');
$category->save();
return Response::json($category);
}
示例6: store
/**
* Store a newly created resource in storage.
*
* @return Response
*/
public function store()
{
$categorize = new Category();
$categorize->type = Input::get('type');
$categorize->save();
return Redirect::to('category');
}
示例7: doSave
/**
* Performs the work of inserting or updating the row in the database.
*
* If the object is new, it inserts it; otherwise an update is performed.
* All related objects are also updated in this method.
*
* @param PropelPDO $con
* @return int The number of rows affected by this insert/update and any referring fk objects' save() operations.
* @throws PropelException
* @see save()
*/
protected function doSave(PropelPDO $con)
{
$affectedRows = 0;
// initialize var to track total num of affected rows
if (!$this->alreadyInSave) {
$this->alreadyInSave = true;
// We call the save method on the following object(s) if they
// were passed to this object by their corresponding set
// method. This object relates to these object(s) by a
// foreign key reference.
if ($this->aCategory !== null) {
if ($this->aCategory->isModified() || $this->aCategory->isNew()) {
$affectedRows += $this->aCategory->save($con);
}
$this->setCategory($this->aCategory);
}
if ($this->isNew() || $this->isModified()) {
// persist changes
if ($this->isNew()) {
$this->doInsert($con);
} else {
$this->doUpdate($con);
}
$affectedRows += 1;
$this->resetModified();
}
$this->alreadyInSave = false;
}
return $affectedRows;
}
示例8: create
/**
* Создание категории
*/
public function create()
{
if (!User::isAdmin()) {
App::abort('403');
}
$category = new Category();
if (Request::isMethod('post')) {
$category->token = Request::input('token', true);
$category->parent_id = Request::input('parent_id');
$category->name = Request::input('name');
$category->slug = Request::input('slug');
$category->description = Request::input('description');
$category->sort = Request::input('sort');
if ($category->save()) {
App::setFlash('success', 'Категория успешно создана!');
App::redirect('/category');
} else {
App::setFlash('danger', $category->getErrors());
App::setInput($_POST);
}
}
$maxSort = Category::find(['select' => 'max(sort) max']);
$maxSort = $maxSort->max + 1;
$categories = Category::getAll();
App::view('categories.create', compact('category', 'categories', 'maxSort'));
}
示例9: actionCreate
/**
* Creates a new model.
* If creation is successful, the browser will be redirected to the 'view' page.
*/
public function actionCreate()
{
$model = new Category();
// Uncomment the following line if AJAX validation is needed
// $this->performAjaxValidation($model);
if (isset($_POST['Category'])) {
$model->attributes = $_POST['Category'];
// if (isset($_POST['Category']['id_parent_category']) && $_POST['Category']['id_parent_category'] == '')
// $model->id_parent_category = null;
if ($model->save()) {
$this->redirect(array('view', 'id' => $model->id_category));
}
}
$categories = $this->getCategories();
$select = '<select name="Category[id_parent_category]" id="Category_parent_category">';
$select .= '<option value="">(No Parent Category)</option>';
foreach ($categories as $parent) {
$select .= '<option value="' . $parent['id'] . '">' . ucfirst($parent['data']['name']) . '</option>';
if (isset($parent['children'])) {
$dash = '--';
foreach ($parent['children'] as $children) {
$select .= '<option value="' . $children['data']->id_category . '">' . $dash . ucfirst($children['data']->name) . '</option>';
if (isset($children['children'])) {
$dash = '----';
foreach ($children['children'] as $child) {
$select .= '<option value="' . $child['data']->id_category . '">' . $dash . ucfirst($child['data']->name) . '</option>';
}
}
}
}
}
$select .= '</select>';
$this->render('create', array('model' => $model, 'parent_category' => $select));
}
示例10: store
public function store()
{
$validator = Validator::make(Input::all(), Issue::$rules, Issue::$messages);
//if($validator->passes()){
$issue = new Issue();
$issue->summary = Input::get('summary');
$issue->detail = Input::get('detail');
$issue->budget = 0.0;
$issue->currentState = "TO-DO";
$issue->points = Input::get('points');
$issue->labels = Input::get('labels');
$issue->iterationid = Input::get('iterationid');
$categoryId = Input::get('categoryid');
if ($categoryId == 0) {
//crear categoria
$category = new Category();
$category->name = Input::get('category_name');
$category->save();
$issue->categoryid = $category->id;
} else {
$issue->categoryid = $categoryId;
}
$issue->save();
return Redirect::to('/iterations/' . $issue->iterationid)->with('message', 'Historia creada con exito');
/*}else{
return Redirect::to('iterations/'. Input::get('iterationid'))
->with('error', 'Ocurrieron los siguientes errores')
->withErrors($validator)
->withInput();
}*/
}
示例11: save_website
function save_website($datas)
{
global $templatesList;
load_lib();
//Etape 1 : sauvegarde du site
require_once MODELS . DS . 'website.php';
$websiteModel = new Website();
$templateId = $datas['template_id'];
$template = $templatesList[$templateId];
$datas['tpl_layout'] = $template['layout'];
$datas['tpl_code'] = $template['code'];
$datas['search_engine_position'] = 'header';
$datas['created_by'] = 1;
$datas['modified_by'] = 1;
$datas['online'] = 1;
$websiteModel->save($datas);
define('CURRENT_WEBSITE_ID', $websiteModel->id);
//Etape 2 : sauvegarde du menu racine
require_once MODELS . DS . 'category.php';
$categoryModel = new Category();
unset($categoryModel->searches_params);
////////////////////////////////////////////////////////
// INITIALISATION DE LA CATEGORIE PARENTE DU SITE //
$categorie = array('parent_id' => 0, 'type' => 3, 'name' => 'Racine Site ' . $websiteModel->id, 'slug' => 'racine-site-' . $websiteModel->id, 'online' => 1, 'redirect_category_id' => 0, 'display_contact_form' => 0, 'website_id' => $websiteModel->id);
$categoryModel->save($categorie);
return $websiteModel->id + $categoryModel->id;
}
示例12: doSave
public function doSave($con = null)
{
parent::doSave($con);
if (!$this->getValue('parent')) {
$treeObject = Doctrine_Core::getTable('Category')->getTree();
$roots = $treeObject->fetchRoots();
//If root was deleted, recreate
if (count($roots) == 0) {
$rootCategory = new Category();
$rootCategory->setName("Categories");
$rootCategory->setActive(true);
$rootCategory->save();
$treeObject->createRoot($rootCategory);
$parent = $rootCategory;
} else {
$parent = Doctrine::getTable('Category')->findOneById($roots[0]['id']);
}
if ($this->isNew()) {
$this->getObject()->getNode()->insertAsFirstChildOf($parent);
} else {
$this->getObject()->getNode()->moveAsFirstChildOf($parent);
}
} elseif ($this->getValue('parent')) {
$parent = Doctrine::getTable('Category')->findOneById($this->getValue('parent'));
if ($this->isNew()) {
$this->getObject()->getNode()->insertAsLastChildOf($parent);
} else {
$this->getObject()->getNode()->moveAsLastChildOf($parent);
}
}
}
示例13: add
public function add()
{
if (Request::isMethod('post')) {
$rules = array('title' => 'required|min:4', 'link' => "required|unique:categories", 'meta_keywords' => 'required');
$validator = Validator::make(Input::all(), $rules);
if ($validator->fails()) {
return Redirect::to("admin/category/add")->withErrors($validator)->withInput(Input::except(''));
} else {
$table = new Category();
$table->title = Input::get('title');
$table->link = Input::get('link');
$table->content = Input::get('content');
$table->parent_id = Input::get('parent_id') ? Input::get('parent_id') : null;
$table->meta_title = Input::get('meta_title') ? Input::get('meta_title') : $table->title;
$table->meta_description = Input::get('meta_description') ? Input::get('meta_description') : $table->title;
$table->meta_keywords = Input::get('meta_keywords');
$table->active = Input::get('active', 0);
if ($table->save()) {
$name = trans("name.category");
return Redirect::to("admin/category")->with('success', trans("message.add", ['name' => $name]));
}
return Redirect::to("admin/category")->with('error', trans('message.error'));
}
}
$categories = array(0 => 'Нет родительской категории') + Category::orderBy('title')->lists('title', 'id');
return View::make("admin.shop.category.add", ['categories' => $categories, 'action' => $this->action]);
}
示例14: run
public function run()
{
DB::table('categories')->delete();
$jsonCat = json_decode(file_get_contents(url('/categories.json')));
foreach ($jsonCat as $categoriesParent) {
$cat = new Category();
$cat->title = $categoriesParent->title;
$cat->slug = last(explode('/', $categoriesParent->slug));
$cat->save();
foreach ($categoriesParent->children as $catChild1) {
$cat1 = new Category();
$cat1->title = $catChild1->title;
$cat1->slug = last(explode('/', $catChild1->slug));
$cat1->parent_id = $cat->id;
$cat1->save();
foreach ($catChild1->children as $catChild2) {
$cat2 = new Category();
$cat2->title = $catChild2->title;
$cat2->slug = last(explode('/', $catChild2->slug));
$cat2->parent_id = $cat1->id;
$cat2->save();
}
}
}
}
示例15: doSave
/**
* Performs the work of inserting or updating the row in the database.
*
* If the object is new, it inserts it; otherwise an update is performed.
* All related objects are also updated in this method.
*
* @param PropelPDO $con
* @return int The number of rows affected by this insert/update and any referring fk objects' save() operations.
* @throws PropelException
* @see save()
*/
protected function doSave(PropelPDO $con)
{
$affectedRows = 0;
// initialize var to track total num of affected rows
if (!$this->alreadyInSave) {
$this->alreadyInSave = true;
// We call the save method on the following object(s) if they
// were passed to this object by their coresponding set
// method. This object relates to these object(s) by a
// foreign key reference.
if ($this->aCategory !== null) {
if ($this->aCategory->isModified() || $this->aCategory->isNew()) {
$affectedRows += $this->aCategory->save($con);
}
$this->setCategory($this->aCategory);
}
if ($this->aBook !== null) {
if ($this->aBook->isModified() || $this->aBook->isNew()) {
$affectedRows += $this->aBook->save($con);
}
$this->setBook($this->aBook);
}
if ($this->isNew()) {
$this->modifiedColumns[] = ArticlePeer::ID;
}
// If this object has been modified, then save it to the database.
if ($this->isModified()) {
if ($this->isNew()) {
$pk = ArticlePeer::doInsert($this, $con);
$affectedRows += 1;
// we are assuming that there is only 1 row per doInsert() which
// should always be true here (even though technically
// BasePeer::doInsert() can insert multiple rows).
$this->setId($pk);
//[IMV] update autoincrement primary key
$this->setNew(false);
} else {
$affectedRows += ArticlePeer::doUpdate($this, $con);
}
$this->resetModified();
// [HL] After being saved an object is no longer 'modified'
}
if ($this->collAuthorArticles !== null) {
foreach ($this->collAuthorArticles as $referrerFK) {
if (!$referrerFK->isDeleted()) {
$affectedRows += $referrerFK->save($con);
}
}
}
if ($this->collAttachments !== null) {
foreach ($this->collAttachments as $referrerFK) {
if (!$referrerFK->isDeleted()) {
$affectedRows += $referrerFK->save($con);
}
}
}
$this->alreadyInSave = false;
}
return $affectedRows;
}