Action Code:
The Public Function index () {
$prod = I ("get.prod_en");
$id = I ("Get.id", 0, "int");
if ($prod = = "") {
$serviceProduct = array ();//Multiple Loops traversal array
The data is stored in two tables, where the $serviceproduct array is initialized by looping
$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 ());
}
If you want to output variables in a template, you must pass the variable to the template in the controller, and the system provides a assign method to assign values to the template variable
, regardless of the type of variable that uses the Assign assignment 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");}}
Template code:
-
{$sp. Srvname}
-
{$pd. PROD_CN}
-
When using multiple nested loops, you need to specify a key value for each volist, by
Determines whether the last element in the array is the same.