difficult data retriving

let me explain my problem, hope you get an idea of what it is.

I have a web service which hide from public access, and have designed a secure way of mysql sql querying using to the service across the websites. so i dont think i can really use the current model layer of Yii2, and that also means i hardly can use cActivedata as no database present.

Currently what i do is to write raw sqls and get all the results and then feed into dataprovider using ArrayDataProvider.

e.g.




        $sql="select * from a_table";

        $result=$remote->select($sql);


        $dataProvider = new ArrayDataProvider([

            'allModels' => $result,

            'sort' => [

                'attributes' => ['date', 'name'],

            ],

            'pagination' => [

                'pageSize' => 10,

            ],

        ]);


        return $this->render('index', [

            'dataProvider' => $dataProvider,

        ]);

that pose a problem, everytime i need to query the full table. This is not idea if the table is very large. It is better to query in the size of 10 something, however if i do


        $sql="select * from a_table LIMIT 10";

no pagination will appear in my case…How do i solve this problem? And if this is not an idea way to talk to external data services, what is ur suggestion?