0

In this URL: www.example.com/transaction/summary/10 I can get 10 by this:

$this->uri->segment(3);

But, along with some other GET params how can I get that value?

e.g.: www.example.com/transaction/summary?local_branch=1/10

PS: GET params could be more than 1.

RNK
  • 5,582
  • 11
  • 65
  • 133

3 Answers3

0

To get these GET parameters you can just use:

$this->input->get('some_variable', TRUE);

As per the SO link here.

example.com/?some_variable=hey

Community
  • 1
  • 1
Tom
  • 1,068
  • 2
  • 25
  • 39
0

If you still want to keep CI style than add segments:

URL:

www.example.com/transaction/summary/10/1/TEST

Segments:

$this->uri->segment(3); // 10
$this->uri->segment(4); // 1
$this->uri->segment(5); // TEST

Or if you want to use query string than you can add params in query string and get values by using $_GET:

www.example.com/transaction/summary/10/?local_branch=1&test=test
devpro
  • 16,184
  • 3
  • 27
  • 38
0

Ok, segments in Codeigniter are the content between slashs like mysite.com/page/page-name. To get the page-name value I get the second segment, or $this->uri->segment(1). To get the strings passed by query string ($_GET), you can simply use the $_GET['local_branch'] as in your example or in case of Codeigniter, as the @Tom answer: $this->input->get('local_branch').

In this case, you can to explode the values delimiting by /.

$localBranch = $_GET['local_branch'];

// Or
$localBranch = $this->input->get('local_branch');

// And split using the / as delimiter if is need.
$localBranch = explode('/', $localBranch);

// Output
// Array(0 => 1, 1 => 10)

This way many values can be passed in same query string.

Andre Cardoso
  • 228
  • 1
  • 12