Tuesday, 17 March 2015

What is stdClass? and How to create stdClass class?

What is stdClass class?
stdClass is Generic empty class in PHP.
OR
stdClass is universal base class in PHP.



Question: Why stdClass class is used?
stdClass is used to create anonymous objects with properties.



Question: Where it is used?
When we need to create an object without having new class. then we used stdClass class which is inbuilt in PHP.
After create object, we can add properties.



Question: How to create stdClass class?
$object=new stdClass();



Question: Can we set different variables in StdClass?
Yes, We can do both get and set.
See Example Below:
//First, create an object with use of stdClass
$object=new stdClass();

//Set new variables in $object 
$object->name='Web Technology Experts Notes';
$object->url='web-technology-experts-notes.in';

//Get the variables values
echo $object->name;
echo $object->url;



Monday, 16 March 2015

How to send an email using Email Template in Zend Framework

How to send an email using Email Template in Zend Framework

Email functionalities in websites is very common and used in mostly in all web application. Whether it is registration process or Order detail, we need to send an email to your valuable client.

To send the email using Email Template follow the following steps
1. First collect all the data which you want to send in Email like first name, last name etc.
$emailTemplateData = array('fname'=>'Web Technology','lname'=>'Experts Notes');


2. Create a Folder with name emails, where you can put the email templates files.
Email template Location: application/views/scripts/emails


3. Create a template with name registration.phtml  for registration Email and add following contents.
First name:  echo $data['fname'];  
Last name:   echo $data['fname'];  
Folder Location: application/views/scripts/emails
Don't forget to add php scripts for php variable
Im just giving you an working code, you can add lot of variables as you need.


Add following code from where you want to send an email
$subject ='This is subject';
$view = new Zend_View();
$view->addScriptPath(APPLICATION_PATH . '/views/scripts/emails');
$view->data = $emailTemplateData; //$emailTemplateData must have the values which you are using in registration.phtml
$emailHtml = $view->render('registration.phtml');
$mail = new Zend_Mail();
$mail->setBodyHtml($emailHtml);
$mail->setSubject($subject);              
$mail->setFrom("support@example.com", "From domain.com");
$mail->send();


If you get an issue regarding this post, Please comment below. we will try to fix your problem.