从 URL 中删除控制器名称以使子目录 CodeIgniter 的 URL 更清晰。

huangapple go评论107阅读模式
英文:

remove controller name from the url to make url clean in sub directory codeigniter

问题

我已经在子目录中创建了博客,因为我的主目录正在运行一个HTML网站,所以博客系统需要使用我开发的CodeIgniter创建,并添加到名为blogs的文件夹中。现在的问题是,我想要使参数动态化,目前的URL是

domainname.com/blogs/posts/test

我希望它像下面这样

domainname.com/blogs/test

有人可以帮我看看如何实现吗?

我已经创建了如下的路由

$route['posts/(:any)'] = 'blogs/posts/$1';

我的控制器如下

class Blogs extends CI_Controller {
    public function posts($slug = null) {
        echo "hello world";
    }
}
英文:

I have created a blogs inside sub directory because my main directory is running an html website so the blog system needs to be created with codengiter i developed and added inside a folder named blogs now the problem is that i want ot make parameters dynamic right now the url is

domainname.com/blogs/posts/test

I want it to be like give below
domainname.com/blogs/test

can any one help me out how do I do that

I have created route as given below


        `$route['posts/(:any)'] = 'blogs/posts/$1';`


my controller


       `class Blogs extends CI_Controller {
        public function posts($slug = null) {
            echo "hello world";
        }
        }``

答案1

得分: 1

将此代码更改如下,需要接受变量到'Controller blog'并将其传递给函数post

$route['blog/(:any)'] = 'blogs/posts/$1';

英文:

Change this code like this need to accept variable to 'Controller blog' and pass it to the function post

$route['blog/(:any)'] = 'blogs/posts/$1';

huangapple
  • 本文由 发表于 2023年8月11日 01:49:21
  • 转载请务必保留本文链接:https://go.coder-hub.com/76878195.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定