Understanding Yii controller: is this correct?


I would like to consult with the comunity if I understand correctly this workflow.

I have a search form, consisting of several drop down menus. This menu is a Porlet that extends Widget, like the Portlets in the Blog tutorial.

Now the first question is this: when I submit the form, it should be submitted to a controller action?

The second question is, if it is a controller, it should be the Search controller or the controller where the data I want to search for belongs?

Thank you.

A user registration form will store information in the user model so you should use the user controller.

Here’s a little break down for you.

Think of models as something that holds data. It holds the information regarding the data (so class attributes [variables]) and it holds rules to define the standards of that data (rules and validation methods [functions]).

Controllers are what manipulate models. They hold the methods used to manipulate the data.

So following your example you have a search form. The “data” class that’s a model will probably hold information such as the date, time, data id and a variety of other fields depending on what it is you’re storing (if it was emails, you’d have to, from, message etc.).

Now the model there will validate the data as it accepts it. So your search queries will have to be of a certain format (dates have to be proper dates and so on). Everything goes well then you will be able to manipulate the data within your controller.

So now in your controller, the action method that leads to the page you’re operating the search would validate the data (based on the methods part of the model) and then once everything is validated, it can perform the queries and other functions that search and pull the data in the database via queries.

The controller would then pass these results from data manipulation on to the view to present.

Hope that clears up the setup for you. Just know that data is stored in a model, it’s manipulated in a controller and it’s presented in a view.

Any further questions, feel free to ask :)