Difference between revisions of "Talk:Main Page"
Line 6: | Line 6: | ||
<?php | <?php | ||
// application/forms/Search.php | // application/forms/Search.php | ||
+ | |||
class Form_Search extends Zend_Form | class Form_Search extends Zend_Form | ||
Line 36: | Line 37: | ||
//application/controllers/IndexController.php | //application/controllers/IndexController.php | ||
+ | |||
+ | |||
public function searchAction() | public function searchAction() | ||
{ | { | ||
Line 64: | Line 67: | ||
<? // application/views/scipts/index/search.phtml ?> | <? // application/views/scipts/index/search.phtml ?> | ||
+ | |||
<?= $this->form ?> | <?= $this->form ?> | ||
Line 70: | Line 74: | ||
<? // application/views/scipts/index/searchname.phtml ?> | <? // application/views/scipts/index/searchname.phtml ?> | ||
+ | |||
+ | |||
<?php if ($this->studnet) :?> | <?php if ($this->studnet) :?> | ||
<dt> Title:<?php echo $this->escape($this-> studnet ->first); ?></dt> | <dt> Title:<?php echo $this->escape($this-> studnet ->first); ?></dt> |
Revision as of 21:44, 30 March 2009
How to search a record by Lima Begum (0610970) For this exercise, I used workshop 5 structure.
Step1 – form
<?php // application/forms/Search.php
class Form_Search extends Zend_Form
{
public function init() { // set the method for the display form to POST $this->setMethod('post'); // add first name element where a record will be searched by a student’s first name $this->addElement('text', 'first', array( 'label' => 'first name:', 'required' => true, 'filters' => array('StringTrim'), 'validators' => array( 'NotEmpty', ) )); // add the search button $this->addElement('submit', 'submit', array( 'label' => 'Search', )); }
}
Step2 – Setting Up the Search Controller
I added the following two actions to the ‘IndexController()’ which will find out search form object and process the form upon submission that will fetch user specified record.
//application/controllers/IndexController.php
public function searchAction()
{ $this->view->title = "Search record"; require_once APPLICATION_PATH . '/forms/Search.php'; $form = new Form_Search(); $form->setAction($this->_helper->url('searchname')); $form->submit->setLabel('Search'); $this->view->form = $form; }
function searchnameAction()
{ $this->view->title = "Search Name"; //while the value is posted if ($this->_request->isPost()) { $first = $this->_request->getParam('first'); //if name is not null, do search and fetch specified record if (!$first = = "") { $students = new Students(); $where = 'first = ' . $first; $this->view->student = $studnets->fetchRow("first='$first'"); } } }
Step3 –View I have added the following two views for form object and display search result.
<? // application/views/scipts/index/search.phtml ?>
<?= $this->form ?>
Display search result if certain conditions are meets.
<? // application/views/scipts/index/searchname.phtml ?>
<?php if ($this->studnet) :?>
<?php else: ?>
Cannot find a record.
<?php endif;?>
Now you can test your code by browse to =
http://mi-linux.wlv.ac.uk/~0123654/QuickStart/public/search