How to get value from url in codeigniter?

Member

by dedrick , in category: PHP Frameworks , 9 months ago

How to get value from url in codeigniter?

Facebook Twitter LinkedIn Telegram Whatsapp

1 answer

Member

by aubrey , 9 months ago

@dedrick 

To get a value from the URL in CodeIgniter, you can utilize the uri->segment() method. Here is an example of how to get a value from the URL in CodeIgniter:

  1. First, make sure you have loaded the uri library in your controller where you want to retrieve the value from the URL. You can load the library in the constructor of your controller:
1
$this->load->library('uri');


  1. Then, you can use the segment() method to retrieve the value from the URL. For example, if your URL is http://example.com/controller/method/parameter, you can retrieve the parameter value like this:
1
$parameter = $this->uri->segment(3); // retrieves the third segment of the URL (parameter)


  1. You can now use the $parameter variable in your controller to perform any necessary operations with the retrieved value.


That's it! You have successfully retrieved a value from the URL in CodeIgniter.