Home  >  Article  >  Backend Development  >  thinkphp怎么在不同的Action类的不同函数之间传值

thinkphp怎么在不同的Action类的不同函数之间传值

WBOY
WBOYOriginal
2016-06-13 10:34:40781browse

thinkphp如何在不同的Action类的不同函数之间传值
我用ThinkPHP做登录页面.
登陆页面提交表单到action="__APP__/Index/login_do" ,然后我在IndexAction类里面写了login_do函数:
public function login_do()
{
if($_SESSION['verify'] != md5($_POST['userauthcode']))
{
$this->error('验证码错误!');
}
  $username=$_POST['username'];
  $password=$_POST['password'];
  $password=md5($password);
   
  $user=M('user');
  $res=$user->where("user_name='$username' && password='$password'")->find();
  if($res)
  {
  redirect('../Home/home',1,"

登录成功!页面正在跳转中...
");
  }
  else
  {
  $this->error('登录失败!');
  }
}




下面是HomeAction类:
class HomeAction extends Action
{
public function home()
{
$this->display();
}
}




....../Tpl/Home/home.html是主页.





现在的问题是:我想在主页上显示用户名,请问要怎样才能把用户名的值传到home.html中显示,望高手指教,给点提示,谢谢!

------解决方案--------------------
做登陆的时候把session 也存起来 然后再home控制器里 用$name=Session :: get ( 'name' ) 得出用户名

然后$this->assign('name',$name);
输出模板 最后在模板页{$name}

速度给分
------解决方案--------------------
按 #1 的描述,在 __URL__/top 对应方法中实现
Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn