TP5.1函数调用的总是提示调用未定义的方法

 public function asd_gets(){
        $session_name =  Session::get('name');
        $session_username = Session::get('username');
        return $session_username;
    }

 public function login()
    {
        
        if (request()->isPost()) {
            $name = Request::instance()->post('name');
            $pwd  = Request::instance()->post('pwd');

            $res = Db::table('usertable')->where('user', $name)->find();
            if ($res) {
                if ($res['pwd'] == $pwd && $res['user'] == $name) {
                    //开启session
                    $username = $res['username'];
                    $session_name =  Session::set('name', $name);
                    $session_username = Session::set('username',$username);
                    asd_gets();
                    return $this->success('登录成功', 'http://leisureshop.cn/index.php/index/index/tindex', -1, 2);
                } else {
                    return $this->error('用户或密码错误不存在', "http://leisureshop.cn/index.php/index/login/login", -1, 2);
                }
            } else {
                return $this->error('用户不存在', "http://leisureshop.cn/index.php/index/login/login");
            }
        }
        return $this->fetch();
    }

上面是控制器 index.php
下面是控制器 goods.php

<?php
namespace app\index\controller;

use think\Controller;
use thinK\Db;
use think\Request;


class Goods extends Controller
{
    public function gouwuche()
    {
        $test = Controller('index/Index');
        echo $test->asd_gets();
        return; 
    }
}

然后我在goods.php这个控制器上调用控制器index.php想通过asd_gets()方法把当前登录的session传到goods.php这个控制器上。但是运行到
asd_gets();就报错 调用未定义的函数appindexcontrollersessionu gets()。
请问如果我想调用的asd_gets()应该怎么办。
图片描述

阅读 4.3k
1 个回答
撰写回答
你尚未登录,登录后可以
  • 和开发者交流问题的细节
  • 关注并接收问题和回答的更新提醒
  • 参与内容的编辑和改进,让解决方法与时俱进
推荐问题