Welcome Guest, Not a member yet? Register   Sign In
how to make shorten url in codeigniter
#1

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 ?
Reply
#2

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!
Reply
#3

(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:

http://www.restapitutorial.com/lessons/r...aming.html

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 ?
Reply
#4

You can use routing ... $routes['mysitename/testmethod'] = 'maintroller/testmethod';
See https://www.codeigniter.com/user_guide/g...ting-rules
Reply
#5

(This post was last modified: 02-21-2018, 01:52 PM by albertleao.)

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 {
 
   public function show($user_id$post_id) {
        //Your logic
 
   }

edit: I can't type today...
Codeigniter is simply one of the tools you need to learn to be a successful developer. Always add more tools to your coding arsenal!
Reply
#6

Thanks all for your valuable suggestions. I was out of internet for last few days and I was late to reply. Apologize for this.
Reply




Theme © iAndrew 2016 - Forum software by © MyBB