How To Handle Cgridview Null Value

5492

img.tiff
Hello alll,

I have a project where i have display gridview with edit delete option but when gridview is display there are also null value will be display in gridview means extra row generates in gridview so i dont know is there any problem in my code or how to handle it

View

<?php $this->widget(‘zii.widgets.grid.CGridView’, array(

'id'=&gt;'category-grid',


'dataProvider'=&gt;&#036;model-&gt;search(),


'filter'=&gt;&#036;model,


'columns'=&gt;array(


	


	array (





        	'name'=&gt;'name',


			//'header'=&gt; 'name' ,


			'type'=&gt;'raw',


			'htmlOptions' =&gt; array('style' =&gt; 'text-align:center;'), 


            'filter' =&gt; false


    	),


	array (


        	'name'=&gt;'Total Images',


			'header'=&gt; 'Total Images' ,


			'type'=&gt;'raw',


			'value'=&gt; array(&#036;model,'totalimages'),


			'htmlOptions' =&gt; array('style' =&gt; 'text-align:center;'), 


            'filter' =&gt; false


    	),


		


	array(


		'class'=&gt;'CButtonColumn',


	),


),

)); ?>

model

public function search()

{





	// Warning: Please modify the following code to remove attributes that


	// should not be searched.


	//&#036;criteria1=new CDbCriteria;


	//&#036;criteria1-&gt;select='c.id,c.user_id,c.name';


	//&#036;criteria1-&gt;alias = 'c';


	//&#036;criteria1-&gt;join='LEFT JOIN user u ON u.id = c.user_id';


	&#036;criteria1-&gt;condition = 'u.email = Yii::app()-&gt;user-&gt;id';


    








	&#036;criteria=new CDbCriteria;


	&#036;criteria-&gt;alias = 'c';


	&#036;criteria-&gt;compare('id',&#036;this-&gt;id);


	&#036;criteria-&gt;compare('name',&#036;this-&gt;name,true);


	&#036;criteria-&gt;compare('is_active',&#036;this-&gt;is_active);


	


	//&#036;criteria-&gt;join='LEFT JOIN user u ON u.id = c.user_id';


	


	&#036;criteria-&gt;addCondition('c.parent_id IS NULL'); 


	//&#036;criteria-&gt;condition = 'u.email = &#092;'' .Yii::app()-&gt;user-&gt;id . '&#092;'';


	&#036;criteria-&gt;condition = 'c.user_id = ' .Yii::app()-&gt;user-&gt;id;


	





	return new CActiveDataProvider(&#036;this, array(


		'criteria'=&gt;&#036;criteria,


		 'sort'=&gt;array(


         'attributes'=&gt;array(


            'c.name'=&gt;array(


                'asc'=&gt;'c.name',


                'desc'=&gt;'c.name DESC',


            ),


            '*',


        ),


    ),


	));


  	}

public function categoryname($data, $row)

{








    &#036;sql=&quot;select id,name from category where parent_id IS NULL AND user_id = &quot;.Yii::app()-&gt;user-&gt;id;


    //print &#036;row;


	&#036;command=Yii::app()-&gt;db-&gt;createCommand(&#036;sql);


	&#036;fetchData = &#036;command-&gt;queryAll();


    


    


    if(count(&#036;fetchData) &gt; 0)


    {





        


    	&#036;cate_all = array();


        





        





    	foreach(&#036;fetchData as &#036;key =&gt; &#036;value)


    	{


            


    		&#036;cate_all[&#036;value['name']] = &#036;value['name'];





	   	} 


    


       	&#036;model=Category::model()-&gt;findAllByAttributes(array('id' =&gt; &#036;data-&gt;id));


    	if(count(&#036;model) &gt; 0)


    	{





    		for(&#036;l=0;&#036;l&lt;count(&#036;model);&#036;l++)


			{ 


    			if(in_array(&#036;model[&#036;l]['name'], &#036;cate_all))


    			{	


    				return CHtml::link(&#036;model[&#036;l]['name'], Yii::app()-&gt;createUrl(&quot;/category/adminsubcategory&amp;id=&quot;.&#036;data-&gt;id.&quot;&quot;),array(&quot;class&quot;=&gt;&quot;classopen1&quot;));


    				


    			}


    		}


    	}	


    }


   //return count(&#036;model);


}

so when i debug the value of the $row get 2 but have record one so from where it passed dont know , so can u please help me here how to handle the extra row in gridview ,

i m new to yii framwork …

Hi,

you have to change the method search () to filter not null values :) thats all

[color="#006400"]NOTE: moved to proper section (From Miscellaneous to General Discussion for Yii 1.1.x)[/color]