In the use of the cascade output of a small problem in a model, I did not pay attention to the model in different ways each time the data is given to the controller, I am in the form of an array of output, but this array I as a private field, to the time when the cascading menu output today, can not output normally, Finally, I have to. This private field is removed, initializing an array in the scope of each method, so that it does not interfere with each other! (It's too little to think about, too whimsical!) )
No, put the code.
HTML section
<select name= "NAV" >
<option> Please select a column category </option>
{$nav}
</select>
/********************************/
PHP Controller Section
<?php
Class Contentaction extends action{
Public function __construct (& $TPL) {
Parent::__construct ($TPL);
}
Public Function action () {
Switch ($_get[' action ']) {
Case ' show ':
$this->show ();
Break
Case ' Add ':
$this->add ();
Break
Case ' Update ':
$this->update ();
Break
Case ' Delete ':
$this->delete ();
Break
Default
Tool::alertback (' Illegal operation! ‘);
Break
}
}
Show
Private Function Show () {
$this->tpl->assign (' show ', true);
$this->tpl->assign (' title ', ' Document List ');
}
Add
Private function Add () {
$this->tpl->assign (' Add ', true);
$this->tpl->assign (' title ', ' New Document ');
Get the cascading drop-down menu
/*
* Use <optgroup></optgroup> group to get the main menu
* Re-content controller in the instantiation of the navigation model
*/
Initialize a variable
$htm = 0;
Instantiate the NAV model class
$nav = new Navmodel ();
foreach ($nav->getallnav () as $object) {//Here loop output main navigation
Outputs the primary navigation Optgroup label in a grouped form
$htm. = ' <optgroup label= "'. $object->nav_name. '" > '. ' \ r \ n "//here to be able to view the source code more clearly, so added \ r \ n
Give the ID of the primary to the private field of the navigation model
$nav->id = $object->id;
The same ID to find the corresponding PID, and to judge
if (!! $childNav = $nav->getallchildnav ()) {
Loop out the array data if it exists and output it with the option tag
foreach ($childNav as $obj) {
$htm. = ' <option value= "'. $obj->id. '" > '. $obj->nav_name. ' </option> '. ' \ r \ n ";
}
}
$htm. = ' </optgroup> ';
}
Registering variables with templates
$this->tpl->assign (' Nav ', $htm);
}
}
Good night!
Learning notes-php simple cascading drop-down menu output-2016.4.7