Welcome Guest, Not a member yet? Register   Sign In
Differing behaviors of $config['uri_protocol']
#1

[eluser]Nanodeath[/eluser]
So...I have this annoying problem. I'm doing my work on two servers -- a server that my university provides (which I'm using as a staging server) and a "production" server that happens to be on Godaddy. So I've figured out how to get past Godaddy being annoying by changing the uri_protocol to request_uri or query_string (either work for navigation, actually). Also, I've .htaccessed the index_page out of the url. So here's the problem.

I have this in my Learn controller:

Code:
function view($id){
        $this->load->model('usercontent');
        $userid = $this->session->userdata('userid');
        if($this->usercontent->isVisibleToUser($id, $userid)){

On my staging server, if I go to the page base_url/learn/view, the if conditional there returns false and I get behavior as desired. However, on the Godaddy site all these warnings and notices come up about $id and "Missing argument 1 for Learn::view()". Is this a bug in the system or something I need to deal with? I mean, I could just go through all my methods and change every parameter variable to default to null, but that's no fun.

(As an aside, there will never be a link to learn/view without an id, but I want the system to fail gracefully if someone tampers with the url by hand).

Thanks!
#2

[eluser]Pascal Kriete[/eluser]
If it's never called without an id, why not make it a private function: _view($id) ?
#3

[eluser]Nanodeath[/eluser]
Be...cause...that would make it private. I still want the URL learn/view/1 to work.
#4

[eluser]Pascal Kriete[/eluser]
Ok, so instead of passing it in as an argument, just grab it from the uri:
Code:
$id = $this->uri->segment(3)
#5

[eluser]Seppo[/eluser]
Code:
function view($id = 0){
#6

[eluser]Nanodeath[/eluser]
Alright, thanks for the feedback guys. Strangely enough this morning I was not able to reproduce the behavior I desired on the university webserver, so either I'm imagining things, I was really tired last night, I tweaked one too many config.php settings, or some combination of the above. Regardless, I still wanted the functionality I described without modifying each and every method in what seems like a bit of a hackish way. Anyway, speaking of hackish (cough), here's my solution:

In Router.php->_set_request, I changed the last line from
Code:
$this->uri->rsegments = $segments;
to
Code:
$this->uri->rsegments = array_pad($segments, 6, null);
This way, every method is passed at least four arguments, and problem solved.

It just seems to *me conceptually that if a controller method is expecting something it doesn't receive, it should assume null instead of exploding.




Theme © iAndrew 2016 - Forum software by © MyBB