PHPFixing
  • Privacy Policy
  • TOS
  • Ask Question
  • Contact Us
  • Home
  • PHP
  • Programming
  • SQL Injection
  • Web3.0

Wednesday, March 2, 2022

[FIXED] How to hide the Post Controller name & method from URL using Codeigniter 3

 March 02, 2022     codeigniter, codeigniter-3, php     No comments   

Issue

I am using Codeigniter 3 and trying to hide the Controller file name and method from the URL but it's not working. In the below example "CommonPages" is the Controller file name and "postdetails" is the method.

www.mydomain.com/CommonPages/postDetails/social-testing-post
www.mydomain.com/CommonPages/postDetails/fix-the-windows-errors

I want to hide CommonPages/postDetails from the URL. There are around 100 of posts so it would be great if I do not specify each and every page link in the route.php file. Alternatively, I have tried the below code in route.php but it didn't worked for me.

$route['(:any)'] = 'CommonPages/postDetails/$1';
$route['(:num)'] = 'CommonPages/postDetails/$1';
$route['([a-zA-Z0-9]+)'] = "CommonPages/postDetails/$1";

Thanks all.


Solution

$route['product/:num'] = 'catalog/product_lookup';

In a route, the array key contains the URI to be matched, while the array value contains the destination it should be re-routed to.

In the above example, if the literal word product is found in the first segment of the URL, and a number is found in the second segment, the catalog class and the product_lookup method are instead used.

You need config better the routes check this for more info:

https://codeigniter.com/userguide3/general/routing.html



Answered By - Ak1to
  • Share This:  
  •  Facebook
  •  Twitter
  •  Stumble
  •  Digg
Newer Post Older Post Home

0 Comments:

Post a Comment

Note: Only a member of this blog may post a comment.

Total Pageviews

Featured Post

Why Learn PHP Programming

Why Learn PHP Programming A widely-used open source scripting language PHP is one of the most popular programming languages in the world. It...

Subscribe To

Posts
Atom
Posts
Comments
Atom
Comments

Copyright © PHPFixing