Welcome Guest, Not a member yet? Register   Sign In
Code to run on every page
#1

[eluser]Unknown[/eluser]
Greetings.

I just started using Codeigniter, so I'm still learning my way around.

I've built a simple login form, and based on whether the user is logged in or not I'd like to display a link. So if the user is logged in it will show "Logout", if the user is not, it will show "Login | Register".

Now how can I set this up so that this check is performed on each page. Without having to repeat my code into every controller.

Any insight would be greatly appreciated.
#2

[eluser]Samus[/eluser]
[quote author="turtlefrog" date="1334100918"]Greetings.

I just started using Codeigniter, so I'm still learning my way around.

I've built a simple login form, and based on whether the user is logged in or not I'd like to display a link. So if the user is logged in it will show "Logout", if the user is not, it will show "Login | Register".

Now how can I set this up so that this check is performed on each page. Without having to repeat my code into every controller.

Any insight would be greatly appreciated.[/quote]
You can have like a header view, which is included on every other view (look into templating)

and then in your header view have something along the lines of this:

Code:
if($this->session->userdata('logged_in') == 1) {
// echo link to logout url
}
else {
// echo links to login & register
}
#3

[eluser]Adrian Walls[/eluser]
Have a look at base classes:

http://philsturgeon.co.uk/blog/2010/02/C...ing-it-DRY




Theme © iAndrew 2016 - Forum software by © MyBB