how to make shorten url in codeigniter |
Suppose my site has a get request with below URL.
http://localhost/mysitename/MainControll...eaname=abc But I want to alias the URL in shot form as like: http://localhost/mysitename/Testmethod How can I make the short form URL using alias ?
If you're trying to pass data using URL query params, you have to put them in the url query params. You can also pass data through post requests but that would mean your user has to submit a form. If you're looking to have 'clean' urls, you may want to look at a RESTful styled urls:
http://www.restapitutorial.com/lessons/r...aming.html
Codeigniter is simply one of the tools you need to learn to be a successful developer. Always add more tools to your coding arsenal!
(02-21-2018, 10:27 AM)albertleao Wrote: If you're trying to pass data using URL query params, you have to put them in the url query params. You can also pass data through post requests but that would mean your user has to submit a form. If you're looking to have 'clean' urls, you may want to look at a RESTful styled urls: Thanks albertleao for your valuable suggestion. But I have one question here..if I want to pass more than one data through query params then how I can use RESTful styled urls ?
You can use routing ... $routes['mysitename/testmethod'] = 'maintroller/testmethod';
See https://www.codeigniter.com/user_guide/g...ting-rules
Using routing like ciadmin mentioned above you can do something like this:
mywebsite.com/users/123/posts/123 Then in your routes file you do this: PHP Code: $route['users/(:num)/posts(:num)'] = 'posts_controller/show/$1/$2'; and in your posts controller PHP Code: class Posts_controller extends CI_Controller {
Codeigniter is simply one of the tools you need to learn to be a successful developer. Always add more tools to your coding arsenal!
Thanks all for your valuable suggestions. I was out of internet for last few days and I was late to reply. Apologize for this.
|
Welcome Guest, Not a member yet? Register Sign In |