Php 如何在CodeIgniter中调用另一个控制器中的函数?
我想调用另一个控制器中的函数。例如,如果用户尝试使用不正确的参数登录,则应用程序将重定向到另一个控制器并传递变量(数组) 是否可以在url帮助器中使用redirect()函数传递变量?是的,您可以使用redirect('othercontroller/function/'。url_encode($data),'location') 这应该行得通Php 如何在CodeIgniter中调用另一个控制器中的函数?,php,codeigniter,Php,Codeigniter,我想调用另一个控制器中的函数。例如,如果用户尝试使用不正确的参数登录,则应用程序将重定向到另一个控制器并传递变量(数组) 是否可以在url帮助器中使用redirect()函数传递变量?是的,您可以使用redirect('othercontroller/function/'。url_encode($data),'location') 这应该行得通 编辑:您还可以将代码放入帮助器中 如果要从另一个控制器调用一个控制器的函数,则可以使用重定向帮助器 <?php $array = arra
编辑:您还可以将代码放入帮助器中
如果要从另一个控制器调用一个控制器的函数,则可以使用重定向帮助器
<?php
$array = array('foo'=>'bar', 'baz'=>'fubar', 'bar' => 'fuzz');
$json = json_encode($array);
$encoded_json= urlencode($json);
/* now pass this variable to your URL redirect)
/* on your receiving page:*/
$decoded_json= urldecode($encoded_json);
/* convert JSON string to an array and output it */
print_r(json_decode($decoded_json, true));
?>
例如:
class Logout extends CI_Controller {
function index() {
session_destroy();
redirect('index.php/home/', 'refresh');
}
}
它将调用另一个控件。如果$data是数组,是否可能?urlencode
(无下划线)需要一个字符串,因此数组不起作用。关于可能的解决方案,请参见我的答案贪婪:对于数组,JSON和urlencoding绝对是最佳选择。好的。。我试试看。。谢谢http url的长度有限制吗?
class Logout extends CI_Controller {
function index() {
session_destroy();
redirect('index.php/home/', 'refresh');
}
}