We have moved our forum to GitHub Discussions. For questions about Phalcon v3/v4/v5 you can visit here and for Phalcon v6 here.

Sending data from View to Controller

Hi, I am new to phalcon. After reading docs, I was able to send data from controller to it srespective view. But I couldn't find out how to send data from View to Controller. How can I call controller from view? This is a very basic question at this forum, but I couldn't find any other community platform to get help regarding phalcon.

Looking forward to response. Please guide me through this. Thank you

you don't - control flow goes from the controller to the view and ends with the view. Maybe you mean you want to post data to the controller which would need a form and another route?



5.1k

Hello

Everything depends on your needs :

  • The most common case is to send user input data from a form with a submit button, it's work like à classic html form,

see invo tutorial : https://docs.phalcon.io/fr/3.2/tutorial-invo

  • By using ajax and jquery to just update an item on the page

Thanks for response.

For example, I am making a chat interface. I have a home view (lets say view A). Whenever user types a message in text box and presses enter, I want that message to be sent to some controller for further processing.

What I got from your comment is that I should do it using forms. Right?

Is using forms the only and best option to acheive such functionality?

edited Aug '17

That would be done via Javascript/Jquery/any JS library OR by standard HTML Posting done from a form. If you don't want the page to reload then AJAX using JS. Note: This would be the same with any PHP framework.

Thanks for response.

For example, I am making a chat interface. I have a home view (lets say view A). Whenever user types a message in text box and presses enter, I want that message to be sent to some controller for further processing.

What I got from your comment is that I should do it using forms. Right?

Is using forms the only and best option to acheive such functionality?