You are on page 1of 5

Gio trnh: Zend Framework Zend_View (phn 2)

Trung Tm Tin Hc Hong Nguyn http://www.hoangnguyen.edu.vn

Zend_View (Phn 2)
Trong Zend_View phn 2 ny chng ta s nghin cu nhng phng thc to ra i tng trong form. Cc i tng ny c gi l Zend_View_Helper. Cc i tng thuc loi Zend_View_Helper thng c s dng ngoi View ca m hnh MVC. (Ch : Tt c v d y thc hin trong phn View ca ng dng) 1. Ly tn Server hin thi (Zend_View_Helper_ServerUrl) V d:
<?php echo $this->serverUrl(); ?>

2. To ng dn url (Zend_View_Helper_Url)
$this->url ($urlOptions, $name , $reset = false, $encode = true) $urlOptions: Mng thng s truyn vo to link $name: Mt i tng cu hnh ca Zend_Controller_Router_Route

Lp ny gip chng ta to ra ng dn gn vo cc link v chng ta c th kt hp vi Zend_Controller_Router_Route to ra nhng ng dn thn thin vi my tm kim hn V d:


<?php echo $this->url(array('module'=>'default', 'controller' => 'index', 'controller' => 'view', 'product_id' => 1)); ?>

3. To button (Zend_View_Helper_FormButton)
$this->formButton($name, $value = null, $attribs = null); $name: tn ca i tng $value: gi tr ca i tng $attribs: cc thuc tnh ca i tng nh size, color, background (array)

V d:
<?php echo $this->formButton('submit', 'Save Now', array('style'=>'border: #666666 1px solid')); ?> <br/><br/>

4. To CheckBox (Zend_View_Helper_FormCheckbox)
$this->formCheckbox($name, $value = null, $attribs = null); $name: tn ca i tng $value: gi tr ca i tng $attribs: cc thuc tnh ca i tng nh size, color, background (array)

V d:
<?

Guide: Phm V Khnh

Email: vukhanh2212@gmail.com

Gio trnh: Zend Framework Zend_View (phn 2)

Trung Tm Tin Hc Hong Nguyn http://www.hoangnguyen.edu.vn

echo $this->formCheckbox ( 'myCheckbox_1', 'Yes', array ('checked' => 'checked' ) ); echo $this->formCheckbox ( 'myCheckbox_2', 'No', null ); ?> <br/><br/>

5. To thng bo error (Zend_View_Helper_FormErrors)


$this->formErrors($errors, array $options = null); $errors: cc thng bo error $option: cc thuc tnh ca i tng nh size, color, background (array)

V d:
<? $arrError = array ('Happy 1', 'Happy 2' ); $options = array ('style' => ' color:#FF0000; font-size:15px' ); //$this->formErrors($errors, array $options = null); echo $this->formErrors ( $arrError, $options ); ?> <br/><br/>

6. To file (Zend_View_Helper_FormFile)
$this->formFile($name, $value = null, $attribs = null); $name: tn ca i tng $value: gi tr ca i tng $attribs: cc thuc tnh ca i tng nh size, color, background (array)

V d:
<?=$this->formFile ( 'myFile', '', array ('size' => '40' ) );?> <br/><br/>

7. To hidden (Zend_View_Helper_FormHidden)
$this->formHidden($name, $value = null, array $attribs = null); $name: tn ca i tng $value: gi tr ca i tng $attribs: cc thuc tnh ca i tng nh size, color, background (array)

V d:
<?=$this->formHidden ( 'hidden', 'abc' );?> <br/><br/>

8. To Image (Zend_View_Helper_FormImage)
$this->formImage($name, $value = null, $attribs = null); $name: tn ca i tng $value: gi tr ca i tng $attribs: cc thuc tnh ca i tng nh size, color, background (array)

V d:
<?=$this->formImage ( 'myImage', 'abcImage', array ('src' => 'images/img001.jpg' ) );?> <br/><br/>

9. To Password (Zend_View_Helper_FormPassword)
$this->formPassword($name, $value = null, $attribs = null); Guide: Phm V Khnh 2 Email: vukhanh2212@gmail.com

Gio trnh: Zend Framework Zend_View (phn 2) $name: tn ca i tng $value: gi tr ca i tng $attribs: cc thuc tnh ca i tng nh size, color, background (array)

Trung Tm Tin Hc Hong Nguyn http://www.hoangnguyen.edu.vn

V d:
<?=$this->formPassword('myPassword','',array('size'=>'30'));?> <br/><br/>

10. To Radio (Zend_View_Helper_FormRadio)


$this->formRadio($name, $value = null, $attribs = null,$options = null, $listsep = "<br/> \n"); $name: tn ca i tng $value: gi tr ca i tng $attribs: cc thuc tnh ca i tng nh size, color, background (array) $option: mng d liu ca cc nt radio $listsep: Du ngn cch gi cc nt radio trong 1 nhm

V d:
<?php $options = array ('1' => 'Happy', '2' => 'Birthday', '3' => 'To', '4' => 'You' ); echo $this->formRadio ( 'myRadio_1', 1, null, $options, ' ' ); echo '<br>' . $this->formRadio ( 'myRadio_2', 3, null, $options, ' ' ); ?> <br/><br/>

11. To Reset button (Zend_View_Helper_FormReset)


$this->formReset($name = '', $value = 'Reset', $attribs = null); $name: tn ca i tng $value: gi tr ca i tng $attribs: cc thuc tnh ca i tng nh size, color, background (array)

V d:
<?php echo $this->formReset ( 'myReset', 'Reset', array ('style' => 'border: #666666 1px solid' ) ); ?> <br/><br/>

12. To SelectBox (Zend_View_Helper_FormSelect)


$this->formSelect($name, $value = null, $attribs = null,$options = null, $listsep = "<br/> \n"); $name: tn ca i tng $value: gi tr ca i tng $attribs: cc thuc tnh ca i tng nh size, color, background (array) $option: mng d liu ca cc nt radio $listsep: Du ngn cch gi cc nt check trong 1 nhm

V d:
<?php $options = array ('1' => 'Happy', '2' => 'Birthday','3' => 'To','4' => 'You' ); echo $this->formSelect ( 'mySelect', 1, array ('style' => 'width: 150px' ), $options, null ); ?> <br/><br/>

13. To Submit button:


Guide: Phm V Khnh 3 Email: vukhanh2212@gmail.com

Gio trnh: Zend Framework Zend_View (phn 2) $this->formSubmit($name, $value = null, $attribs = null); $name: tn ca i tng $value: gi tr ca i tng $attribs: cc thuc tnh ca i tng nh size, color, background (array)

Trung Tm Tin Hc Hong Nguyn http://www.hoangnguyen.edu.vn

V d:
<?php Echo $this->formSubmit('mySubmit','Save Now', array('style'=>'border: #666666 1px solid')); ?> <br/><br/>

14. To Textbox (Zend_View_Helper_FormSubmit)


$this->formText($name, $value = null, $attribs = null); $name: tn ca i tng $value: gi tr ca i tng $attribs: cc thuc tnh ca i tng nh size, color, background (array)

V d:
<?php echo $this->formText('myText', 'I love ZF', array('style'=>' color:#FF0000; fontsize:15px')); ?> <br/><br/>

15. To TextArea (Zend_View_Helper_FormTextarea)


$this->formTextarea($name, $value = null, $attribs = null); $name: tn ca i tng $value: gi tr ca i tng $attribs: cc thuc tnh ca i tng nh size, color, background (array)

V d:
<?php echo $this->formTextarea('myTextArea', 'I love ZF', array('cols'=>'60','rows'=>'8')); ?> <br><br>

16. Multi checkbox (Zend_View_Helper_FormMultiCheckbox)


$this->formMultiCheckbox($name, $value = null, $attribs = null,$options = null, $listsep = "<br/> \n") $name: tn ca i tng $value: gi tr ca i tng $attribs: cc thuc tnh ca i tng nh size, color, background (array) $option: mng d liu ca cc nt radio $listsep: Du ngn cch gi cc nt radio trong 1 nhm

V d:
<?php $options = array('1'=> 'admin','2'=>'mod','3'=>'user'); echo $this->formMultiCheckbox('abc',array('1','3'),array('width'=>'200px'),$options); ?>

Cc cch nhng script vo View. 17. S dng Zend_View_Helper_Partial


Guide: Phm V Khnh 4 Email: vukhanh2212@gmail.com

Gio trnh: Zend Framework Zend_View (phn 2)

Trung Tm Tin Hc Hong Nguyn http://www.hoangnguyen.edu.vn

$this->partial ([string $name = null], [string|array $module = null], [array $model = null]) string $name: Tn ca script (.php, .phtml) string|array $module: gi tr c a nhn t view truyn vo array $model: gi tr c a nhn t view truyn v

scripts/partial.phtml
<ul> <li>From: <?php echo $this->escape($this->from) ?></li> <li>Subject: <?php echo $this->escape($this->subject) ?></li> </ul>

index3.phtml
<h1> index3.phtml</h1> <?php echo $this->partial('partial.phtml', array( 'from' => 'Team Framework', 'subject' => 'view partials')); ?>

18. S dng Zend_View_Helper_PartialLoop


$this->partialLoop([string $name = null], [string|array $module = null], [array $model = null]) string $name: Tn ca script (.php, .phtml) string|array $module: gi tr c a nhn t view truyn vo array $model: gi tr c a nhn t view truyn v

scripts\partialLoop.phtml
<?php // partialLoop.phtml ?> <dt><?php echo $this->key ?></dt> <dd><?php echo $this->value ?></dd>

\view\index4.phtml
<h1> index4.phtml</h1> <dl> <?php $model = array( array('key' => 'Mammal', 'value' => 'Camel'), array('key' => 'Bird', 'value' => 'Penguin'), array('key' => 'Reptile', 'value' => 'Asp'), array('key' => 'Fish', 'value' => 'Flounder'), ); ?> <?php echo $this->partialLoop('partialLoop.phtml', $model) ?> </dl>

18. S dng Zend_View_Helper_Action


$this->string action(string $action, string $controller, [string $module = null], [ $params = array()]) string $action: Tn ca action string $controller: Tn ca controller string $modules: Tn ca module $paramas: Mng tham s truyn vo

V d:
<?php echo $this->action('index3','index','default');?>

Guide: Phm V Khnh

Email: vukhanh2212@gmail.com

You might also like