Function 如何使用codeigniter中的stdclass调用类中的函数
我是CodeIgniter的新手。我有一个关于控制器中函数的问题。控制器中的索引函数如下所示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-&
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变量有错误?