Welcome Guest, Not a member yet? Register   Sign In
Routing to specific controller in case controller/method is not found.
#5

Thank you for your interest @mwhitney.

Let me be more specific on the issue.

Let's say,

i'm showing list of blog posts on example.com/blog which points to controller/Blog.php->index()

and, i'm showing single blog post on example.com/blog/view/post-slug-here which points to controller/Blog.php->view($slug)

and maybe my contact page on example.com/contact which points to controller/Contact.php->index()

these are expected behaviour of CI and should work perfecty.

in addition to this scenario, (blog and contact page) there is another content (eg: page table on database) which i want to serve from url pattern like this: "example.com/page-title"

there maybe tens of dynamic content. so i cannot create controller for each of these content.

Exaple Page Table
Code:
ID   TITLE           CONTENT
1    brown-fox       The quick brown fox jumps over the lazy dog
2    fox-origin      The quick brown fox jumps over the lazy dog
..
99   where-is-lazy   The quick brown fox jumps over the lazy dog

To archieve this behaviour i tried following route:
PHP Code:
$route['(:any)'] = 'page/view/$1'

Since this approach archieves my needs, it's also breaking other blogs/pages etc.
Because any string just after example.com/anystring routing to [b]controller/Page.php->view($title)[/b]

So, is there a way to tell to CI that,

1) If requested controller/method exists, execute it. eg: example.com/blog => controller/Blog.php->index() )
2) And in case if it's not exists , execute a specified controller/method.
Reply


Messages In This Thread
RE: Routing to specific controller in case controller/method is not found. - by W140 - 09-25-2015, 11:29 AM



Theme © iAndrew 2016 - Forum software by © MyBB