Difference between revisions of "Talk:Main Page"

From mi-linux
Jump to navigationJump to search
(Dead link)
 
(One intermediate revision by one other user not shown)
Line 1: Line 1:
How to search a record by Lima Begum (0610970)
+
<p>How to search a record by Lima Begum (0610970)
 
For this exercise, I used workshop 5 structure.
 
For this exercise, I used workshop 5 structure.
 
+
</p><p>Step1 – form  
Step1 – form  
+
</p><p>&lt;?php
 
+
<p>// application/forms/Search.php
<?php
+
</p>
// application/forms/Search.php
+
</p><p><br />
 
+
<p>class Form_Search extends Zend_Form
 
 
class Form_Search extends Zend_Form
 
 
{
 
{
  public function init()
+
</p>
    {
+
</p>
    // set the method for the display form to POST
+
<pre>  public function init()
        $this->setMethod('post');
+
  {
        // add first name element where a record will be searched by a student’s first name
+
    // set the method for the display form to POST
        $this->addElement('text', 'first', array(
+
      $this-&gt;setMethod('post');
            'label'      => 'first name:',
+
      // add first name element where a record will be searched by a student’s first name
            'required'  => true,
+
      $this-&gt;addElement('text', 'first', array(
            'filters'    => array('StringTrim'),
+
          'label'      =&gt; 'first name:',
            'validators' => array(
+
          'required'  =&gt; true,
                'NotEmpty',
+
          'filters'    =&gt; array('StringTrim'),
            )
+
          'validators' =&gt; array(
        ));
+
              'NotEmpty',
        // add the search button
+
          )
        $this->addElement('submit', 'submit', array(
+
      ));
            'label'    => 'Search',
+
      // add the search button
        ));
+
      $this-&gt;addElement('submit', 'submit', array(
    }
+
          'label'    =&gt; 'Search',
}
+
      ));
 
+
  }
 
+
</pre>
Step2 – Setting Up the Search Controller
+
<p>}
 
+
</p><p><br />
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.   
+
<p>Step2 – Setting Up the Search Controller
 
+
</p>
 
+
</p><p>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
+
</p><p><br />
 
+
<p>//application/controllers/IndexController.php
 
+
</p>
public function searchAction()
+
</p><p><br />
    {
+
<p>public function searchAction()
        $this->view->title = "Search record";   
+
</p>
        require_once APPLICATION_PATH . '/forms/Search.php';
+
</p>
        $form = new Form_Search();
+
<pre>  {
        $form->setAction($this->_helper->url('searchname'));
+
      $this-&gt;view-&gt;title = &quot;Search record&quot;;   
        $form->submit->setLabel('Search');
+
      require_once APPLICATION_PATH . '/forms/Search.php';
        $this->view->form = $form;
+
      $form = new Form_Search();
    }   
+
      $form-&gt;setAction($this-&gt;_helper-&gt;url('searchname'));
function searchnameAction()
+
      $form-&gt;submit-&gt;setLabel('Search');
    {
+
      $this-&gt;view-&gt;form = $form;
        $this->view->title = "Search Name";
+
  }   
      //while the value is posted
+
</pre>
        if ($this->_request->isPost()) {
+
<p>function searchnameAction()
            $first = $this->_request->getParam('first');
+
</p>
            //if name is not null, do search and fetch specified record
+
<pre>  {
            if (!$first = = "") {
+
      $this-&gt;view-&gt;title = &quot;Search Name&quot;;
                $students = new Students();
+
      //while the value is posted
                $where = 'first = ' . $first;
+
      if ($this-&gt;_request-&gt;isPost()) {
                $this->view->student = $studnets->fetchRow("first='$first'");
+
          $first = $this-&gt;_request-&gt;getParam('first');
            }
+
            //if name is not null, do search and fetch specified record
        }
+
          if (!$first = = &quot;&quot;) {
    }
+
              $students = new Students();
 
+
                $where = 'first = ' . $first;
Step3 –View   
+
              $this-&gt;view-&gt;student = $studnets-&gt;fetchRow(&quot;first='$first'&quot;);
 +
          }
 +
      }
 +
  }
 +
</pre>
 +
<p>Step3 –View   
 
I have added the following two views for form object and display search result.   
 
I have added the following two views for form object and display search result.   
+
</p><p>&lt;? // application/views/scipts/index/search.phtml&nbsp;?&gt;
<? // application/views/scipts/index/search.phtml ?>
+
</p><p>&lt;?= $this-&gt;form&nbsp;?&gt;
 
+
</p><p><br />
<?= $this->form ?>
+
<p>Display search result if certain conditions are meets.   
 
+
</p>
 
+
</p><p>&lt;? // application/views/scipts/index/searchname.phtml&nbsp;?&gt;
Display search result if certain conditions are meets.   
+
</p><p><br />
 
+
<p>&lt;?php if ($this-&gt;studnet)&nbsp;:?&gt;
<? // application/views/scipts/index/searchname.phtml ?>
+
</p>
 
+
</p>
 
+
<pre>  &lt;dt&gt; firstname:&lt;?php echo $this-&gt;escape($this-&gt; studnet -&gt;first);&nbsp;?&gt;&lt;/dt&gt;
<?php if ($this->studnet) :?>
+
  &lt;dt&gt;lastname:&lt;?php echo $this-&gt;escape($this-&gt; studnet -&gt;last);&nbsp;?&gt;&lt;/dt&gt;
  <dt> Title:<?php echo $this->escape($this-> studnet ->first); ?></dt>
+
</pre>
  <dt>Series:<?php echo $this->escape($this-> studnet ->last); ?></dt>
+
<p>&lt;?php else:&nbsp;?&gt;
<?php else: ?>
+
</p>
 
   <p>Cannot find a record.</p>
 
   <p>Cannot find a record.</p>
<?php endif;?>
+
<p>&lt;?php endif;?&gt;
 
+
</p><p><br />
 
+
<p>Now you can test your code by browse to =  
Now you can test your code by browse to =  
+
http://mi-linux.wlv.ac.uk/~0123654/QuickStart/public/search [Link dead]
http://mi-linux.wlv.ac.uk/~0123654/QuickStart/public/search
+
</p>
 +
</p>

Latest revision as of 22:10, 28 September 2010

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) :?>

  <dt> firstname:<?php echo $this->escape($this-> studnet ->first); ?></dt>
  <dt>lastname:<?php echo $this->escape($this-> studnet ->last); ?></dt>

<?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 [Link dead]