isLogged in one Controller? |
[eluser]FREEZA[/eluser]
Hello. Ich want to create a Controller called Product. There you can find two methods: Code: createProduct(); // This method is only available for users witch are logged in The method getAllProducts() should be available for all! Please Help me: )
[eluser]Eric Barnes[/eluser]
Why not just move your isLogged into the method you want to require login and not in the constructor?
[eluser]FREEZA[/eluser]
so then i must to write this Code in every method where logged in is required? Code: if($this->session->userdata('logged_in') hm...it is okay so?
[eluser]steelaz[/eluser]
I would write this the other way around: Code: if ( ! $this->session->userdata('logged_in')
[eluser]FREEZA[/eluser]
okay, thanks for help! What i could do when i have a lot of methods where you must to be logged in? then i must write this code in every method: Code: if ( ! $this->session->userdata('logged_in') do you know a other way?
[eluser]steelaz[/eluser]
Usually I have "public" controllers (login/registration pages, website front-end, etc.) and "user/admin" controllers where user has to be logged-in to access them. Logged-in check happens in controller constructor so not to repeat it in every method. If you have a lot of methods that require logged-in user and some methods that are public, you might want to consider moving public methods to another controller.
[eluser]JonoB[/eluser]
Have a look at http://philsturgeon.co.uk/news/2010/02/C...ing-it-DRY |
Welcome Guest, Not a member yet? Register Sign In |