How can I get the user input from search form?

Hi All,

The data entered from user in the advanced search (_search.php) can be accessed in the search method in the corresponding model.

I need to access these data from another place (because I need to display them in some reports) other than the search method (from a model, a controller or whatever…)

How can I achieve this?

Hi erand

Please post an example.

_search.php is a view

actionSearch() belongs to Controller

search() of model is in Models section.

So, If you want to use the results of search method for other purpose you have to create an action and write the appropriate code.

OR

if you want to use those result in the same controller/action (actionAdmin) you have to store the model->search() in another variable (in action) and use it both in controller and in view.

Tell us what exactly you want to do?

Hi Kostas,

Thank you for your reply.

I wanted to access the user entered data (in the search form) from the same view.

(it was easy, I don’t know why I was confused…).

Even though it is working now, I am doing redundant work…

In the model, in the search method. Below is one example (out of many I do inside this method):




if($this->year_g != null){

        $start_;

        $end_;

        $start_month='10';

        $end_month='9';

        $year=$this->year_g;

        $next_year=$year+1;

        $date_from=$year.'-'.$start_month.'-'.$start_date;

        $date_to=$next_year.'-'.$end_month.'-'.$end_date;

        $criteria->addCondition("t.dAnfang>=:from && t.dAnfang<=:to");

        $criteria->params += array('from' => date('Y-m-d', strtotime($date_from)),'to' => date('Y-m-d', strtotime($date_to)));

                }



And I wanted to get the "$date_from" and "$date_to" calculated above and use it in a view (for report purposes).

And right now I am calculating again in the view…the same things I do inside the search method…