php - 如何在codeigniter中从一个页面重定向到另一个页面
问题描述
我不知道如何做这个 codeignitor 概念。
如果我单击链接,如何将一个页面重定向到另一个页面?
Main1.php
<?php
class Main1 extends CI_Controller {
public function index() {
//Load the URL helper
$this->load->helper('url');
//Redirect the user to some site
redirect('http://localhost/CodeIgniter/index.php/Main');
$this->load->view('test1');
}
}
?>
test1.php
<!DOCTYPE html>
<html>
<head>
<title>view page</title>
</head>
<body style="padding-top:50px; padding-left:300px">
<h1 style="color:red"> Without Extension </h1>
<a href="">Visit With Extension Example</a>
</body>
</html>
主文件
<?php
class Main extends CI_Controller {
public function index() {
$this->load->view('test.html');
}
}
?>
测试.html
<!DOCTYPE html>
<html>
<head>
<title>view page</title>
</head>
<body style="padding-top:50px; padding-left:300px">
<h1 style="color:red"> With Extension </h1>
</body>
</html>
解决方案
你可以使用redirect();
下面给出的东西。
redirect('controllerName/methodName','refresh');
或者,如果您想在同一个控制器中重定向。
$this->methondName;
你的代码应该是这样的
<?php
class Main1 extends CI_Controller {
public function index() {
//Load the URL helper
$this->load->helper('url');
//Redirect the user to some site
redirect('Main/index','refresh');
}
}
?>
推荐阅读
- python - 时间数据不匹配
- dependencies - Prometheus 查询依赖映射,理想情况下显示“源”或类似的?
- reactjs - 使用 React,我的 three.js 相机在单击事件后未定义
- r - 从 R 中的 url 下载 .tif 图像时出错:我只得到一个损坏的小文件
- powershell - Powershell 遍历哈希表的多维数组以查找匹配项并组合两个数组中的值
- sql - 为什么我的 SQL 子查询会出现语法错误?使用计数()
- reactjs - 反应上下文菜单
- django - 在 Django 中动态构建 Q 过滤器,使用 AND 和 OR 运算符?
- python - 无法让 Django-Simple-Captcha 工作,即使使用错误的验证码也会发帖
- linux - 如何使用 Linux 内核启动调试参数