echo $form->labelEx($model, 'name'); ?> <?php echo $form->textField($model, 'name', array('size' => 60, 'maxlength' => 256)); ?> <?php echo $form->error($model, 'name'); ?> </div> <div class="row"> <?php echo $form->labelEx($model, 'parent_id'); ?> <?php echo $form->dropDownList($model, 'parent_id', CHtml::listData(ProductFolder::model()->findAll(array('condition' => "company_id=:company_id", 'params' => array(':company_id' => Yii::app()->session['user']->company_id), 'order' => 'id, parent_id')), 'id', 'cascadeFolderNameRec'), array('class' => 'span4', 'encode' => false)); ?> <?php /*echo $form->textField($model,'parent_id'); */ ?> <?php echo $form->error($model, 'parent_id'); ?> </div> <div class="row buttons"> <?php echo CHtml::submitButton($model->isNewRecord ? 'Create' : 'Save'); ?> </div>
<?php /* @var $this ProductFolderController */ /* @var $dataProvider CActiveDataProvider */ $this->breadcrumbs = array('Product Folders'); $this->menu = array(array('label' => 'Create ProductFolder', 'url' => array('create')), array('label' => 'Manage ProductFolder', 'url' => array('admin'))); ?> <h1>Product Folders</h1> <?php $this->widget('ext.ztree.zTree', array('treeNodeNameKey' => 'name', 'treeNodeKey' => 'id', 'treeNodeParentKey' => 'parent_id', 'options' => array('expandSpeed' => "", 'showLine' => true), 'model' => "ProductFolder", 'data' => ProductFolder::model()->getAllFolders())); ?> <?php $this->widget('zii.widgets.CListView', array('dataProvider' => $dataProvider, 'itemView' => '_view'));
/** * Returns the data model based on the primary key given in the GET variable. * If the data model is not found, an HTTP exception will be raised. * @param integer $id the ID of the model to be loaded * @return ProductFolder the loaded model * @throws CHttpException */ public function loadModel($id) { $model = ProductFolder::model()->findByPk($id, "company_id=:company_id", array(':company_id' => Yii::app()->session['user']->company_id)); if ($model === null) { throw new CHttpException(404, 'The requested page does not exist.'); } return $model; }
/** * @return array get all folders */ public function getAllFolders() { $folders = ProductFolder::model()->find("company_id=:company_id", array(':company_id' => Yii::app()->session['user']->company_id)); $result = array(); if (!empty($folders)) { foreach ($folders as $folder) { $result[$folder->id] = array('id' => $folder->id, 'name' => $folder->name, 'parent_id' => $folder->parent_id); } } return $result; }