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

Send message to another controller? #229

Open
abdhass opened this issue Jan 29, 2017 · 3 comments
Open

Send message to another controller? #229

abdhass opened this issue Jan 29, 2017 · 3 comments

Comments

@abdhass
Copy link

abdhass commented Jan 29, 2017

Hi

Say i have a user login view (site/login). On submit goes to a method (site/loginUser) and in that controller method I want to send the user back to site/login but with a message (in my case a error message to say they couldnt log in), how would i do that?

I tried making a public property called message in my controller and setting it in loginUser() method and then the login() method will check if its filled and so the view will show message, but this doesnt work as the class will create itself again when sent to location: site/login.

Currently I put everything in one controller method, this checks if form submitted, if error then add to error array and the view will show this. if form not submitted, show the view form.

Any ideas? thanks

@bravedave
Copy link

Presumably you get to the site/login with some sort of redirect

so pass the message with the redirect

in straight php that is:

<?php
	header( "location: /site/login\n");

so:

<?php
	header( sprintf( "location: /site/login?msg=%s\n", urlencode('big fail'));

then on your login form:

<p><?php if ( isset($_GET['msg'])) print $_GET['msg'] ?></p>

@abdhass
Copy link
Author

abdhass commented Jan 30, 2017

thanks, thats one way. I went with IF logic in my method. that way, i can load the view with a error message.

Maybe i understand OOP in PHP wrong.

Seems like every page you hit, the application will restart. So any variables etc saved in-memory will get lost. How do people handle that?

p.s I have learnt a lot from this project and its code. Thank you.

@dannysmc95
Copy link

Hi @abdhass, this is the base of an MVC model, what happens is every request is redirected to index.php and then the MVC framework takes over. So you are right each time you request a page the MVC framework is run each time.

Saving variables can be done with files, cookies, session or a database. Depends on the type of content you need to store.

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

3 participants