这里是我们的控制器的命名空间
<?php
namespace app\controllers;
use Yii;
use app\models\Post;
use app\models\News;
use app\models\newtype;
use yii\web\Controller;
use yii\web\NotFoundHttpException;
use yii\db\Query;
use yii\data\Pagination;
class XinwenController extends Controller
{
这里是搜索方法
public function actionSearchs()
{
$request = Yii::$app->request;
$search=$request->get('search');
// var_dump($search);
if ($search){
$comm= news::find()
->select("*")
->innerjoin('newtype','newtype.tid=news.tid');
$pages = new Pagination(['totalCount' => $comm->count(),'pageSize'=>4]);
$models = $comm->offset($pages->offset)
->Where(['like', 'content', $search])
->limit($pages->limit)
->asArray()
->all();
// var_dump($models);
return $this->render('searchs',[
'models'=> $models,
'pages' => $pages
]);
}
}
我们使用jquery搜索在form表单页面使用的写法参考吧大神们,一定会报错
$(function(){
$(".bt").click(
function () {
var search=$('#search').val();
// alert(search);
$.ajax({
type: "get",
url: "?r=xinwen/searchs",
data: "search="+search,
success: function(msg){
$("#div").html(msg);
}
});
}
)
})
我们这里可以给整个摸板加div盒子置换
忘了告诉大神yii框架form表单写法
<?php
use yii\widgets\LinkPager;
use yii\helpers\Html;
?>
分页小部件
<?php
echo LinkPager::widget([
'pagination' => $pages,
]);
?>