Foreground data back station value, often is the novice most headache, recently in the study thinkphp time, also encountered this kind of problem, summarizes, go to insufficient place please everybody to advise.
First, the front-page interface code, back to the value of two ways, one is get, the other is post, beginners, no matter what the way it is, the value of success in the next station can be.
First, write a from form,
<form Action= "{: U (Recom/goodsprice)}" method= "post" >
<a href= "{: U (' Recom/goodsprice ', array(' price ' =' + ')}" > Prices greater than 700</a>// In this case, let's introduce the value of hyperlinks.
</form>
This price is passed to the backstage, after passing, but also to accept the value to pass, see step Two,
Second, the background of the control layer code is as follows:
Public Function Goodsprice () {
$price = I (' price ');//This will get the value of the price of the foreground pass.
Print_r ("Price:". $price. " ");//Check the success of the pass value, need to run after the source code to open the foreground whether there is this value
$model = D (' Goods ');//Select a table in the database, for example, call Goods watch.
$res = $model->selectprice ($price);//key moment, call the Selectprice function of the model layer, take $price this parameter to pass
$this->assign (' res ', $res ["date"]);//Get data, named Res
$this->assign (' page ', $res ["page"]), a paging method that comes with//thinkphp, is simple, but needs to be configured in the model layer and explained below.
$this->display ();//This is the display interface
}
Third, the code of the model layer is as follows:
Public Function Selectprice ($price) {
$this->db (1, "DB_CONFIG1")->db (1);//Select Database
$map [' price '] = Array (' GT ', $price); Defining query criteria
$count = $this->db (1, "DB_CONFIG1")->where ($map)->count ();//statistic Bar number
$page = new \think\page ($count, 10);//pagination processing
$show = $page->show ();
$limit = $page->show ();
$limit = $page->firstrow. ",". $page->listrows;
$goodsprice = $this->db (1, "DB_CONFIG1")->limit ($limit)->where ($map)->select ();//sql statement
Print_r ($this->getlastsql ());//debug dedicated, output last SQL statement
$res ["date"] = $goodsprice;
$res ["page"] = $show;
return $res;
}
The specific code and procedure is so simple, do you have any help?
PHP Background Pass Value