The examples on this site are currently tested to work on Phalcon V3.4 and Phalcon Devtools V3.2 Some issues may arise when using later versions.

Please get in touch or post a comment below the post if you encounter a problem.

The search page which is auto-generated by the scaffolder provides some very useful simple search functionality. A user who visits http://localhost/tennisClub/member/ having scaffolded the member table from the getting started section will be presented with the following page

This allows the user to enter one or more criteria upon which to search the member table. If the user enters "Junior" in the Membertype field they will get a list of Junior members.


The results are shown with a paginator in case there are a large number of results. This is very useful if a little bit clunky from a UX perspective. 

It is open to the developer to develop their own searchAction and results page which would return a list of junior members. This could be integrated seamlessly into the menu system of the application.

With a small tweak of the searchAction() function, however, that function could take search parameters passed to it using the router. This would allow the user to create a simple route which would show all junior members (or any other search criteria) and allow for rapid development of specific search requirements which could be quickly integrated into the menu system of the application.

To achieve this edit the file /app/controllers/MemberController.php. Modify the searchAction() function implementing the changes highlighted in red below.


else{
	if (isset($parms)) {
		$query = Criteria::fromInput($this->di, '\tennisClub\Member', $parms);
		$this->persistent->parameters = $query->getParams();
	} 

The searchAction function now takes an optional argument called $params. The else clause which has been added contains code identical to the code in the first if block except that rather than using the $_POST variable to extract the search criteria the $params variable is used. We can now create routes which will pass the search criteria to the search action via $_GET.

To do this modify the file /app/config/router.php. Add the following route

$router->add(
    '/juniorMembers',
    [
        'controller' => 'member',
        'action'     => 'search',
	3	     => ['membertype' => 'Junior'],
    ]
);

$router->add(
    '/seniorMembers',
    [
        'controller' => 'member',
        'action'     => 'search',
	3	     => ['membertype' => 'Senior'],
    ]
);

Now if a user visits http://localhost/tennisClub/juniorMembers they will get the same search results as if the user had typed Junior into the Membertype field on the search page as follows


http://localhost/tennisClub/seniorMembers will yield a list of Senior members. This approach can be applied to any searchAction function which has been auto-generated by the scaffolder. The approach is a bit of a hack but can achieve very useful results very quickly.