当前位置: 首页>>代码示例>>PHP>>正文


PHP ProductCategory::saveNode方法代码示例

本文整理汇总了PHP中ProductCategory::saveNode方法的典型用法代码示例。如果您正苦于以下问题:PHP ProductCategory::saveNode方法的具体用法?PHP ProductCategory::saveNode怎么用?PHP ProductCategory::saveNode使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在ProductCategory的用法示例。


在下文中一共展示了ProductCategory::saveNode方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。

示例1: actionCreate

 /**
  * Creates a new model.
  * If creation is successful, the browser will be redirected to the 'view' page.
  */
 public function actionCreate()
 {
     $this->__baseScriptUrl = Yii::app()->assetManager->publish(dirname(__FILE__) . '/../assets');
     Yii::app()->getClientScript()->registerCssFile($this->__baseScriptUrl . '/products.css');
     $model = new ProductCategory();
     // Uncomment the following line if AJAX validation is needed
     // $this->performAjaxValidation($model);
     $treeRoots = ProductCategory::model()->roots()->findAll();
     if (empty($treeRoots)) {
         $root = new ProductCategory();
         $root->name = 'Root';
         $root->saveNode();
     }
     if (isset($_POST['ProductCategory'])) {
         $model->attributes = $_POST['ProductCategory'];
         if ($model->parent_id == 'root') {
             $model->parent_id = null;
         } else {
             $model->parent_id = $_POST['ProductCategory']['parent_id'];
         }
         $fileUpload = CUploadedFile::getInstance($model, 'image');
         if (isset($fileUpload) && $model->validate()) {
             $uploadPath = YiiBase::getPathOfAlias('webroot') . '/files/products/';
             //Yii::app()->basePath . '/../jlwebroot/upload';
             if (!is_dir($uploadPath)) {
                 @mkdir($uploadPath);
                 @chmod($uploadPath, 0777);
             }
             $filename = time() . mt_rand(0, 0xfff) . '.' . $fileUpload->getExtensionName();
             $fileUpload->saveAs($uploadPath . '/' . $filename);
             /**
              * @todo chưa có setting cho thumbnail                 
              * */
             // thumbnails image
             $thumbsPath = $uploadPath;
             Yii::import('ext.phpthumb.EasyPhpThumb');
             $thumbs = new EasyPhpThumb();
             $thumbs->init();
             $thumbs->setThumbsDirectory($thumbsPath);
             $thumbs->load($uploadPath . '/' . $filename)->resize(80, 60)->save('thumb_' . $filename);
             $model->image = $filename;
         }
         $model->created = date('Y-m-d H:i:s', time());
         $model->modified = date('Y-m-d H:i:s', time());
         if ($model->parent_id == 'root') {
             if ($model->validate()) {
                 $model->saveNode();
                 $this->redirect(array('admin'));
             }
         } else {
             if ($model->validate()) {
                 $root = ProductCategory::model()->findByAttributes(array('id' => $model->parent_id));
                 $model->appendTo($root);
                 $this->redirect(array('admin'));
             }
         }
     }
     $arrTrees = ProductCategory::model()->roots()->findAll();
     $this->render('form', array('model' => $model, 'arrTrees' => $arrTrees));
 }
开发者ID:qkongvan,项目名称:k6-thuc-pham,代码行数:64,代码来源:Manage_categoriesController.php


注:本文中的ProductCategory::saveNode方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。