Example:
...scms/contracts/set_pm/3/Monthly
this is the URL and i want to get the word monthly...I cant use uri->segment in my view so I'm asking if there's other way
May be something like this
$actual_link = current_url();
$slashes = explode("/",$actual_link);
echo $element = $slashes[count($slashes)-1];
Just retrieve the current_url()
and explode it with /
, but why do such cumbersome process when you have lots of options provided by CI
.
If you cant use $this->uri
in your view just put that segment in a variable and load the view like this:
$data['segment'] = $this->uri->segment(5); //your segment here you want in your view
$this->load->view('view', $data);
Now, you will get the segment in your view as $segment
.
You can use explod
function in PHP to get a tab with your string in input.
$tab = explode("/", $url);
$last = end($tab);
Considering contracts is your controller file name and set_pm is your function then you can also fetch it like this:
class Contracts extends CI_Controller {
function set_pm($id, $interval)
{
echo $id; //prints 3
echo $interval; // prints Monthly
}
}