Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Question #3

Closed
dosbubba opened this issue Dec 5, 2020 · 3 comments
Closed

Question #3

dosbubba opened this issue Dec 5, 2020 · 3 comments

Comments

@dosbubba
Copy link

dosbubba commented Dec 5, 2020

If you have a website where the header (/app/views/layout/header.php) is different for logged in users and not logged in users, how would you implement that?

The difference is one header for anonymous users that contains a Sign In button and a drop down menu of other account options and one that contains Log Out button instead for logged in users.

I can think of 2 possible solutions:

  1. Pass the data to the view through the $data[] associative array. (ex: $data['loggedin] = 0 or 1 for true and false). Then add the logic (an if statement) within /app/views/layout/header.php to render the right content. Is it appropriate to put if statement logic within a view?

  2. Have the Model call a different view if user is logged in (for example: /app/views/layout/header.php and /app/views/layout/user_header.php).

Any thoughts would be greatly appreciated.

@ahegazy
Copy link
Owner

ahegazy commented Dec 5, 2020

Hey,
It's been a while since i last checked the project, but i took a quick look and I think the second solution would be better for modularity .

You already have $loggedUser variable in /app/core/Controller.php so you can just modify the view function to include different header in case the user is logged in.

@dosbubba
Copy link
Author

dosbubba commented Dec 5, 2020

Thank you. This project has helped me a lot with learning PHP MVC.

@ahegazy
Copy link
Owner

ahegazy commented Dec 6, 2020

Happy to hear that, you are welcome.

@ahegazy ahegazy closed this as completed Dec 6, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants