本文整理匯總了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));
}