[Help] Pass Parameter In Same Page

hi all, i want to ask about passing parameter.

3416

Untitled.jpg

i have two column, left one is category and the right one which when i click the category it will show the category id in the right one.

my code in login.php

for the list category




foreach($exe as $row)

{

 echo CHtml::link($row['category_name']."(".$row['ttl'].")", '#',

	array('onClick'=>' {'.CHtml::ajax(

	     array(

	           'update'=>'#infra',

                   'data'=>array('ids'=>$row['category_id']),

  		   'type'=>'GET',

		)

             ).' return false; }'

								));

}



<div id="infra">

echo $_GET[‘ids’];

</div>

how can i pass the id to the div?

can anyone help me?

Thanks

Ajax is generally a client server technique. It could help if your intention was to display something as a result of server processing.

In your case you should simply replace that with


 'onClick'=>'$("#infra").html(' . $row['category_id'] . ')'

Or write a general click event binding function for your links…

Thanks bennouna for your replied,sorry i forget to mention, when first time open the web the id infra will show item from all category, until i click the book category it will show all item from book category.

so in my mind i want do like this

in login.php




foreach($exe as $row)

{

   echo CHtml::link($row['category_name']."(".$row['ttl'].")", '#',

	array('onClick'=>' {'.CHtml::ajax(

	     array(

	           'update'=>'#infra',

	           'data'=>array('ids'=>$row['category_id']),

		   'type'=>'GET',

		)

            ).' return false; }'

	));

   echo "<br>";

}


<div id="infra">

if($_GET['ids'] == null) //show item from all category first time

{

	$dataProvider=new CActiveDataProvider('Infrastruktur',array(

		'criteria'=>array(

			'order'=>'urutan asc',

			),

		'pagination'=>array(

		        'pageSize'=>4,

		),

	));

								

	$this->widget('zii.widgets.CListView', array(

		'dataProvider'=>$dataProvider,

		'itemView'=>'//infrastruktur/_view',

		'template'=>'{pager}{items}',

		'pager'=>array(

		    'maxButtonCount'=>'3',

		    'nextPageLabel'=>'>',

		    'prevPageLabel'=>'<',

		    'header'=>'', 

		    'cssFile'=>Yii::app()->baseUrl.'/css/pager.css',

		),

		'summaryText'=>'',

		'emptyText'=>'',

	));

}

else //show item from clicked category

{

	$dataProvider=new CActiveDataProvider('Infrastruktur',array(

		'criteria'=>array(

		    'order'=>'first_update desc',

		    'condition'=>'category_id = '.$_GET['ids'],

		),

		'pagination'=>array(

			'pageSize'=>4,

			//'route'=>'user/login/login',

		),

	));


	$this->widget('zii.widgets.CListView', array(

		'dataProvider'=>$dataProvider,

		'itemView'=>'_view',

		'template'=>'{pager}{items}',

		'pager'=>array(

			'maxButtonCount'=>'3',

			'nextPageLabel'=>'>',

			'prevPageLabel'=>'<',

			'header'=>'',

			'cssFile'=>Yii::app()->baseUrl.'/css/pager.css',

		),

		'summaryText'=>'',

		'emptyText'=>'',

	));

}

</div>



can you give suggestion to do with it?

Thanks

Ok. You can do it in multiple ways. This is one of them:

[list=1]

[*]move the part of the code in your #infra to a partial view.

[*]use a new separate controller action that takes the id as argument to render that partial view.

[*]call that new action in your ajax call passing the clicked id to it

[/list]

Something along these lines (not tested, so I hope you can work out the errors if there are):

[list=1]

[*]your current view becomes


foreach($exe as $row)

{

   echo CHtml::ajaxLink($row['category_name']."(".$row['ttl'].")",

             array('yourController/yourNewMethod'),

             array(

                   'update'=>'#infra',

                   'data'=>array('ids'=>$row['category_id']),

                   'type'=>'GET',

                )

            ).' return false; }'

        ));

   echo "<br>";

}[


<div id="infra">

    <?php $this->renderPartial('_yourPartialView', array('ids' => null)); ?>

</div>

[*]in yourController.php


public function actionYourNewMethod($ids)

{

    if (!Yii::app()->request->isAjaxRequest || ($ids == null)) {

        Yii::app()->end;

    }


    echo $this->renderPartial('_yourPartialView', array('ids' => $ids));

}

[*]_yourPartialView.php


if($ids == null) //show item from all category first time

{

        $dataProvider=new CActiveDataProvider('Infrastruktur',array(

                'criteria'=>array(

                        'order'=>'urutan asc',

                        ),

                'pagination'=>array(

                        'pageSize'=>4,

                ),

        ));

                                                                

        $this->widget('zii.widgets.CListView', array(

                'dataProvider'=>$dataProvider,

                'itemView'=>'//infrastruktur/_view',

                'template'=>'{pager}{items}',

                'pager'=>array(

                    'maxButtonCount'=>'3',

                    'nextPageLabel'=>'>',

                    'prevPageLabel'=>'<',

                    'header'=>'', 

                    'cssFile'=>Yii::app()->baseUrl.'/css/pager.css',

                ),

                'summaryText'=>'',

                'emptyText'=>'',

        ));

}

else //show item from clicked category

{

        $dataProvider=new CActiveDataProvider('Infrastruktur',array(

                'criteria'=>array(

                    'order'=>'first_update desc',

                    'condition'=>'category_id = '.$ids,

                ),

                'pagination'=>array(

                        'pageSize'=>4,

                        //'route'=>'user/login/login',

                ),

        ));


        $this->widget('zii.widgets.CListView', array(

                'dataProvider'=>$dataProvider,

                'itemView'=>'_view',

                'template'=>'{pager}{items}',

                'pager'=>array(

                        'maxButtonCount'=>'3',

                        'nextPageLabel'=>'>',

                        'prevPageLabel'=>'<',

                        'header'=>'',

                        'cssFile'=>Yii::app()->baseUrl.'/css/pager.css',

                ),

                'summaryText'=>'',

                'emptyText'=>'',

        ));

}

[/list]