thinkPHP's Html template tag usage method

  • 2020-05-26 08:07:23
  • OfStack

Note: in use as < html:select / > Before waiting for tags, you must introduce TP's tag library: < tagLib name="html" / >

If we now need an select drop-down menu item, we can do so in ThinkPHP.

1. Get data in the method of Action controller, as shown below:

 
public function mylist(){ 
$user = new Model( ' User'); 
$list = $user->getField( ' id,username'); 
$this->assign( ' users',$list); 
$this->display(); 
} 


2. Import the tag library in the template page and write the following code

 
<tagLib name="html" /> 
<html:select name="uid" options="users" first=" Please select user " change="alert( ' Hello')"/> 


This allows us to do the following with just one simple tag :(compiled HTML code)

 
<select id="" name="uid" onchange="alert( ' Hello')" ondblclick="" class=""> 
<option value=""> Please select user </option> 
<option value="1 " >no1</option> 
<option value="2 " >no2</option> 
<option value="3 " >no3</option> 
<option value="4 " >no4</option> 
</select> 

Related articles: