public function actionIndex($mode)
{
if ($mode == 1)
$this->layout = "//layouts/column2";
else
$this->layout = "//layouts/column1";
$dataProvider=new CActiveDataProvider('Passport');
$this->render('index',array(
'dataProvider'=>$dataProvider,
));
public function actionCreate()
{
$model = new Role;
// Uncomment the following line if AJAX validation is needed
// $this->performAjaxValidation($model);
if (isset($_POST['Role']))
{
$model->attributes = $_POST['Role'];
if ($model->save())
{
if (isset($_POST['im_id']))
{
$command = Yii::app()->db->createCommand();
$maxOrderNumber = Yii::app()->db->createCommand()
->select('max(id) as max')
->from('t_role')
->queryScalar();
$max = $maxOrderNumber ;
foreach ($_POST['im_id'] as $check)
{
$Ids = $_POST['im_id'];
};
for ($i = 0; $i < count($Ids); $i++)
{
$command->insert('t_haspage', array(
'id_role' => $max, ////
'id_page' => (int) $Ids[$i], ////
));
}
}
$this->redirect(array('view', 'id' => $max));
}
}
$this->render('create', array(
'model' => $model,
));
}
$a = Page::model()->findAll();
foreach ($a as $user)
{
$all[$user->p_parent][] = array(id => $user->p_id, text=> $user->p_title, parent_id => $user->p_parent);
}
function RecursiveTree2(&$rs, $parent)
{
$out = array();
if (!isset($rs[$parent]))
{
return $out;
}
foreach ($rs[$parent] as $row)
{
$chidls = RecursiveTree2($rs, $row['id']);
if ($chidls)
{
$row['expanded'] = false;
$row['children'] = $chidls;
}
$out[] = $row;
}
return $out;
}
$this->widget('CTreeView', array('data' => RecursiveTree2($all ,0), 'htmlOptions' => array('class' => 'treeview-red')));
array(7) {
[2]=>
array(2) {
[0]=>
array(3) {
["id"]=>
int(3)
["text"]=>
string(1) "3"
["parent_id"]=>
int(2)
}
[1]=>
array(3) {
["id"]=>
int(8)
["text"]=>
string(5) "22222"
["parent_id"]=>
int(2)
}
}