我在Controller中有以下目录结构:
Controllers
|__ posts
|__ post.php
views
|__ welcome_message.php
|__ home.php
welcome_message.php
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<title>Welcome to CodeIgniter</title>
</head>
<body>
<a href="<?php echo site_url("posts/post/posts_controller"); ?>">link</a>
</body>
</html>
home.php
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<title>Welcome to CodeIgniter Link Page</title>
</head>
<body>
<div id="container">
<h1>This is the link page</h1>
<div id="body">
<p class="footer">Page rendered in <strong>{elapsed_time}</strong> seconds</p>
</div>
</div>
</body>
</html>
的welcome.php
<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');
class Welcome extends CI_Controller {
public function __construct()
{
parent::__construct();
$this->load->helper('url');
}
public function index()
{
$this->load->view('welcome_message');
}
}
post.php中
<?php
Class Post extends CI_Controller
{
public function __construct()
{
parent::__construct();
$this->load->helper('url');
}
public function posts_controller()
{
$this->load->view('home');
}
}
?>
当我点击welcome_message.php中的链接时,我得到以下网址http://localhost/url_routing/posts/post/posts_controller
,但我想从网址中删除帖子(即文件夹名称),所以我在routes.php文件夹中尝试了$route['posts'] = "post/posts_controller";
但结果是一样的。所以请帮助我解决我的问题,如果可能的话,给我一个小的解释,我已经看到了stackoverflow的其他答案,但不能完全理解。
答案 0 :(得分:0)
$route['post/posts_controller'] = 'posts/post/posts_controller';