Submitting data to web applications powered by Mivec Framework

Calling MivecServlet.php

After creating the Actions, we may start preparing the HTML pages and forms which calls the Actions added into Mivec Framework.

As Mivec Framework directly maps request parameters to Actions using the parameter names, for the following Action:

<?php
 
require_once MIVEC_HOME . "action/WebAction.class.php";
 
class ListUsers extends WebAction
{
    var $page;
    var $sort;
 
    function setPage($page)
    {
        $this->page = $page;
    }
 
    function setSort($sort)
    {
        $this->sort = $sort;
    }
 
    function execute()
    {
        //The code to query database is omitted....
        return SUCCESS;
    }
 
    function listAll()
    {
        //The code to query database is omitted....
        return SUCCESS;
    }
}
 
?>

All requests to Actions in Mivec Framework must be submitted to MivecServlet.php, with a parameter, ____mivec_action____ followed by the name of the Action.1) Therefore, when calling this action from a web page, we will use the following URL:

http://example.com/MivecServlet.php?____mivec_action____=ListUsers&page=2&sort=asc

For values which are arrays, e.g. values from a bunch of checkboxes, we just need to follow PHP’s convention to declare the value name with a pair of brace([]) at the end. As an example, look at the following snippet from a HTML form:

<!-- This is just a snippet. Of course you would not use forms simple like this :) -->
<p>Please tick your interest(s) below: (You can check more than one)</p>
<form action="MivecServlet.php" method="post">
<table>
    <tr>
    <td><input type="checkbox" name="interest[]" value="entertainment">Entertainment</td>
    <td><input type="checkbox" name="interest[]" value="music">Music</td>
    <td><input type="checkbox" name="interest[]" value="movies">Movies</td>
    </tr>
    <tr>
    <td><input type="checkbox" name="interest[]" value="books">Books</td>
    <td><input type="checkbox" name="interest[]" value="tech">Technology</td>
    <td><input type="checkbox" name="interest[]" value="fashion">Fashion</td>
    </tr>
</table>
<input type="hidden" name="____mivec_action____" value="RegisterNewUser">
</form>

At the Action implementation, RegisterNewUser, which this HTML form will be submitted to, it just need a setInterest() method, and proper PHP code that handles the injected array.

Specify the command to execute in Action

For the above Action ListUsers, if we want Controller to execute the listAll() method, which may return a full list of the users instead of page-by-page, we add a dot (.) followed by the command name to execute. In other words, the URL to call listAll() in ListUsers will then be

http://example.com/MivecServlet.php?____mivec_action____=ListUsers.listAll&page=2&sort=asc

The dot can be changed, however, by setting the configuration parameter “mivec.settings.controller.command-separator” in settings.properties.

Submitting data without the ____mivec_action____

As you may noticed, for submitting data to the web application powered by Mivec Framework, we always need to add the clumsy ____mivec_action____ and always submitting to MivecServlet.php, which may be not very pretty, either to application users and search engines. For this, Mivec Framework also comes with solutions based on URL rewriting or extraction. See Friendly URLs with Mivec Framework for details.


« Prev: Internationalizing Application with gettext Next: Working with Views: page templates »

1) Such cryptic name is chosen to prevent confusion.
 
  devguide/calling_mivec.txt · Last modified: 2005/03/05 14:53
 
Recent changes RSS feed Powered by PHP Valid XHTML 1.0 Valid CSS Driven by DokuWiki

SourceForge.net Logo