1

In Codeigniter, parameters from the URI are automatically made available to the method being called.

For example:

/admin/edit/news/1 in the url would mean that in the admin controller, you could do the following:

function edit($table,$id)
{
    echo $table; // outputs 'news'
    echo $id; // outputs '1'
}

So, in essence you are able to name and use the arguments within the method without previously having 'passed them in' in that order anywhere, and regardless of how many there are, they are still passed to the function in the order they appear in the URI.

I guess this must have something to do with the __call() magic method, but I can't get my head around how to pass them to the method being called as though they were individual arguments and not an $args array as received by the __call() method.

How is this achieved?

2

1 Answer 1

1

You can see the inteire logic around this magic on system/core/CodeIgniter.php file.

You can see how it is instantiating the class https://github.com/bcit-ci/CodeIgniter/blob/develop/system/core/CodeIgniter.php#L500

And also, I highlighted the line that is doing the job of call the method with parameters.

https://github.com/bcit-ci/CodeIgniter/blob/develop/system/core/CodeIgniter.php#L514

[]'s

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.