1
從URL刪除子文件夾目錄中的笨,我有以下目錄結構控制器:能不能使用路由
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>
家。 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
但我想刪除帖子(即文件夾名稱)從URL所以我試圖$route['posts'] = "post/posts_controller";
在routes.php文件夾中,但結果是一樣的。所以請幫我解決我的問題,如果可能的話給我一個小的解釋,我已經看到其他人從stackoverflow的答案,但不能完全理解。
什麼是你的默認基地網址? –
@cos尼克:這是我的基地網址:http:// localhost/url_routing/ – user3653474
如果我是正確的,你想看到這個網址的本地視圖:localhost/url/routing/post/posts_controller? –