1.thinkphp模型搜索器
模型代码
public function select_query(){
$data = user::withSearch(['name'], [
'name' => '子',
])
->select();
return $data;
}
//使用模型搜索器调用
public function searchNameAttr($query, $value)
{
$query->where('name','like','%'. $value . '%');
}
控制器代码
public function select_q(){
$user = new user();
return $user->select_query();
}
演示效果
2.thinkphp门面类
演示效果
代码如下
public function index()
{
//
echo '<table width="600" height="400" align="center">';
echo " <caption>使用Env门面类来获取数据库信息</caption>
<tbody>";
echo " <tr style='border: 1px solid blue; padding: 5px; background: yellow;text-align: center;'>
<td style='border: 0px solid'>type</td>
<td style='border: 0px solid'>".Env::get('database.type')."</td>
</tr>";
echo " <tr style='border: 1px solid blue; padding: 5px; background: yellow;text-align: center;'>
<td style='border: 0px solid'>hostname</td>
<td style='border: 0px solid'>".Env::get('database.hostname')."</td>
</tr>";
echo " <tr style='border: 1px solid blue; padding: 5px; background: yellow;text-align: center;'>
<td style='border: 0px solid'>database</td>
<td style='border: 0px solid'>".Env::get('database.database')."</td>
</tr>";
echo " <tr style='border: 1px solid blue; padding: 5px; background: yellow;text-align: center;'>
<td style='border: 0px solid'>username</td>
<td style='border: 0px solid'>".Env::get('database.username')."</td>
</tr>";
echo " <tr style='border: 1px solid blue; padding: 5px; background: yellow;text-align: center;'>
<td style='border: 0px solid'>password</td>
<td style='border: 0px solid'>".Env::get('database.password')."</td>
</tr>";
echo " <tr style='border: 1px solid blue; padding: 5px; background: yellow;text-align: center;'>
<td style='border: 0px solid'>hostport</td>
<td style='border: 0px solid'>".Env::get('database.hostport')."</td>
</tr>";
echo " <tr style='border: 1px solid blue; padding: 5px; background: yellow;text-align: center;'>
<td style='border: 0px solid'>charset</td>
<td style='border: 0px solid'>".Env::get('database.charset')."</td>
</tr>";
echo "</tbody></table>";
}
演示效果
3.thinkphp多应用
使用composer 安装多应用
composer require topthink/think-multi-app
演示效果
安装
应用
4.thinkphp调试
演示效果
5.thinkphp 使用config助手函
代码
public function get_one(){
echo '<table width=600 height=400 align="center" >';
echo"<caption>使用config助手函数来获取数据库信息</caption>";
foreach (array_filter(config()['database']['connections']['mysql']) as$k => $v){
echo '<tr style="border: 1px solid blue; padding: 5px; background: yellow;text-align: center;">';
if($k ==='master_num' ) { break;}
echo '<td style="border: 0px solid ">'.$k.'</td>'.'<td style="border: 0px solid ">'.$v.'</td>';
echo '</tr>';
}
echo "</table>";
}
演示效果