php教程|PHP开发Yii2dropdownlist联动php教程-PHP开发旅游网站php源码,下载vscode很慢网址改不了,ubuntu虚拟机桥接,如何启动与停止tomca
php教程|PHP开发
Yii2 dropdownlist 联动
php教程-PHP开发
旅游网站php源码,下载vscode很慢网址改不了,ubuntu虚拟机 桥接,如何启动与停止tomcat,sqlite插入guid,ps网页设计制作,万网服务器绑定域名,dede手机版插件,微前端框架 vue,德国爬虫店,深入理解php,云南seo排名,springboot 单机队列,图片类网站模板,网页高度100,恩斯道模板安装教程,?]后台的网站可以备案吗,织梦嵌入php页面,vba 仓库管理系统,程序员表白源代码lzw
视图部分:
易语言图标提取工具源码,vscode 标签快捷键,ubuntu 编辑软件,360自动关闭tomcat,嘉定爬虫商店,php 全等于,郑州整站seo优化外包,大灌篮h5游戏网站源码,网站模板源码下载后怎么使用lzw
['index'], 'method' => 'get', 'options' => ['class' => 'form-inline'] ]); ?> field($model, 'cityName', ['options' => ['class' => 'form-group col-lg-2']])->dropDownList(ArrayHelper::map($cities, 'id', 'name'), ['prompt' => '请选择城市'])->label('请选择城市', ['class' => 'sr-only']) ?> field($model, 'areaName', ['options' => ['class' => 'form-group col-lg-2']])->dropDownList(ArrayHelper::map($areas, 'id', 'name'), ['prompt' => '请选择区县'])->label('请选择区县', ['class' => 'sr-only']) ?> field($model, 'communityName', ['options' => ['class' => 'form-group col-lg-2']])->dropDownList(ArrayHelper::map($communities, 'id', 'name'), ['prompt' => '请选择小区'])->label('请选择小区', ['class' => 'sr-only']) ?>
'btn btn-primary']) ?>
registerJs(' //市地址改变 $("#itemsearch-cityname").change(function() { //市id值 var cityid = $(this).val(); $("#itemsearch-areaname").html("请选择区县"); $("#itemsearch-communityname").html("请选择小区"); if (cityid > 0) { getArea(cityid); } }); //区地址改变 $("#itemsearch-areaname").change(function() { //区id值 var areaid = $(this).val(); $("#itemsearch-communityname").html("请选择小区"); if (areaid > 0) { getCommunity(areaid); } }); //获取市下面的区列表 function getArea(id) { var href = "' . Url::to(['/service/base/get-area-list'], true). '"; $.ajax({ "type" : "GET", "url" : href, "data" : {id : id}, success : function(d) { $("#itemsearch-areaname").append(d); } }); } //获取区下面的小区列表 function getCommunity(id) { var href = "' . Url::to(['/service/base/get-community-list'], true) . '"; $.ajax({ "type" : "GET", "url" : href, "data" : {id : id}, success : function(d) { $("#itemsearch-communityname").append(d); } }); } //搜索小区 $("#search-community").click(function() { var word = $("#keyword").val(); var areaid = $("#itemsearch-areaname option:selected").val(); var href = "' . Url::to(['/service/base/search-community'], true) . '"; if (areaid > 0) { $.ajax({ "type" : "GET", "url" : href, "data" : {id : areaid, word : word}, success : function(d) { $("#itemsearch-communityname").html(d); } }); } });');?>
模型部分:
仿苏宁源码,试用ubuntu和安装,tomcat8 rc4漏洞,js爬虫实现网页,php中按钮的位置怎么调,乐从seo网站lzw
就是我们常用的ajax请求,当然php中需要直接组合成这样的结构直接用,$form->field($model, $var)中的变量数据表中不一定有,得在模型中自己定义,并设置安全字段,而且搜索模型也可能需要修改成自己需要的样子,模型可能要这样:
class HuangYeError extends \yii\db\ActiveRecord{ public $cityName; public $areaName; public $communityName; public $group; public $cate; /** * @inheritdoc */ public static function tableName() { return 'll_hy_huangye_error'; } public static function getDb() { return Yii::$app->get('dbnhuangye'); }}
之前是多表,需要使用jjoinWith()连表,后来被我全部转化为单表了,多表实在是慢,能转化成单表就用单表吧:
class HuangYeErrorSearch extends HuangYeError{ const PAGE_SIZE = 20; public $communityName; public $startTime; public $endTime; /** * @inheritdoc */ public function rules() { return [ [['id', 'serviceid', 'userid', 'categoryid', 'communityid', 'sortorder', 'ctime', 'utime', 'status'], 'integer'], [['username', 'name', 'logo', 'phone', 'address', 'content', 'error', 'communityName', 'startTime', 'endTime'], 'safe'], ]; } /** * @inheritdoc */ public function scenarios() { // bypass scenarios() implementation in the parent class return Model::scenarios(); } /** * Creates data provider instance with search query applied * * @param array $params * * @return ActiveDataProvider */ public function search($params) { $query = HuangYeError::find(); //status == 9 删除状态 $cOndition= ' `status` != :status'; $p[':status'] = 9; $query->where($condition, $p); $dataProvider = new ActiveDataProvider([ 'query' => $query, 'pagination' => [ 'pageSize' => self::PAGE_SIZE, ], ]); $this->load($params); if (!$this->validate()) { // uncomment the following line if you do not want to any records when validation fails // $query->where('0=1'); return $dataProvider; } $query->andFilterWhere([ 'userid' => $this->userid ]); $query->andFilterWhere(['like', 'username', $this->username]) ->andFilterWhere(['like', 'name', $this->name]) ->andFilterWhere(['like', 'phone', $this->phone]) ->andFilterWhere(['like', 'address', $this->address]) ->andFilterWhere(['like', 'content', $this->content]) ->andFilterWhere(['ll_hy_huangye_error.status' => $this->status]) ->andFilterWhere(['ll_hy_huangye_error.categoryid' => $this->categoryid]) ->andFilterWhere(['between', 'ctime', strtotime($this->startTime . '0:0:0'), strtotime($this->endTime . '23:59:59')]) ->andFilterWhere(['like', 'error', $this->error]); if (intval($this->communityName)) { $query->andFilterWhere(['ll_hy_huangye_error.communityid' => intval($this->communityName)]); } $order = ' `ctime` DESC'; $query->orderBy($order); return $dataProvider; }}
控制器中写比较简单一点,直接调用就行了:
/*** ajax请求小区** @param $id* @return string*/public function actionGetCommunityList($id){ $option = ''; $result = self::getCommunity($id); if ($result) { foreach ($result as $value) { $option .= '' . $value['name'] . ''; } } else { $option .= '暂未开通可选择的小区'; } echo $option;}
更多Yii2使用dropdownlist实现地区三级联动功能的方法相关文章请关注PHP中文网!