Warning: file_get_contents(/data/phpspider/zhask/data//catemap/6/codeigniter/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Function 如何使用codeigniter中的stdclass调用类中的函数_Function_Codeigniter_Class_Object_Stdclass - Fatal编程技术网

Function 如何使用codeigniter中的stdclass调用类中的函数

Function 如何使用codeigniter中的stdclass调用类中的函数,function,codeigniter,class,object,stdclass,Function,Codeigniter,Class,Object,Stdclass,我是CodeIgniter的新手。我有一个关于控制器中函数的问题。控制器中的索引函数如下所示 public function index() { $data = new stdClass; $data->words = "Apple"; $data->shuffled_words = str_shuffle("Apple"); $this-&

我是CodeIgniter的新手。我有一个关于控制器中函数的问题。控制器中的索引函数如下所示

    public function index()
    {
        $data                   = new stdClass;
        $data->words            = "Apple";
        $data->shuffled_words   = str_shuffle("Apple");

        $this->load->view('t/header');
        $this->load->view('projects/game', $data);
        $this->load->view('t/footer');
    }
但我已经在两个函数中编写了索引函数。有点不对劲,没用

        public function index()
        {
            $this->shuffle();
            $this->load->view('t/header');
            $this->load->view('projects/game', $data);
            $this->load->view('t/footer');
        }

        public function shuffle()
        {
             $data                  = new stdClass;
             $data->words           = "Apple";
             $data->shuffled_words  = str_shuffle("Apple");
        }

你能帮我解决这个问题吗?

这是一个快速的解决方案。我希望它能帮助你

    public function index()
    {
        $data = $this->shuffle();
        $this->load->view('t/header');
        $this->load->view('projects/game', $data);
        $this->load->view('t/footer');
    }

    public function shuffle()
    {
         $data                  = new stdClass;
         $data->words           = "Apple";
         $data->shuffled_words  = str_shuffle("Apple");

         return $data;
    }

这是一个快速的解决方案。我希望它能帮助你

    public function index()
    {
        $data = $this->shuffle();
        $this->load->view('t/header');
        $this->load->view('projects/game', $data);
        $this->load->view('t/footer');
    }

    public function shuffle()
    {
         $data                  = new stdClass;
         $data->words           = "Apple";
         $data->shuffled_words  = str_shuffle("Apple");

         return $data;
    }

$data在索引函数中不可用。 这样

 public function index()
    {
        $data=$this->shuffle();//make $data available here
        $this->load->view('t/header');
        $this->load->view('projects/game', $data);
        $this->load->view('t/footer');
    }

    public function shuffle()
    {
         $data                  = new stdClass;
         $data->words           = "Apple";
         $data->shuffled_words  = str_shuffle("Apple");
         return $data;//return the values
    }

$data在索引函数中不可用。 这样

 public function index()
    {
        $data=$this->shuffle();//make $data available here
        $this->load->view('t/header');
        $this->load->view('projects/game', $data);
        $this->load->view('t/footer');
    }

    public function shuffle()
    {
         $data                  = new stdClass;
         $data->words           = "Apple";
         $data->shuffled_words  = str_shuffle("Apple");
         return $data;//return the values
    }

您可以使用$this调用相同的类函数。我猜$data变量有错误?可以使用$this调用相同的类函数。我猜$data变量有错误?