Introduction to MVC Programming with Agavi, Part 4: Creating a Agavi search engine with multiple output types (XML, RSS, or soap)
Brief introduction
In part 3rd of this series, you experience a task that you often encounter when building web-based applications: Implement a management module that allows administrators to perform CRUD operations through the Web interface. You also explored the Agavi security model, building a login system to authenticate users to secure access to application resources.
Now continue Agavi learning to add more functionality to this WASP (Web Car Sales Platform) sample application. You will implement a search engine that allows users to search the database directly and get a list that matches specific criteria. Furthermore, Agavi provides developers with a complex framework that allows them to easily add support for applications to multiple output types (XML, RSS, or SOAP). This article will learn how to return XML encoding results from search engines with minimal programming support.
Working with search criteria
Common abbreviations
API: Application Programming Interface
CRUD: Creating, reading, updating, and deleting
CVS: Concurrent Version Systems
DOM: Document Object Model
HTML: Hypertext Markup Language
HTTP: Hypertext Transfer Protocol
MVC: Model-View-controller
PDF: Portable Document Format
RSS: a really easy aggregation
URL: Uniform Resource Locator
XML: Extensible Markup Language
So far, the WASP application can accept the vehicle inventory submitted by the reseller and store it in the database for approval. The management module developed in part 3rd of this series allows administrators to review and approve these submitted manifests for display on the Web site. Administrators can also define the length of time each manifest is displayed on the site.
To make it easier for potential buyers to find a vehicle that meets their needs, it's a good idea to add a search feature to your application. The search interface will receive specific conditions from the buyer, search for approved listings to find the cars that meet the conditions, and finally display the results for further inspection.
First, add a new searchaction to the Listing module using the Agavi build script:
shell> agavi action-wizard
Module name: Listing
Action name: Search
Space-separated list of views to create for Search [Success]: Error Success
and update the application's routing table and add a new route for this Action, as shown in Listing 1:
Listing 1. Listing/searchaction Routing Definition
<?xml version="1.0" encoding="UTF-8"?>
<ae:configurations xmlns:ae="http://agavi.org/agavi/config/global/envelope/1.0"
xmlns="http://agavi.org/agavi/config/parts/routing/1.0">
<ae:configuration>
<routes>
...
<!-- action for listing pages "/listing" -->
<route name="listing" pattern="^/listing" module="Listing">
<route name=".create" pattern="^/create$" action="Create" />
<route name=".display" pattern="^/display/(id:\d+)$" action="Display" />
<route name=".search" pattern="^/search$" action="Search" />
</route>
...
</routes>
</ae:configuration>
</ae:configurations>