《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.vephp.com/jiaocheng/2279.html