TP5.0模板action调用控制器方法或自定义方法

分类首页日期4年前访问5493评论0

在输出模板的时候在前端调用后台自定义方法,使用助手函数action,传送门:https://www.kancloud.cn/manual/thinkphp5/144731

使用方法如下:

//视图调用如下
{:action('api/v1/token/index')}
//类调用如下
action('api/v1/token/index');

全部代码:

<!DOCTYPE html>
<html>
<head>
	<title>登录</title>
</head>
<body>
	<form id="target"  action="" method="get" submit="return false" style="width: 90%;margin:auto;text-align: center;">
		<input type="text" name="account" placeholder="请输入账号/邮箱/用户名">
		<br/>
		<input type="password" name="password" placeholder="请输入密码">
		<br/>
		{:action('api/v1/token/index')}
		<input type="button" id="sub" value="登录">
	</form>
</body>
</html>