Welcome Guest, Not a member yet? Register   Sign In
Controller in subfolder, url parameters offset
#1

[eluser]msteudel[/eluser]
I have a controller in a subfolder

e.g.

admin/school.php

On my index action I have a list of schools and I want to pass the id through the url

e.g.

admin/school/update/id/9

Question 1
Is this the right format? vs. admin/school/update/9

Question 2
What's the right way to get id parameter? I tried to do:
$uri = $this->uri->uri_to_assoc()

And I print that array out I get:

Array
(
[update] => id
[9] =>
)


I can do

$this->uri->uri_to_assoc(4) and I get the right association match up. But I wondering if there is a less manual way for the system to figure this out?

TIA
#2

[eluser]Narkboy[/eluser]
Honestly, I looked at controllers in sub-folders and gave up. The confusion over URIs becomes too much of a pain. If it works for you, then great - and yes, Q1 you do have the right format.

For Q2 - are you always expecting an ID in the URI? If so then just write your controller function as
Code:
function some_page($id)

CI does the work of parsing the URI anyway - to load anything at all it has to read the admin directory for the school class and then load the update function. Variables in the function declaration are extensions of that. If you may or may not recieve an id, then remember to give it a default value in the function declaration and handle the default version first.

From a personal standpoint, I would avoid using subfolders unless you really have to. Just me not liking the URI results!

Smile
#3

[eluser]bhogg[/eluser]
[quote author="msteudel" date="1272445925"]I have a controller in a subfolder
...
Question 1
Is this the right format? vs. admin/school/update/9
[/quote]

If the function in admin/school.php is

Code:
function update($id)

then you should be calling admin/school/update/9

Quote:Question 2
What's the right way to get id parameter?

With the above you would just look at the value of $id
#4

[eluser]bhogg[/eluser]
Forgot to post this before a meeting, NarkBoy is right it can get confusing! Rarely have situations where a subfolder is needed.
#5

[eluser]msteudel[/eluser]
Interesting I thought subfolders seemed easier than setting up custom routing for some admin functionality.

Anyway just using $id worked.

Thanks guys




Theme © iAndrew 2016 - Forum software by © MyBB