英文:
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';
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论