本文整理汇总了PHP中CategoryModel::add方法的典型用法代码示例。如果您正苦于以下问题:PHP CategoryModel::add方法的具体用法?PHP CategoryModel::add怎么用?PHP CategoryModel::add使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类CategoryModel
的用法示例。
在下文中一共展示了CategoryModel::add方法的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: insert
/**
* 添加分类插入数据库函数
*/
function insert()
{
$category = new CategoryModel();
//如果没有选择单元
if ($_POST['sectionid'] == -1) {
$this->assign('jumpUrl', __URL__ . '/add');
$this->error('请选择正确的单元');
} else {
//如果数据压入成功
if (($data = $category->create()) !== false) {
if ($category->add()) {
$this->assign('jumpUrl', __URL__ . '/index');
$this->success('添加新类别成功');
} else {
$this->assign('jumpUrl', __URL__ . '/index');
$this->error('添加新类别失败' . $category->getDbError());
}
} else {
$this->assign('jumpUrl', __URL__ . '/index');
$this->error('添加失败' . $category->getError());
}
}
}
示例2: add
function add($values)
{
//ak produkt nie je, pridaj
if ($values['Name_sk'] == '') {
return false;
}
//ak je pridany aby ho system nemusel prepisovat
$is_added = false;
if (!isset($this->all_product_param_db[$values['Code']]) and $values['Name_sk'] != '') {
/* [Code] => 21420011
[Name_sk] => Ladies polo shirt, S, white/ blue (01)
[Name_cz] => Dámska poloko?e?a, S, white/ blue (01)
[Name_en] => Ladies polo shirt, S, white/ blue (01)
[Name_de] =>
[Name_hu] =>
[Package] => 1
[Price_CZK] => 124.000000
[Price_EUR] => 4.770000
[Price_SK] => 143.700000
[Image] => p990.02.jpg
[Mark] => Best in Town
[Stock] => 2
[Category1_sk] => Textil
[Category1_cz] => Textil
[Category1_en] => Textile
[Category1_de] =>
[Category1_hu] =>
[Category2_sk] => Výpredaj
[Category2_cz] => Výprodej
[Category2_en] => Discount
[Category2_de] =>
[Category2_hu] =>
[Category3_sk] =>
[Category3_cz] =>
[Category3_en] =>
[Category3_de] =>
[Category3_hu] =>
*/
//zisti ci je v product_temp_parse aby sme zistili group
$product_temp_parse = dibi::fetch("SELECT * FROM product_temp_parse WHERE code = %s", $values['Code']);
if (!$product_temp_parse) {
throw new Exception('Polozka nie je v product_temp_parse. Nemame ako zistit skupinu resp. group_code');
}
//zisti ci group_code je v nasej db ak nie je pridaj
if (!isset($this->all_product_db[$product_temp_parse['group_code']])) {
$arr = array('mark' => $values['Mark'], 'group_code' => $product_temp_parse['group_code']);
$id_product = ProductModel::add($arr);
if (!$id_product) {
throw new Exception('Nastala chyba. Nexistuje id_product');
}
$arr_lang = array('id_product' => $id_product, 'id_lang' => 1, 'name' => $product_temp_parse['groupnameSK'], 'link_rewrite' => NStrings::webalize($product_temp_parse['groupnameSK']));
ProductModel::addProductLang($arr_lang);
$this->all_product_db[$product_temp_parse['group_code']] = $id_product;
$this->all_product_param_db[$values['Code']] = $id_product;
} else {
$id_product = $this->all_product_db[$product_temp_parse['group_code']];
$this->all_product_param_db[$values['Code']] = $id_product;
}
//pridanie parametru produktu
$arr = array('id_product' => $id_product, 'code' => trim($values['Code']), 'capacity' => $values['Package'], 'color' => trim($product_temp_parse['color']), 'size' => trim($product_temp_parse['dimension'] != '' ? $product_temp_parse['dimension'] : $product_temp_parse['size']), 'material' => trim($product_temp_parse['material']), 'price' => $values['Price_EUR'], 'stock' => $values['Stock'], 'image' => $values['Image']);
ProductModel::addProductParamValue($arr);
$is_added = true;
}
$id_product = $this->all_product_param_db[$values['Code']];
/*
* Uprava produktu
*/
if (!$is_added and $values['Name_sk'] != '') {
//upravi len co je v xml - nie co je parsovane z CSV
$arr = array('price' => $values['Price_EUR'], 'stock' => $values['Stock']);
$id_product_param = $this->all_product_param_db[$values['Code']];
ProductModel::setProductParamValue($arr, $id_product_param, 1);
}
$id_categories = array();
//echo $values['Category1_sk'];
if ($id_category = array_search($values['Category1_sk'], $this->category_1)) {
$id_categories[] = $id_category;
}
if ($id_category = array_search($values['Category2_sk'], $this->category_2)) {
$id_categories[] = $id_category;
}
if ($id_category = array_search($values['Category3_sk'], $this->category_3)) {
$id_categories[] = $id_category;
}
ProductModel::removeAllCategory($id_product);
// print_r($id_categories);
ProductModel::addProductToCategory($id_categories, $id_product);
$pom = 0;
//ak nie je kategoria pridaj
if (!in_array($values['Category1_sk'], $this->category_1) and $values['Category1_sk'] != '') {
$id_category = CategoryModel::add(array('id_parent' => NULL, 'active' => 1));
$arr = array('id_category' => $id_category, 'id_lang' => 1, 'name' => $values['Category1_sk']);
CategoryModel::addCategoryLang($arr);
$this->category_1[] = $values['Category1_sk'];
++$pom;
}
if (!in_array($values['Category2_sk'], $this->category_2) and $values['Category2_sk'] != '') {
$cat1 = dibi::fetchSingle("SELECT category.id_category FROM [category] JOIN [category_lang] USING(id_category) WHERE name = %s", $values['Category1_sk'], " AND id_lang = 1 AND id_parent IS NULL");
if (!$cat1) {
throw new Exception('Rodic pre kategoriu neexistuje : ' . $values['Category1_sk']);
//.........这里部分代码省略.........
示例3: zeng
public function zeng() {
$category=new CategoryModel();
$category->add(array(
'name' => '华硕',
'content' => 'good',
'cid' => 2
));
}
示例4: categoryAction
function categoryAction(NForm $form)
{
$values = $form->getValues();
$langs = Setting::getLangs();
switch ($this->mode) {
case 'edit':
$id_category = $values['id_category'];
foreach ($langs as $l) {
$lang_val = array();
foreach ($values as $k => $v) {
if (strpos($k, self::$_separator . $l['iso'])) {
list($name) = explode(self::$_separator . $l['iso'], $k);
$lang_val[$name] = $v;
//pridanie linky rewrite
if ($name == 'link_rewrite' and $v == '') {
$lang_val[$name] = NStrings::webalize($values['name' . self::$_separator . $l['iso']]);
} elseif ($name == 'link_rewrite') {
$lang_val[$name] = NStrings::webalize($lang_val[$name]);
}
// unset($values[$k]);
}
}
$lang_val += array('id_parent' => $values['id_parent'], 'active' => $values['active'], 'show_on_bottom' => $values['show_on_bottom']);
$c = new CategoryModel($l['id_lang']);
$c->save($lang_val, $id_category);
}
$c = new CategoryModel(1);
$c->repairSequence();
// print_r($values);
CategoryModel::repairCategoryRewriteLink();
CategoryModel::invalidateCache();
$this->getPresenter()->flashMessage(_('Kategória bola upravená.'));
$this->getPresenter()->redirect("this");
break;
case 'add':
$id_category = CategoryModel::add(array('id_parent' => $values['id_parent'], 'active' => $values['active']));
unset($values['id_parent'], $values['active']);
foreach ($langs as $l) {
$lang_val = array();
foreach ($values as $k => $v) {
if (strpos($k, self::$_separator . $l['iso'])) {
list($name) = explode(self::$_separator . $l['iso'], $k);
$lang_val[$name] = $v;
//pridanie linky rewrite
if ($name == 'link_rewrite' and $v == '') {
$lang_val[$name] = NStrings::webalize($values['name' . self::$_separator . $l['iso']]);
}
}
}
$lang_val += array('id_category' => $id_category, 'id_lang' => $l['id_lang']);
CategoryModel::addCategoryLang($lang_val);
}
$c = new CategoryModel(1);
$c->repairSequence();
// prepisanie file_node na novy id_category
dibi::query("UPDATE [file_node] SET id_module = %i", $id_category, "WHERE id_module = 999999 AND type_module = 'category'");
CategoryModel::repairCategoryRewriteLink();
CategoryModel::invalidateCache();
// print_r($values);
$this->getPresenter()->flashMessage(_('Kategória bola pridaná.'));
$this->getPresenter()->redirect("Eshop:default");
break;
}
}
示例5: add
static function add($data)
{
if (!$data) {
return false;
}
$model = new CategoryModel();
$result = $model->add($data);
return $result;
}
示例6: exit
<?php
define('ACC', true);
require '../system/init.php';
/***
Controller:
file category.php
作用:接受添加category表单。
调用category model,入库
***/
//print_r($_POST);
//第一步:后台检查数据
if (empty($_POST['cat_name'])) {
exit('category name has to be set');
}
//第二步:接受数据
$data['cat_name'] = $_POST['cat_name'];
$data['dscrpt'] = $_POST['cat_desc'];
$data['parent_id'] = $_POST['parent_id'];
//print_r($data);
//第三步:实例化model,调用方法
$cat = new CategoryModel();
if ($cat->add($data)) {
echo "category added successfully";
} else {
echo "category added unsuccessfully";
}