如何在 CodeIgniter 中重定向?
How to redirect in CodeIgniter?
我正在尝试使用以下代码重定向到特定页面:
window.location.href="'<?php echo base_url() ?>'/index.php/user/view_cart/viewCart";
但在 url 中它被发送为
http://localhost/CI/index.php/user/view_available_books/viewAvailableBooks/'%3C?php%20echo%20base_url()%20?%3E%27/index.php/user/view_cart/viewCart
我得到的输出是
The URI you submitted has disallowed characters.
这是我当前的页面:
http://localhost/CI/index.php/user/view_available_books/viewAvailableBooks/
这是它的重定向方式:
http://localhost/CI/index.php/user/view_available_books/viewAvailableBooks/'%3C?php%20echo%20base_url()%20?%3E%27/index.php/user/view_cart/viewCart
它在重定向时也占用了当前页面的url。任何解决方案?
从上面的语句中删除 single quotes
。
<script>window.location.href="<?php echo base_url(); ?>/index.php/user/view_cart/viewCart";</script>
在 Condigniter 中,您可以使用 UrlHelper class 重定向页面。
class MyController extends CI_Controller
{
public function index()
{
}
public function aFunc()
{
$this->load->helper('url');
redirect('/anotherController/action/', 'refresh');
}
JS 文件无法处理 PHP。相反,您可以尝试将 JS 更改为 PHP 文件并尝试这样做:
将您的 js 文件重命名为:
<script src="yourExternalJsFile.js"></script>
收件人:
<script src="yourExternalJsFile.php"></script>
并在您的 php 文件中包含您的脚本,如下所示:
<?php header("Content-type: application/x-javascript");?>
window.location.href="'<?php echo base_url() ?>'/index.php/user/view_cart/viewCart";
您可以在 permitted_uri_chars 添加不允许的字符,这些字符存在于配置文件中。
在配置文件中
$config['permitted_uri_chars'] = 'a-z 0-9~%.:_\-=';
但在您的情况下,您添加的单引号是错误的,您必须删除单引号。
我正在尝试使用以下代码重定向到特定页面:
window.location.href="'<?php echo base_url() ?>'/index.php/user/view_cart/viewCart";
但在 url 中它被发送为
http://localhost/CI/index.php/user/view_available_books/viewAvailableBooks/'%3C?php%20echo%20base_url()%20?%3E%27/index.php/user/view_cart/viewCart
我得到的输出是
The URI you submitted has disallowed characters.
这是我当前的页面:
http://localhost/CI/index.php/user/view_available_books/viewAvailableBooks/
这是它的重定向方式:
http://localhost/CI/index.php/user/view_available_books/viewAvailableBooks/'%3C?php%20echo%20base_url()%20?%3E%27/index.php/user/view_cart/viewCart
它在重定向时也占用了当前页面的url。任何解决方案?
从上面的语句中删除 single quotes
。
<script>window.location.href="<?php echo base_url(); ?>/index.php/user/view_cart/viewCart";</script>
在 Condigniter 中,您可以使用 UrlHelper class 重定向页面。
class MyController extends CI_Controller
{
public function index()
{
}
public function aFunc()
{
$this->load->helper('url');
redirect('/anotherController/action/', 'refresh');
}
JS 文件无法处理 PHP。相反,您可以尝试将 JS 更改为 PHP 文件并尝试这样做:
将您的 js 文件重命名为:
<script src="yourExternalJsFile.js"></script>
收件人:
<script src="yourExternalJsFile.php"></script>
并在您的 php 文件中包含您的脚本,如下所示:
<?php header("Content-type: application/x-javascript");?>
window.location.href="'<?php echo base_url() ?>'/index.php/user/view_cart/viewCart";
您可以在 permitted_uri_chars 添加不允许的字符,这些字符存在于配置文件中。 在配置文件中
$config['permitted_uri_chars'] = 'a-z 0-9~%.:_\-=';
但在您的情况下,您添加的单引号是错误的,您必须删除单引号。