Im just confused how to build this URL (easy question for you guys, I think) |
[eluser]towki[/eluser]
Please see this image, I cannot attach files My method/function "administration" in my "Infosystem" controller loads a view that serves as an administration page that is only accessible by admins. For example an admin logged in typed "www.example.com/infosystem/administration" my administration page will be showed up consisting of several administrative functions. Speaking of this administrative function, My problem exactly is I want to have a link on this administration page that point to another view/page that function as managing the users, and that link should have a URL like this "www.example.com/infosystem/administration/user_management". If not for my URL concern, I could have created my user_management page by creating another function in my controller and loading a view. but i think that will not create the URL that I want. Just a newbie. Please help me with this
[eluser]pickupman[/eluser]
You would need to use the [url="http://codeigniter.com/nightly_user_guide/general/routing.html"]Router[/url] class for this. Routing is for making a uri use a different pattern than the standard in CI. This would go in /application/config/routes.php Code: $route['infosystem/administration/user_management'] = 'infosystem/user_management/'; //URI without 4th segment
[eluser]TWP Marketing[/eluser]
Since your second URL segment, "administration", may be used for two (or more) functions, you can set up a conditional statement in the administration method code: Your Controller named Infosystems" Code: ... Now if you use this URL: Code: http://www.example.com/infosystems/adminstration If you use this URL: Code: http://www.example.com/infosystems/adminstration/user_management and the conditional statement will call the user_management method and then return. NOTE: CI will pass the third URL segment as a parameter of the second URL segment, it's built in to CI.
[eluser]towki[/eluser]
@TWP MARKETING, I have tried your code and it works. However when I typed this url: Code: http://www.example.com/infosystems/user_management The user_management function can still be accessed. I want this user_management to be accessed only by the URL i wanted. Code: http://www.example.com/infosystems/adminstration/user_management Because this user_management is under the administration so its better to see my URL like that and could only be accessed by that URL
[eluser]pickupman[/eluser]
Don't you think it would be tough for some to guess that the URI might be different an remove a segment to access the page from the real URI. You know it's an option, but no one else would. It's also unlikely that anyone not in web development even pays attention to a url, let alone manipulate it. With that being said, just make it a private method to make it inaccessible directly. Code: public function administration($func="admin")
[eluser]towki[/eluser]
[quote author="pickupman" date="1343396461"]Don't you think it would be tough for some to guess that the URI might be different an remove a segment to access the page from the real URI. You know it's an option, but no one else would. It's also unlikely that anyone not in web development even pays attention to a url, let alone manipulate it. With that being said, just make it a private method to make it inaccessible directly. [/quote] Thanks for reply. But I have another question about URL. Sorry if my issues was all about URL When i typed my url for example and add another segment at the end of it which do not exist in my content, it should show an error 404 page. But instead it shows the page for the last valid segment in the URL.How could I fix that??.
[eluser]pickupman[/eluser]
I supposed if you wanted to worry about it, something like this would take care of it. Code: function administration($func="admin")
[eluser]TWP Marketing[/eluser]
Quote:...If there may be another segment, which is optional, just parse it the same as the prior segment. For a URL like this: Code: http://mydomain.com/infosystems/administration/user_management/some_var Code: ... |
Welcome Guest, Not a member yet? Register Sign In |