本文整理匯總了PHP中yii\helpers\ArrayHelper::treeTosingle方法的典型用法代碼示例。如果您正苦於以下問題:PHP ArrayHelper::treeTosingle方法的具體用法?PHP ArrayHelper::treeTosingle怎麽用?PHP ArrayHelper::treeTosingle使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類yii\helpers\ArrayHelper
的用法示例。
在下文中一共展示了ArrayHelper::treeTosingle方法的2個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的PHP代碼示例。
示例1: actionIndex
/**
* Lists all Menu models.
* @return mixed
*/
public function actionIndex()
{
$searchModel = new MenuSearch();
$MenuSearch = Yii::$app->request->get('MenuSearch');
if (!$MenuSearch) {
$menuList = Menu::find()->where(['uid' => Yii::$app->user->getId()])->leftJoin('{{%plug}}', '{{%plug}}.id={{%menu}}.type')->select('{{%menu}}.*,{{%plug}}.name as typename,{{%plug}}.controller as controller')->orderBy('sort_order')->asArray()->all();
$menuList = ArrayHelper::createTree($menuList);
$menuList = ArrayHelper::treeTosingle($menuList);
foreach ($menuList as $key => $item) {
if (!empty($item['children'])) {
$menuList[$key]['is_bottom'] = 0;
} else {
$menuList[$key]['is_bottom'] = 1;
}
unset($menuList[$key]['children']);
}
$render = 'index';
} else {
//搜索的時候
$menuList = Menu::find()->where(['uid' => Yii::$app->user->getId()])->leftJoin('{{%plug}}', '{{%plug}}.id={{%menu}}.type')->select('{{%menu}}.*,{{%plug}}.name as typename,{{%plug}}.controller as controller')->orderBy('sort_order')->andFilterWhere(['like', '{{%menu}}.title', $MenuSearch['title']])->andFilterWhere(['{{%menu}}.type' => $MenuSearch['type']])->asArray()->all();
// echo $menuList;die;
$render = 'filter';
}
$model = $menuList;
$dataProvider = new \yii\data\ArrayDataProvider(['allModels' => $model, 'pagination' => ['pageSize' => 200], 'sort' => ['attributes' => ['id desc', 'sort_order asc']]]);
return $this->render($render, ['searchModel' => $searchModel, 'dataProvider' => $dataProvider, 'pluglist' => self::plugList()]);
}
示例2: findlist
public static function findlist()
{
$menuList = Menu::find()->where(['uid' => Yii::$app->user->getId()])->orderBy('sort_order')->select('id,title,parentId,sort_order')->asArray()->all();
$return = array();
$return[0] = '一級菜單';
$menuList = ArrayHelper::createTree($menuList);
$menuList = ArrayHelper::treeTosingle($menuList);
foreach ($menuList as $item) {
$left = '';
for ($i = 1; $i < $item['level']; $i++) {
$left .= ' ';
}
$return[$item['id']] = $left . '└' . $item['title'];
}
return $return;
}