本文整理汇总了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;
}