Action code:
- public function index(){
- $prod = I("get.prod_en");
- $id = I("get.id", 0, "int");
- if ($prod == ""){
- $serviceProduct = array();//Array traversed by multiple loops
Copy code
- //The data is saved in two tables, here $serviceProduct is initialized through the loop Array
- $service = M("product_class")->order("oid ASC")->select();
- for ($i = 0; $i < count($service); $i++)
- {
- array_push($serviceProduct, array("srvName"=>$service[$i]["pc_cn"], "product"=>M("product")->where("prod_class_id=".$ service[$i]["pcid"])->order("oid ASC")->select()));
- }
Copy code
- //If you want to use it in the template To output variables, the variables must be passed to the template in the controller. The system provides the assign method to assign values to template variables. Regardless of the variable type, assign assignment is used uniformly.
- $this->assign("serviceProduct", $serviceProduct);
- $this->display();
- }else{
- if ($id > 0){
- $this->display("detail ");
- }else{
- $this->assign('prod_en', $prod);
- $clsList = M("question_class")->order("oid ASC")->select();
- $this->assign('clsList', $clsList);
-
- $qusList = M("question")->order("oid ASC")->select();
- $this-> assign('qusList', $qusList);
- $this->display("list");
- }
- }
- }
-
Copy code Template code:
-
-
- {$sp.srvName}
-
-
- {$pd.prod_cn}
-
-
- |
-
-
-
-
-
-
-
- Specify the key value and use
Copy the code to determine whether it is the last element in the array. -
|