Prev | Current Page 124 | Next

Rob Allen, Nick Lo, and Steven Brown

"Zend Framework in Action"

com>
Please post comments or corrections to the Author Online forum at
http://www.manning-sandbox.com/forum.jspa?forumID=329
Listing 4.6: IndexController action to display the page
public function indexAction()
{
$this->view->baseUrl = $this->_request->getBaseUrl(); |#1
}
<#1: store the base url in the view so that we can use it to load the requried JavaScript files >
To respond to the Ajax call, we need a separate action, which we will call ajaxAction. We will reuse the
same ajax.php file that we have been using for all examples as it has a perfectly good checkUsername()
function to do the actual validation. In keeping with the MVC separation, we have put this file in the models
directory and then include it for use in our action:
public function ajaxAction()
{
include ('models/ajax.php');
$name = trim($this->_request->getParam('name'));
$this->_view->result = checkUsername($name);
}
The associated view file, views/scripts/ajax.phtml contains just one line of code to output the result:
result; ?>
This is probably the simplest view file you??™ll ever see!
4.4.2 The client site of an Ajax request
In the Zend Framework, the JavaScript part of an Ajax request is held within the view section. Usually this
means that we use a template.


Pages:
112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136
pożyczki hale Porównywarka zasłony opony samochodowe