Click MTreeView URL link node to generate CGridView

Hi,

My admin.php view page has two div parts, the left is MTreeView, and the right side is CGridView.

The MTreeView is filled with nodes. I want to make each node to be a link, so everytime i click one node, the right side CGridView will update it’s related database table regarding to the clicked node.

Here is my Controller class php file: "ProjectController.php"


<?php


class ProjectController extends Controller

{

	//$this->layout = false;

	/**

	 * @var string the default layout for the views. Defaults to '//layouts/column2', meaning

	 * using two-column layout. See 'protected/views/layouts/column2.php'.

	 */

	public $layout='//layouts/column2';


	/**

	 * @return array action filters

	 */

	public function filters()

	{

		return array(

			'accessControl', // perform access control for CRUD operations

		);

	}


	/**

	 * Specifies the access control rules.

	 * This method is used by the 'accessControl' filter.

	 * @return array access control rules

	 */

	public function accessRules()

	{

		return array(

			array('allow',  // allow all users to perform 'index' and 'view' actions

				'actions'=>array('index','view','AjaxFillTree','tableDisplay'),

				'users'=>array('*'),

			),

			array('allow', // allow authenticated user to perform 'create' and 'update' actions

				'actions'=>array('create','update'),

				'users'=>array('@'),

			),

			array('allow', // allow admin user to perform 'admin' and 'delete' actions

				'actions'=>array('admin','delete'),

				'users'=>array('admin'),

			),

			//array('deny',  // deny all users

		//		'users'=>array('*'),

		//	),

		);

	}

       /**

	 * Manages all models.

	 */

	public function actionAdmin()

	{

		//$name = Yii::app()->getRequest()->getQuery('name'); 

		//echo "name is ".$name;

		$model=new Project('search');

		$model->unsetAttributes();  // clear any default values

		if(isset($_GET['Project']))

			$model->attributes=$_GET['Project'];


		$count=Yii::app()->db->createCommand('SELECT COUNT(*) FROM tb1')->queryScalar();

		$sql='SELECT * FROM tb1';

		$dataProvider=new CSqlDataProvider($sql, array(

    		'totalItemCount'=>$count,

    		'sort'=>array(

        		'attributes'=>array(

             		'id', 'name', 'description',

       			 ),

    		),

    		'pagination'=>array(

        	'pageSize'=>10,

   		 ),

		));

		$this->render('admin',array('dataProvider' => $dataProvider,'model'=>$model,));

		

	}

}



Here is my view php file: admin.php


<?php

$this->breadcrumbs=array(

	'Projects'=>array('index'),

	'Manage',

);

<div class = 'middle-panel'>

<h2>TreeView</h2>

<?php

$this->widget('application.extensions.MTreeView.MTreeView',array(

        'collapsed'=>true,

        'animated'=>'fast',

        //---MTreeView options from here

        'table'=>'tbl_user_class',//what table the menu would come from

        'hierModel'=>'adjacency',//hierarchy model of the table

        'conditions'=>array('visible=:visible',array(':visible'=>1)),//other conditions if any                                    

        'fields'=>array(//declaration of fields

            'text'=>'title',//no `text` column, use `title` instead

            'alt'=>false,//skip using `alt` column

            'id_parent'=>'id_parent',//no `id_parent` column,use `parent_id` instead

            'task'=>false,

            'icon'=>false,

            'url'=>array('/project/admin',array('text'=>'title'))

			        ),

    ));

 ?>


</div>

<div class = 'right-panel'>

<h2>GridView</h2>

<?php 

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

		'dataProvider'=>$dataProvider,

		)

	);

?>

</div>

when i first click the admin.php link, it shows the tree and grid well. But when tried to click node in the MTreeView, it will pop up error or not display the right thing. How should i pass the node information that i clicked to the actionAdmin function? I am newbie in yii, I had some difficuties to learn and understand the framework. Hope some one could help me. Thank you very much!

Which error do you get?

what exactly do you mean?

I suppose you need to write some js handling for such functionality.

As I got from MTreeView docs (which I don’t use, so can’t be specific about your request), there’re ajaxOptions that will help you.

Also, I suppose it’ll be helpful to search for ‘CGridView ajax’ in docs and forum. Maybe something like this one thread will be helpful. Again I couldn’t be more specific, as you didn’t point out what exactly you need to update in your CGridView.

Anyway, hope it’ll help to find more ideas.