index 控制器
<?php
namespace app\index\controller;
class Index extends \think\Controller
{
public function index()
{
return'学习中...';
}
public function hello($name)
{
if ($name=='thinkphp')
{
$this->success('验证成功,正在跳转...',url('demo/Login/ok'));
}
else{
$this->error('验证失败,正在返回登陆页面...','http://www.php.cn');
}
}
}demo/Login/
<?php
namespace app\demo\controller;
class Login extends \think\Controller
{
public function ok()
{
return '欢迎使用后台登陆系统...';
}
public function login()
{
return '登陆页面...';
}
}--------------------------------------------------------------------------------------------------------------------------------
重定向
<?php
namespace app\index\controller;
class Index extends \think\Controller
{
public function index()
{
return'学习中...';
}
public function hello($name)
{
if ($name=='thinkphp')
{
//redirect(路由地址,请求变量,后缀,是否显示域名)
$this->redirect('ok',['siteName'=>'php中文网']);
}
else{
$this->redirect('http://www.php.cn',302);
}
}
public function ok()
{
return '欲穷千里目,更上一层楼';
}
}
Copyright 2014-2025 https://www.php.cn/ All Rights Reserved | php.cn | 湘ICP备2023035733号