《PHP實戰:yii框架搜索分頁modle寫法》要點:
本文介紹了PHP實戰:yii框架搜索分頁modle寫法,希望對您有用。如果有疑問,可以聯系我們。
相關主題:YII框架
控制器層PHP實戰
<?PHP namespace frontend\controllers; header('content-type:text/html;charset=utf-8'); use Yii; use yii\base\InvalidParamException; use yii\web\BadRequestHttpException; use yii\web\Controller; use yii\filters\VerbFilter; use yii\filters\AccessControl; use common\models\LoginForm; use frontend\models\PasswordResetRequestForm; use frontend\models\ResetPasswordForm; use frontend\models\SignupForm; use frontend\models\ContactForm; use frontend\models\Goods; //加載jidian 表的model use yii\data\Pagination; //yii框架中使用分頁 use frontend\web\myclass\QRcode;//加載生成二維碼類 /** * Site controller */ class GoodsController extends Controller { public $enableCsrfValidation = false; //商品展示列表 public function actionGoodslist() { //接收過來搜索的條件 $w=yii::$app->request->get('goods_name'); //分頁 $test=new Goods(); //實例化model模型 $arr=$test->find()->where(['like','goods_name',"$w"]); //加上搜索的條件where $pages = new Pagination([ 'totalCount' => $arr->count(), 'pageSize' => 4 //每頁顯示條數 ]); $models = $arr->offset($pages->offset) ->limit($pages->limit) ->all(); return $this->render('goodslist', [ //前臺的頁面 'data' => $models, 'pages' => $pages, 'where' =>$w //把搜索的條件顯示到前面 ]); } }
視圖層PHP實戰
轉載請注明本頁網址:
http://www.snjht.com/jiaocheng/2279.html