stratusquo
            (Stratosaravias)
          
          
          
              
              
          1
          
         
        
          My noob question…
I have a table with "categories" that are related (indirectly) in a hierarhy by using the ENestedSet extension.
I try to figure out how to create a simple Create Category form where user should
enter the name of category and select a parent category (or no parent if category is a new root)
- I try to use a dropDownList, but my problem is that the implementation of Category has no parent_id field.
 
Parent category is determinated by left,right,level indexes in category table and no parent attribute exists in table,
so i think $form->dropDownList($model,…) is not possible here because my category $model has no parent_id attribute, so how should i make it?
- Drop down list is a limited solution to this, because i can not estimate how many category records will exists
 
in future… so i think i need a modal form, with pagging, but don’t know yet how to do it… 
any sugestions?
thanks in advance…
         
        
          
        
           
           
           
         
         
            
            
          
       
      
        
          
          
            creocoder
            (Creocoder)
          
          
          
              
              
          2
          
         
        
          First. I’m glad that you use my extension. Second. You can use this widget for this:
class CategorySelectWidget extends CInputWidget
{
	public $root;
	public $showRoot=true;
	public $condition='';
	public function run()
	{
		$root=Category::model()->roots()->findByAttributes(array('name'=>$this->root));
		if($root!==null)
		{
			$categories=$root->descendants()->findAll(array('select'=>'id,title,level','condition'=>$this->condition));
			if($this->showRoot)
				$categories=array_merge(array($root),$categories);
			foreach($categories as $category)
				$category->title=str_repeat('—',$this->showRoot ? $category->level-1 : $category->level-2).' '.CHtml::encode($category->title);
			if(!isset($this->htmlOptions['encode']))
				$this->htmlOptions['encode']=false;
			echo CHtml::activeDropDownList($this->model,$this->attribute,CHtml::listData($categories,'id','title'),$this->htmlOptions);
		}
	}
}