src/apis/SearchController.php
public function actionIndex($query)
    {
        $search = [];
        $module = Yii::$app->getModule('admin');

        foreach (Yii::$app->adminmenu->getModules() as $node) {
            if (isset($node['searchModelClass']) && !empty($node['searchModelClass'])) {
                $model = Yii::createObject($node['searchModelClass']);
                if (!$model instanceof GenericSearchInterface) {
                    throw new Exception('The model must be an instance of GenericSearchInterface');
                }
                $data = $this->transformGenericSearchToData($model->genericSearch($query));
                if (count($data) > 0) {
                    $stateProvider = $model->genericSearchStateProvider();
                    $search[] = [
                        'hideFields' => $model->genericSearchHiddenFields(),
                        'type' => 'custom',
                        'menuItem' => $node,
                        'data' => $data,
                        'stateProvider' => $stateProvider,
                    ];
                }
                
                unset($data);
            }
        }

        foreach (Yii::$app->adminmenu->getItems() as $api) {
            if ($api['permissionIsApi']) {
                $ctrl = $module->createController($api['permissionApiEndpoint']);
                $controller = $ctrl[0];
                $data = $this->transformGenericSearchToData($controller->model->genericSearch($query));
                if (count($data) > 0) {
                    $search[] = [
                        'hideFields' => $controller->model->genericSearchHiddenFields(),
                        'type' => 'api',
                        'menuItem' => $api,
                        'data' => $data,
                        'stateProvider' => $controller->model->genericSearchStateProvider(),
                    ];
                }
                
                unset($data);
            }
        }

        $searchData = new SearchData();
        $searchData->query = $query;
        $searchData->num_rows = count($search);
        $searchData->save();

        return $search;
    }
public function actionIndex($query)
    {
        $search = [];
        $module = Yii::$app->getModule('admin');

        foreach (Yii::$app->adminmenu->getModules() as $node) {
            if (isset($node['searchModelClass']) && !empty($node['searchModelClass'])) {
                $model = Yii::createObject($node['searchModelClass']);
                if (!$model instanceof GenericSearchInterface) {
                    throw new Exception('The model must be an instance of GenericSearchInterface');
                }
                $data = $this->transformGenericSearchToData($model->genericSearch($query));
                if (count($data) > 0) {
                    $stateProvider = $model->genericSearchStateProvider();
                    $search[] = [
                        'hideFields' => $model->genericSearchHiddenFields(),
                        'type' => 'custom',
                        'menuItem' => $node,
                        'data' => $data,
                        'stateProvider' => $stateProvider,
                    ];
                }
                
                unset($data);
            }
        }

        foreach (Yii::$app->adminmenu->getItems() as $api) {
            if ($api['permissionIsApi']) {
                $ctrl = $module->createController($api['permissionApiEndpoint']);
                $controller = $ctrl[0];
                $data = $this->transformGenericSearchToData($controller->model->genericSearch($query));
                if (count($data) > 0) {
                    $search[] = [
                        'hideFields' => $controller->model->genericSearchHiddenFields(),
                        'type' => 'api',
                        'menuItem' => $api,
                        'data' => $data,
                        'stateProvider' => $controller->model->genericSearchStateProvider(),
                    ];
                }
                
                unset($data);
            }
        }

        $searchData = new SearchData();
        $searchData->query = $query;
        $searchData->num_rows = count($search);
        $searchData->save();

        return $search;
    }
public function actionIndex ( $ query ) { $ search = [ ] ; $ module = Yii :: $ app -> getModule ( 'admin' ) ; foreach ( Yii :: $ app -> adminmenu -> getModules ( ) as $ node ) { if ( isset ( $ node [ 'searchModelClass' ] ) && ! empty ( $ node [ 'searchModelClass' ] ) ) { $ model = Yii :: createObject ( $ node [ 'searchModelClass' ] ) ; if ( ! $ model instanceof GenericSearchInterface ) { throw new Exception ( 'The model must be an instance of GenericSearchInterface' ) ; } $ data = $ this -> transformGenericSearchToData ( $ model -> genericSearch ( $ query ) ) ; if ( count ( $ data ) > 0 ) { $ stateProvider = $ model -> genericSearchStateProvider ( ) ; $ search [ ] = [ 'hideFields' => $ model -> genericSearchHiddenFields ( ) , 'type' => 'custom' , 'menuItem' => $ node , 'data' => $ data , 'stateProvider' => $ stateProvider , ] ; } unset ( $ data ) ; } } foreach ( Yii :: $ app -> adminmenu -> getItems ( ) as $ api ) { if ( $ api [ 'permissionIsApi' ] ) { $ ctrl = $ module -> createController ( $ api [ 'permissionApiEndpoint' ] ) ; $ controller = $ ctrl [ 0 ] ; $ data = $ this -> transformGenericSearchToData ( $ controller -> model -> genericSearch ( $ query ) ) ; if ( count ( $ data ) > 0 ) { $ search [ ] = [ 'hideFields' => $ controller -> model -> genericSearchHiddenFields ( ) , 'type' => 'api' , 'menuItem' => $ api , 'data' => $ data , 'stateProvider' => $ controller -> model -> genericSearchStateProvider ( ) , ] ; } unset ( $ data ) ; } } $ searchData = new SearchData ( ) ; $ searchData -> query = $ query ; $ searchData -> num_rows = count ( $ search ) ; $ searchData -> save ( ) ; return $ search ; }
Administration Global search provider.

This method returns all node items with an search model class or a generic search interface instance and returns its data.

@param string $query The query to search for.
@return array
@throws Exception
Administration Global search provider .