Pro PHP- Patterns, Frameworks, Testing and More

(vip2019) #1

(^228) CHAPTER 15 ■ INTRODUCTION TO THE ZEND FRAMEWORK
Listing 15-13. Using View Helpers (application/views/scripts/customers/add.phtml)



formText('name'); ?>
formSubmit('submit'); ?>

This invokes two view helpers: formText and formSubmit. These views will resolve to create
the following output HTML:




Next, add an empty action method to the controller class in CustomersController.php, as
shown in Listing 15-14. Even without a method body, this method’s mere presence will allow
for the rendering of the view customers/add.phtml.
Listing 15-14. Adding an Action Method (in CustomersController.php)
public function addAction() {}
Next, visit [http://example.com/customers/add,](http://example.com/customers/add,) and you should see your form.
Before you start on any given form, it is usually useful to submit some good data and make
sure it gets to your application correctly. Normally, you might use var_dump($_POST) or some-
thing similar to output all the form data. However, in the Zend Framework, you want to ensure
that the data is getting through all the APIs properly. To do this, you will use Zend_Debug to display
the post information parsed by the Zend_Request object. Modify the addAction() method as
shown in Listing 15-15.
Listing 15-15. Using Zend_Debug::dump (in CustomersController.php)
public function addAction() {
Zend_Debug::dump($this->getRequest()->getPost());
}
On submitting your form, you should see your form, as well as a result like this:
array(2) {
["name"] => string(4) "test"
["submit"] => string(6) "submit"
}
At this point, you know that your inputs are working and that the post action is going to the
right action. You are now ready to process your form.
McArthur_819-9C15.fm Page 228 Thursday, February 28, 2008 7:44 AM
Free download pdf