First I found that the ability to implement the options in the Click Drop-down box to pass information is required by JavaScript. So I copied the corresponding code to change the address of the jump. Then I found that I could not pass the value of <option value= ' > in the past because of '. ' operator is not used. So again to see the code in the Dede, the original JS to use ' + ' to connect the address. Because the provincial and municipal drop-down boxes all need to use JS, and if I use the same function, it is not good to distinguish between the information I passed, so I used two functions, but if it is the same function, only the last address has a difference, the jump will always be a problem, unable to pass the message normally. So I went to see the code of Dede, found that he has two about the drop-down box jump function, one is passed the ID of one is passed the option value.
Then, is prepared to write a lot and function, because in each function will use the SQL statement, each function I have to do model instantiation, too troublesome, think of in the THINKCMF to upload the image of the code, saw him in all methods before the creation of global variables to instantiate, This eliminates the need to write a lot of repetitive code.
Secondly, in the process of writing, there are some areas to note, for example, when the query statement using where (), usually we want to compare the int type with the int type, but sometimes we need to compare the string, at this time we have to use double quotation marks around the variable to enclose it in quotation marks. And if we just need to find a message, and then use Select (), it returns a two-dimensional array, which you need to be aware of. The Find method returns only one piece of data.
Finally, when displaying the city level, my provincial drop-down box should show what I have chosen, that is, I have selected the provincial level I need to keep, here I use the session.
The code is as follows.
IndexadminController.class.php
<?php
namespace Student\controller;
Use Common\controller\adminbasecontroller;
Class Indexadmincontroller extends adminbasecontroller{
protected $province _model;
protected $city _model;
protected $area _model;
The System action class provides an initialization method for the _initialize interface, which can be used for extension needs, _initialize methods
is executed first before all action method calls
function _initialize () {
Parent::_initialize ();
$this->province_model=d ("common/province");
$this->city_model=d ("common/city");
$this->area_model=d ("Common/area");
}
function index () {
$p = $this->province_model->select ();
$this->assign (' P ', $p);
if ($_get[' P ']) {
$pro =$_get[' P '];
Var_dump ($_server["SERVER_NAME"].$_server["Request_uri"]);//output current full URL
Note that TP's query statement, generated SQL statement, queries the username=admin, this format is less single quotes
$pselect = $this->province_model->where (' province= '. $pro. "'") ->select ();
$this->assign (' ps ', $pselect [0]);
Session (' PS ', $pselect [0]);
$c = $this->city_model->where (' father= '. $pselect [0][' id '])->select ();
$this->assign (' C ', $c);
}
if ($_get[' C ']) {
$father =$_get[' C '];
$cselect = $this->city_model->where (' id= '. $father)->select ();
$this->assign (' CS ', $cselect [0]);
$a = $this->area_model->where (' father= '. $father)->select ();
$this->assign (' A ', $a);
$this->assign (' PS ', session (' ps '));
}
if ($_post) {
$area =$_post[' area ', $city =$_post[' city ', $province =$_post[' province '];
$an = $this->area_model->where (' id= '. $area)->getfield (' area ');
$CN = $this->city_model->where (' id= '. $city)->getfield (' City ');
$PN = $this->province_model->where (' id= '. $province)->getfield (' Province ');
$this->assign (' pn ', $PN);
$this->assign (' cn ', $CN);
$this->assign (' an ', $an);
}
$this->display ();
}
}
Index.html
<admintpl file= "header"/>
<script language= "JavaScript" >
function Changepage (sobj)
{
var ntxt = Sobj.options[sobj.selectedindex].text;
if (sobj.options[sobj.selectedindex].value==0)
{
Location.href= "{: U (' Indexadmin/index ')}";
}
Else
{
var ns = ntxt.split (' | ');
Location.href= "{: U (' Indexadmin/index ')}&p=" +ns[0];
}
}
function ChangePage2 (sobj)
{
var NV = Sobj.options[sobj.selectedindex].value;
if (sobj.options[sobj.selectedindex].value==0)
{
Location.href= "{: U (' Indexadmin/index ')}";
}
Else
{
Location.href= "{: U (' Indexadmin/index ')}&c=" +NV;
}
}
</script>
<body class= "j_scroll_fixed" style= "min-width:800px;" >
<div class= "Wrap J_check_wrap" >
<ul class= "Nav nav-tabs" >
<li class= "Active" ><a href= "{: U (' Indexadmin/index ')}" > Student information </a></li>
</ul>
<form action= "{: U (' Indexadmin/index ')}" method= "POST" >
<table class= "Table Table-hover table-bordered table-list" >
<select name= "province" id= "province" onchange= "Changepage (This)" >
<?php if (! $ps) {?>
<option value= ' 0 ' >--province--</option>
<?php} else {?>
<option value={$ps. id}>{$ps .province}</option>
<?php}?>
<volist name= ' P ' id= ' P ' >
<option value={$p. id}>{$p .province}</option>
</volist>
</select>
<select name= ' city ' id= ' city ' onchange= ' ChangePage2 (this) ' >
<?php if (! $cs) {?>
<option value= ' 0 ' >--city--</option>
<?php} else {?>
<option value={$cs. id}>{$cs .city}</option>
<?php}?>
<volist name= ' C ' id= ' C ' >
<option value={$c. id}>{$c .city}</option>
</volist>
</select>
<select name= "area" id= "Area" >
<option value= ' 0 ' >--District--</option>
<volist name= ' A ' id= ' a ' >
<option value={$a. id}>{$a .area}</option>
</volist>
</select>
<input type= ' Submit ' value= ' submission ' >
</table>
</form>
<?php if ($pn && $cn &&an) {?>
{$PN}-{$cn}-{$an}
<?php}?>
</div>
<script src= "__root__/statics/js/common.js" ></script>
</body>
Effect.
There are a lot of places that are very complex, probably because I use very simple things, so complex, there are many I do not know the very efficient way to look forward to my exploration.
PHP Multi-level linkage learning (II.)