I have a weird problem. Hopefully, there's a simple explanation / a simple bug somewhere in my code.
I have methodA in my controller, that needs 3 parameters from the url. The code looks like this:
$data['listofpts'] = $this->sw_model->get_all_widgets($this->uri->segment(3),$this->uri->segment(4) );
$data['model'] = $this->uri->segment(4);
$data['ip'] = $this->uri->segment(3);
$data['objectid'] = $this->uri->segment(5);
$data['main_content']='allstats';
$this->load->view('includes/template', $data);
You can see that I'm grabbing 3 pieces of from the url. I have 2 additional methods (lets call them methodB and methodC) in the same controller and both of them, when complete, call methodA. However, when these other methods call methodA, the url looks different. Specifically, the "objectid" variable can be either segment 6 or 7 instead of segment 5.
here's an example of what the URL looks like when methodA is called:
http://myserver/myapp/mycontroller/methodA/10.14.123.123/H8699A/417
Here's an example of what the URL looks like when methodB is called:
http://myserver/myapp/mycontroller/methodB/10.14.3.44/H8699A/A14/417
I'm not sure if this is good design or not, but I decided to change the signature of methodA so that it accepts a number, representing the segment ID. So from methodB, I could do something like:
$this->methodA(6);
PROBLEM / QUESTION: There are two things that i don't understand. The first question is why the new parameter is displaying a value when you just call methodA on its own. As soon as the ivew "allstats" loads, it shows a value inside the new parameter. Technically, it should be empty. I've double checked to make sure that only 2 methods call methodA.
Second, I don't understand why when i dump the contents of the parameter, its showing the IP address, which is uri segment 3.
So far, the new code for methodA looks like this:
public function methodA($uriObjectid)
{
echo $uriObjectid;
$data['listofpts'] = $this->switches_model->get_all_widgets($this->uri->segment(3),$this->uri->segment(4) );
$data['model'] = $this->uri->segment(4);
$data['ip'] = $this->uri->segment(3);
$data['objectid'] = $this->uri->segment(5);
$data['main_content']='allstats';
$this->load->view('includes/template', $data);
}//end methodA
Any help would be appreciated. Thanks.
EDIT 1
This is what my controller looks like:
public MyController extends CI_Controller {
public methodA($optionalparm)
{
//url looks like: http://myserver/myapp/thiscontroller/value1/valueformethodA
echo $optionalparm; //this is the variable that's problematic. it should be 3 or 4.
$valueformethodA = $this->uri->segment(2)
}
public methodB() {
//url looks like: http://myserver/myapp/thiscontroller/value1/value2/value3/valueformethodA
//call methodA
// $valueformethodA is now uri segment 4. pass that as argument
$this->methodA(4);
}
public methodC() {
//url looks like: http://myserver/myapp/thiscontroller/value1/value2/valueformethodA
//call methodA
// $valueformethodA is now uri segment 4. pass that as argument
$this->methodA(3);
}
}