本文整理汇总了PHP中Category::appendTo方法的典型用法代码示例。如果您正苦于以下问题:PHP Category::appendTo方法的具体用法?PHP Category::appendTo怎么用?PHP Category::appendTo使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Category
的用法示例。
在下文中一共展示了Category::appendTo方法的9个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: actionEdit
public function actionEdit($id)
{
//var_dump($_POST);
if ($_POST && $id) {
if ($_POST['nest-act'] == 'create-parent' && $_POST['name_cat'] !== '') {
//echo '<script>alert("111")</script>';
$node = Category::model()->findByPk($id);
$category = new Category();
$category->name = CHtml::encode($_POST['name_cat']);
$category->appendTo($node);
//$this->actionIndex();
}
if ($_POST['nest-act'] == 'delete' && $id !== '11') {
$node = Category::model()->findByPk($id);
$node->deleteNode();
}
if ($_POST['nest-act'] == 'rename') {
$node = Category::model()->findByPk($id);
$node->name = CHtml::encode($_POST['name_cat']);
$node->saveNode();
}
header('Location: /category');
die;
}
$param = Category::model()->findByPk($id);
$this->render('edit', ['model' => $param]);
}
示例2: actionCreate
public function actionCreate()
{
$err = true;
$this->breadcrumbs = array('Теги' => array('index'), 'Создать');
$model = new Category();
if (isset($_POST['Category'])) {
$model->attributes = $_POST['Category'];
if ($model->validate()) {
if (!empty($model->parent_id)) {
$parent = $this->loadModel($model->parent_id);
if ($model->appendTo($parent)) {
$model->refresh();
$err = false;
}
} else {
if ($model->saveNode()) {
$err = false;
}
}
if ($err) {
$this->addFlashMessage($model->errors, 'error');
} else {
$this->redirect(Yii::app()->createAbsoluteUrl('/admin/tags'));
}
} else {
$this->addFlashMessage($model->errors, 'error');
}
}
$this->render('_form', array('model' => $model));
}
示例3: addCategory
public static function addCategory($appendTo, $data = array())
{
try {
$node = new Category($data);
$node->appendTo($appendTo)->save();
} catch (Exception $e) {
echo $e->getMessage();
}
}
示例4: actionCreate
/**
* Creates a new model.
* If creation is successful, the browser will be redirected to the 'view' page.
*/
public function actionCreate()
{
$model = new Category();
//$model->enableBehavior('tree');
// Uncomment the following line if AJAX validation is needed
// $this->performAjaxValidation($model);
if (isset($_POST['Category'])) {
$model->attributes = $_POST['Category'];
if (!empty($_POST['Category']['parent_id'])) {
$root = Category::model()->findByPk($_POST['Category']['parent_id']);
$model->appendTo($root);
} else {
$model->saveNode();
}
$this->redirect(array('view', 'id' => $model->id));
}
$this->render('create', array('model' => $model));
}
示例5: actionCreate
/**
* Creates a new model.
* If creation is successful, the browser will be redirected to the 'view' page.
*/
public function actionCreate()
{
$model = new Category('create');
$action = 'category';
// Uncomment the following line if AJAX validation is needed
// $this->performAjaxValidation($model);
if (isset($_POST['Category'])) {
$model->attributes = $_POST['Category'];
$parent_node = $_POST['Category']['node'];
if ($parent_node != 0) {
$node = Category::model()->findByPk($parent_node);
$model->appendTo($node);
// print_r($_POST['DealCategory']);
// exit;
}
// file handling
$imageUploadFile = CUploadedFile::getInstance($model, 'pic');
if ($imageUploadFile !== null) {
// only do if file is really uploaded
$imageFileExt = $imageUploadFile->extensionName;
$save_path = dirname(Yii::app()->basePath) . '/upload/' . $action . '/';
if (!file_exists($save_path)) {
mkdir($save_path, 0777, true);
}
$ymd = date("Ymd");
$save_path .= $ymd . '/';
if (!file_exists($save_path)) {
mkdir($save_path, 0777, true);
}
$img_prefix = date("YmdHis") . '_' . rand(10000, 99999);
$imageFileName = $img_prefix . '.' . $imageFileExt;
$model->pic = $ymd . '/' . $imageFileName;
$save_path .= $imageFileName;
}
if ($model->saveNode()) {
if ($imageUploadFile !== null) {
// validate to save file
$imageUploadFile->saveAs($save_path);
}
$this->redirect(array('admin'));
}
}
$this->render('create', array('model' => $model));
}
示例6: actionCreate
/**
* Creates a new model.
* If creation is successful, the browser will be redirected to the 'view' page.
*/
public function actionCreate()
{
$model = new Category('create');
$action = 'category';
if (isset($_POST['Category'])) {
//Uncomment the following line if AJAX validation is needed
// $this->performAjaxValidation($model);
$model->attributes = $_POST['Category'];
$parent_node = $_POST['Category']['node'];
if ($parent_node != 0) {
$node = Category::model()->findByPk($parent_node);
$model->appendTo($node);
}
if ($model->saveNode()) {
$this->redirect(array('admin'));
}
}
$this->render('create', array('model' => $model));
}
示例7: actionCreate
public function actionCreate() {
$err = true;
$model = new Category();
if (isset($_POST['Category'])) {
$model->attributes = $_POST['Category'];
if ($model->validate()) {
if (!empty($model->parent_id)) {
$parent = $this->loadModel($model->parent_id);
if ($model->appendTo($parent)) {
$model->refresh();
$err = false;
}
} else {
if($model->saveNode() && $model->storeTypeAttributes(Yii::app()->getRequest()->getPost('attributes', []))){
$err = false;
}
}
if ($err) {
$this->addFlashMessage($model->errors,'error');
} else {
$this->redirect(Yii::app()->createAbsoluteUrl('catalog/admin/default'));
}
} else {
$this->addFlashMessage($model->errors,'error');
}
}
$this->render('_form', array('model' => $model));
}
示例8: testFailsToSaveNodeUntilParentIsSaved
/**
* @expectedException Exception
*/
public function testFailsToSaveNodeUntilParentIsSaved()
{
$node = new Category(array('title' => 'Node'));
$parent = new Category(array('title' => 'Parent'));
$node->appendTo($parent)->save();
}
示例9: actionCreate
public function actionCreate()
{
$lang = $this->getLanguageCode();
$listCategory = CategoryLanguage::model()->getListCategoryWithLanguage($lang);
$listLanguage = Language::model()->listLanguage();
$model = new Category();
$modelCateLang = new CategoryLanguage();
$attributeInTab = '';
if (Yii::app()->request->getPost('Category') && Yii::app()->request->getPost('CategoryLanguage')) {
$catePost = Yii::app()->request->getPost('Category');
$model->attributes = $catePost;
$postCategoryLanguage = $_POST['CategoryLanguage'];
$this->validateCategoryLanguage($listLanguage, $postCategoryLanguage, $modelCateLang, $errorMessage, $attributeInTab);
if (empty($postCategoryLanguage)) {
Yii::app()->user->setFlash('error', Yii::t('category', 'Name, Description cannot be blank.'));
}
if (($errorString = $this->convertErrorMessageToString($errorMessage)) !== FALSE) {
Yii::app()->user->setFlash('error', $errorString);
}
if ($model->validate() && empty($errorMessage) && !empty($postCategoryLanguage)) {
$model->attributes = Yii::app()->request->getPost('Category');
$model->created_by = Yii::app()->user->id;
$parent = Category::model()->findByPk($model->parent_id);
$firstLanguage = reset($postCategoryLanguage);
$cateUrl = Yii::app()->extraFunctions->getBreadscumFromCategoryID($parent->id);
$catePost['params']['cateUrl'] = $cateUrl . '/' . Yii::app()->extraFunctions->setRemoveFontVi_urlTitle($firstLanguage['name']);
$model->params = CJSON::encode($catePost['params']);
$transaction = Yii::app()->db->beginTransaction();
try {
if ($model->appendTo($parent)) {
foreach ($postCategoryLanguage as $index => $attribute) {
$modelCateLang = new CategoryLanguage('create');
$modelCateLang->category_id = $model->id;
$modelCateLang->language_id = $attribute['language_id'];
$modelCateLang->name = $attribute['name'];
$modelCateLang->description = $attribute['description'];
if (!$modelCateLang->save()) {
Yii::app()->user->setFlash('error', Yii::t('category', 'Add category language failed. Please try it later.'));
$transaction->rollback();
}
}
$transaction->commit();
Yii::app()->user->setFlash('success', Yii::t('category', 'Add category successfully.'));
$this->redirect(array('/' . backend . '/category/admin'));
}
$cateUrl = Yii::app()->extraFunctions->getBreadscumFromCategoryID($model->id);
$catePost['params']['cateUrl'] = $cateUrl;
$model->params = CJSON::encode($catePost['params']);
$model->save();
} catch (Exception $ex) {
$transaction->rollback();
Yii::app()->user->setFlash('error', Yii::t('category', 'Fails.'));
Yii::app()->user->setFlash('message', Yii::t('category', 'Create category fails.'));
$this->redirect(array('/' . backend . '/category/admin'));
}
}
}
$this->render('create', array('model' => $model, 'modelCateLang' => $modelCateLang, 'listCategory' => $listCategory, 'listLanguage' => $listLanguage, 'attributeInTab' => $attributeInTab));
}