ZEND query

-

-

1-How To Create Form in Zend   of Form architecture in ZEND

class Form_UserRank extends Zend_Form
{
public function __construct($option=null)
{
parent::__construct($options);
$this->setName(‘User Rank’);
$id=new Zend_form_Element_Hidden(‘id’);

$rank=new Zend_Form_Element_Select(‘rank’);
$services->setRequired(true)
->removeDecorator(‘label’)
->removeDecorator(‘HtmlTag’)
->addFilter(‘StripTags’)
->addFilter(‘StringTrim’)
->addValidator(‘NotEmpty’)
->addErrorMessage(‘Services required.’);

$user=new Zend_form_Element_Hidden(‘user’);

$date=new Zend_Form_Element_Text(‘date’);
$date->setRequire(true)
->addFilter(‘StripTags’)
->addFilter(‘StringTrim’)
->addValidator(‘NotEmpty’);

$submit=new Zend_Form_Element_Submit(‘submit’);
$submit->setAttrib(‘id’,'submitbutton’);

$this->addElements(array($id,$rank,$user,$date,$submit));

}
}

2-How to create  Paginator in zend

Model Section

public function showAllSlotRecord($pageNumber,$viewSlot) {
$result= $this->getAdapter()->fetchAll(“SELECT * FROM $this->_name WHERE slot_id=$viewSlot order by total_child desc”);
$paginator=Zend_Paginator::factory($result);
$paginator->setItemCountPerPage(’100′);
$paginator->setCurrentPageNumber($pageNumber);
return $paginator;
}

controller section

$dashboard=new Uni_Classes_MLM_DashboardManager();
$this->view->sponserrecord=$record=$dashboard->getAllMemberId($this->_getParam(‘page’,1),$genDate2);

view section

<table width=”100%” border=”0″ cellpadding=”4″ cellspacing=”0″ bgcolor=”#ededed” style=”border:1px solid #dcdcdc”>

<tr><td width=”31%” colspan=”2″>—–Paste  Your Content—-</td></tr>

<tr>
<td colspan=”8″ align=”center” bgcolor=”#f6f6f6″ style=”border:1px solid #dcdcdc”><b>
<?php echo $this->paginationControl($this->allslot,’Jumping’,'paginator.phtml’); ?></b>
</td>
</tr>

<table>

3:-Insert multi-dimensional array in database in zend

public function insertRefferalAmount($data)
{
//return $this->insert($data1);
foreach ($data as $row)
{
$this->insert($row);
}

}

4->Set Multioption in form add value in select option from database

Model Query–

public function getAllModule() {
$att= $this->getAdapter()->fetchAll(“select * from cms_module “);
$data=array();
for($i=0;$i<count($att);$i++) {
$data[$att[$i]['id']]=$att[$i]['name'];
}
return $data;
}

form query-

$modelC= new Model_DbTable_Controller();
$getAllControllerName=$modelC->getAllControllerName();

$subject=new Zend_Form_Element_Select(‘subject’,array(‘style’=>’width:251px; margin-left:100px; padding:2px;’));
$subject->setRequired(true)
->removeDecorator(‘label’)
->setLabel(‘Category’)
->setDescription(‘Subject of you contact (e.g Testing)’)
->removeDecorator(‘HtmlTag’)
->addFilter(‘StripTags’)
->addFilter(‘StringTrim’)
->addValidator(‘NotEmpty’)
->setMultiOptions(array($getAllControllerName));

Question :- How to send email in zend ?

Answer :-

public function send()
{
$config = array(‘ssl’ => ‘tls’, ‘port’ => 587, ‘auth’ => ‘login’, ‘username’ => ‘username@gmail.com’, ‘password’ => ‘password’);
$transport = new Zend_Mail_Transport_Smtp(‘smtp.gmail.com’, $config);

$mail = new Zend_Mail();
if (strtolower($this->getType()) == ‘html’)
$mail->setBodyHtml($this->getBody());
}
else {
$mail->setBodyText($this->getBody());
}

$mail
->setFrom($this->getFromEmail(), $this->getFromName())
->addTo($this->getToEmail(), $this->getToName())
->setSubject($this->getSubject());

$mail->send($transport);

return $this;
}

Question :- How to file download in Zend ?

Answer :-

public function downloadAction() {
$file = $this->getRequest()->getParam(‘filename’);
$filename = ‘uploads/joining_kit/’ . $file;
header(“Pragma: public”);
header(“Expires: 0″);
header(“Pragma: no-cache”);
header(“Cache-Control: no-store, no-cache, must-revalidate, post-check=0, pre-check=0″);
header(“Content-Type: application/force-download”);
header(“Content-Type: application/octet-stream”);
header(“Content-Type: application/download”);
header(‘Content-disposition: attachment; filename=’ . basename($filename));
header(“Content-Transfer-Encoding: binary”);
header(‘Content-Length: ‘ . filesize($filename));
readfile($filename);
exit(0);
}

Question :- How to create PDF in Zend ?

Answer:- <?php
function createPdf(){
require_once ‘Zend/Loader/Autoloader.php’;
// register auto-loader
$loader = Zend_Loader_Autoloader::getInstance();
try {
$pdf = new Zend_Pdf();
$page = new Zend_Pdf_Page(Zend_Pdf_Page::SIZE_A4);
$font = Zend_Pdf_Font::fontWithName(Zend_Pdf_Font::FONT_HELVETICA);
$ifont = Zend_Pdf_Font::fontWithName(Zend_Pdf_Font::FONT_COURIER_ITALIC);
$image = Zend_Pdf_Image::imageWithPath(‘http://www.google.co.in/logos/2011/lebanon-2011-hp.jpg’);
$image2 = Zend_Pdf_Image::imageWithPath(‘http://www.google.co.in/logos/2011/lebanon-2011-hp.jpg’);
$page->drawImage($image, 70, 775, 120, 800);
$page->drawImage($image2, 550, 700, 500, 750);

$page->setFont($font, 12)
->drawText(‘Coupon Code: NSUFR59Q2′, 72, 755);
$page->setFont($font, 10)
->drawText(‘Arskort A baA hA siA Ai aA eins…’, 72, 735);

$page->setFont($ifont, 10)
->drawText(‘Date Oct21,2011′, 72, 720)
->drawText(‘Brottor 2 jun’, 72, 705)
->drawText(‘Heimkoma 7 jun’, 72, 690);

$page->drawLine(10, 670, ($page->getWidth()-10), 670);

$page->setFont($font, 12)
->drawText(‘Use At:’, 72, 650)
->drawText(‘Fine Print:’, 490, 650);

$page->setFont($font, 10)
->drawText(‘Brautarholti 20, 105. Reykjavik Iceland’, 72, 635)
->drawText(‘Gildir i alla opna tima taekjasal, heita laug’, 400, 635)
->drawText(‘www.badhusid.is’, 72, 620)
->drawText(‘sauna, vatnsgufu og hvildarhreiour.’, 430, 620)
->drawText(‘Nyta verour petta tilboo fyrir 30 juni 2011′, 405, 605);

$page->setFont($font, 12)
->drawText(‘Valid Thought:’, 72, 595);
$page->setFont($font, 10)
->drawText(’13 jun, 2011′, 72, 580);
$page->setFont($font, 12)
->drawText(‘Worth:’, 72, 565);
$page->setFont($ifont, 10)
->drawText(‘kr 62,900′, 72, 550);

$page->drawLine(10, 535, ($page->getWidth()-10), 535);
$page->setFont($font, 14)
->drawText(‘Auka texti her’, 230, 520);

$page->drawLine(10, 513, ($page->getWidth()-10), 513);
$page->setFont($font, 12)
->drawText(‘Leiobeiningar:’, 72, 490);

$page->setFont($font, 10)
->drawText(’1. Prentaou mioann.’, 72, 475)
->drawText(’2. Lestu Smaa letrio. Pantaou time/boro ef pess gerist porf’, 72, 460)
->drawText(’3. Kynntu inneignarmioann hja seljanda.’, 72, 445)
->drawText(’4. Skemmtu per og Njottu!’, 72, 430);

$pdf->pages[] = $page;

$pdf->save(‘example.pdf’);
echo ‘SUCCESS: Document saved!’;
} catch (Zend_Pdf_Exception $e) {
die (‘PDF error: ‘ . $e->getMessage());
} catch (Exception $e) {
die (‘Application error: ‘ . $e->getMessage());
}


Leave a Reply