Wednesday 31 October 2012

Zend Framework 2 : Send Html Mail with Simple Template

Here is my experiment with some help from my friend, how to use zend framework 2 mail component to sent mail as html. Even though we don't have any mail server or we just don't want to think of how to set mail server but with this component we could send mail easily. In this section, we will utilize a reliable smtp server like Gmail. Then we just have to have an account on the web mail to use the service for send mail.

Before we move on to the code, make sure that openssl have activated on our php.ini configuration. By doing uncomment extension=php_openssl.dll.

Let's assume that we have a module called Email with structure as below


1. Make a template for mail

In view/email directory, there's a tpl directory contains template.phtml. template.phtml file is used for our template content mail that will be sent. Actually, you can make template mail wherever you want.

template.phtml


Greetings

ini template buat email !!
2. Call Namespace Zend Component
// for email library
use Zend\Mail;
use Zend\Mime\Part as MimePart;
use Zend\Mime\Message as MimeMessage;
3. Make action on your Controller to send mail
// setup SMTP options
$options = new Mail\Transport\SmtpOptions(array(
            'name' => 'localhost',
            'host' => 'smtp.gmail.com',
            'port'=> 587,
            'connection_class' => 'login',
            'connection_config' => array(
                'username' => 'put your gmail username ',
                'password' => 'put your gmail password',
                'ssl'=> 'tls',
            ),
));
                 
$this->renderer = $this->getServiceLocator()->get('ViewRenderer');
$content = $this->renderer->render('email/tpl/template', null);

// make a header as html
$html = new MimePart($content);
$html->type = "text/html";
$body = new MimeMessage();
$body->setParts(array($html,));

// instance mail 
$mail = new Mail\Message();
$mail->setBody($body); // will generate our code html from template.phtml
$mail->setFrom('sender email address','Sender Name');
$mail->setTo('some email addressed');
$mail->setSubject('Your Subject');

$transport = new Mail\Transport\Smtp($options);
$transport->send($mail);

Tuesday 16 October 2012

Mari Menulis dengan Media Blog !

Berawal dari kebanyakan orang-orang hanya menghabiskan waktu didepan monitor dengan tidak melakukan hal yang lebih bermanfaat. Disini saya mencoba memberikan beberapa opsi dan alasan untuk mencoba sebuah kegiatan yang menarik yaitu menulis dimana salah satu media dan kegiatannya adalah nge-blog.

Jadi berikut beberapa alasan mengapa pentingnya menulis :

1. Dengan menulis kita bisa menjadi inspirasi buat yang lainnya.

Yap, menulis merupakan sarana menyebarkan inspirasi. Contoh buku "The Old New Land" yang ditulis Theodore Herzl adalah suatu buku sastra karya seorang yahudi, gara-gara buku fiksi tersebut, jutaan orang Yahudi terinspirasi untuk mendirikan sebuah negara Israel. Dimana, jutaan orang yahudi yang kala itu tersebar di berbagai belahan dunia beramai-ramai datang ke negara Islam yang terdapat kiblat pertama, Al Aqsha, Palestina. Hal tersebut merupakan hal yang luar biasa dimana cuma berawal dari pemikiran yang diwujudkan dengan tulisan dan dengan bantuan media lainnya, orang-orang yahudi tersebut berusaha mewujudkan negara tersebut hanya berawal dari tulisan fiksi. Terlepas dari konspirasi & cara mereka yang sangat tidak berperikemanusiaan dalam proses mencapai tujuan tersebut.

Zend Framework 2 : Using Classmap Generator

Since version 5, PHP has given support that very varied in OOP. One of them by overloading feature implemented on PHP 5.1.2. This feature really helps the efficiency of the writing of the code becomes more compact (so we don't need to use require or include  to load a class).

In Zend Framework 2, there is Zend\Loader\Autoloader component for autoloading of Zend Framework and your own classes. It provides functionality through two classes: StandardAutoloader and ClassMapAutoloader. here, I would explain about classmap generator that could generate Classmap Autoloader in Zend Framework .The class map autoloader its self is a high performance autoloader. It uses class maps, which are simply associative arrays of each classname to the name of the file disk that contains that class.

The contents of classmap autoloader usually like this :
   return array(
    'ZendSkeletonModule\Module'                        => __DIR__ . '/Module.php',
    'ZendSkeletonModule\Controller\SkeletonController' => __DIR__ . '/src/ZendSkeletonModule/Controller/SkeletonController.php',
    'ZendSkeletonModuleTest\Framework\TestCase'        => __DIR__ . '/tests/ZendSkeletonModule/Framework/TestCase.php',
    'ZendSkeletonModuleTest\SampleTest'                => __DIR__ . '/tests/ZendSkeletonModule/SampleTest.php',
);
The problem basically if our class in our application are pretty much. We would be getting tired and bored to write it manually. So Zend Framework 2 provides classMap generator that already exist in the vendor\ZF2\bin folder if you download ZendSkeletonApplication.

Assume that we have a structure module directory as below:


Well, the file autoload_classmap is in our module folder. So we just have to execute file ../../vendor/ZendFramework/bin/classmap_generator.php as below :
 server@server-comp:/var/www/ZendSkeletonApplication/module/Test$ php ../../vendor/ZF2/bin/classmap_generator.php -w -l ./ \ -o ./autoload_classmap.php
PHP Warning:  Module 'pdo_pgsql' already loaded in Unknown on line 0
Creating class file map for library in '/var/www/ZendSkeletonApplication/module/Test'...
Wrote classmap file to '/var/www/ZendSkeletonApplication/module/Test/autoload_classmap.php'
server@server-comp:/var/www/ZendSkeletonApplication/module/Test$ 
then if you do it correctly, the file autoload_classmap would change become like this :
 return array(
    'Test\Module'                    => __DIR__ . '/Module.php',
    'Test\Controller\TestController' => __DIR__ . '/src/Test/Controller/TestController.php',
    'Test\Model\ContohModel'         => __DIR__ . '/src/Test/Model/ContohModel.php',
);
Done !

Reference :
  1. http://samsonasik.wordpress.com/2012/03/15/zend-framework-2-classmap-generator/
  2. http://akrabat.com/zend-framework-2/using-zendloaderautoloader/

Monday 15 October 2012

Create Easy CSS3 Radio Buttons

Ever wondered how to style radio buttons, but without any JavaScript? Thanks to CSS3 you can!

Here is the way !
In this time, we will make a simple question with lists of options.
  1. HTML
    • Your Question ??
  2. CSS
  3. .list_question {
        width: 300px;
        height: auto;
        margin: 0px auto;
        background: #0096F4;
        color: #fff;
        padding: 10px;
        border-radius: 6px 6px 6px 6px;
    }
    .list_question ul li {
        list-style: decimal;
        background: none;
        padding: 0px;
        margin: 0px;
    }
    .list_question ul.choices{
        list-style: none;
        margin: 0px;
        margin-left: -35px;
        padding: 0px;
    }
    .list_question ul.choices li{
        list-style: none;
    }
    .list_question ul{
        margin: 0px;
    }
    
    /* check radio button*/
    
    .radio {
        cursor: pointer;
        display: inline-block;
        font: 15px/41px sans-serif;
        padding-right: 20px;
    }
    .radio:hover .inner {
        opacity: 0.5;
    }
    .radio input {
        display: none;
    }
    .radio input:checked + .outer .inner {
        opacity: 1;
    }
    .radio .outer {
        background:url("images/check_radio_sheet.png") -38px top no-repeat;
        display: block;
        float: left;
        margin: 10px;
        width:19px;
        height:19px;
    }
    .radio .inner {
        -moz-transition: opacity 0.5s ease 0s;
        background:url("images/check_radio_sheet.png") -57px top no-repeat;
        border-radius: 20px 20px 20px 20px;
        display: block;
        opacity: 0;
        width:19px;
        height:19px;
    }
    
    Here is my image background for radio button:


  4. Let's preview the result ! here's mine.


In this post, I also put style transition animation when the cursor hovering on the radio. Once again, it's pure css without any javascript.
Done !

Source :
  1. http://webdesign.tutsplus.com/tutorials/htmlcss-tutorials/quick-tip-easy-css3-checkboxes-and-radio-buttons/
Monday 8 October 2012

Hidup Ini

peliknya hidup ini, tergores hidup warna warni
dalam kehampaan jiwa yang sepi..
membunuh bongkahan awan hitam tersipu layu
keindahan hidup merayu merdu

dan aku terkikis debu membatu.
jiwa liar terpaku membisu
entah kemana yang ingin dituju
dengan mencari sisa kehidupan masa lalu

kilauan asam yang terpatri
berhembus alunan sampan yang tertatih
membawa angan hingga ketepian

kusodorkan bunga harapan
yang berbalaskan keresahan
dalam hati ku berdendang sepi
tapak hidup yang harus ku jalani

harapan tak pernah sirna
selama hujan mengikis keliru hati
helaian tanya ku berdoa
demi hak yang terbagi
ku genggam asa untuk masa yang abadi

aku manusia dengan ironi

Pengenalan CURL

CURL adalah suatu command line (jadi kayak command cmd ato terminal) tool yang sangat terkenal. curl memungkinkan kita melakukan komunikasi langsung dengan berbagai protokol terkenal di internet.

Curl mendukung protokol FTP (File Transfer Protocol) , FTPS (FTP/SSL), HTTP (Hyper Text Transfer Protocol), HTTPS (HTTP/SSL) , SCP (Secure Copy Protocol), SFTP (Secure FTP), TFTP (Trivial FTP), Telnet, dan sebagainya.Untuk lebih lengkapnya bisa dilihat di website CURL . Sering sekali kita sebagai programmer PHP ingin menggunakan protokol-protokol ini secara customized dan belum ada library php yang mendukungnya. Untuk itu modul curl/libcurl adalah solusi yang paling cocok untuk kita.

Setting CURL untuk Web

Untuk mengaktifkan curl pada distribusi PHP kita, maka perlu kita pastikan bahwa library curl sudah ada dan kita perlu edit file php.ini. Setting CURL distribusi php dari paket XAMPP windows. Asumsi bahwa distribusi XAMPP telah terinstall di komputer kita.
Edit file php.ini yang terdapat pada folder apache/bin/php.ini dan cari baris dengan entri seperti dibawah ini :
;extension = php_curl.dll 
kemudian di hilangkan tanda titik koma di depan sehingga menjadi
extension = php_curl.dll
Kemudian coba di test configurasi curl anda dengan menggunakan php_info() function dan lihat apakah modul curl sudah diload dengan baik. Apabila modul tersebut telah aktif maka pada informasi php_info() akan terlihat baris modul curl telah aktif.

Thursday 4 October 2012

Zend Framework 2 : Instalation and Make a Module

On 3 March 2012, Zend has released zend framework version 2.0. In zend framework 2.0, you will feel the different from previous version (Zend Framework version 1). Some of the different are zend framework 2 is more solid coding and  better performance. Btw, if you wanna try it you should use PHP version 5.3.For installing Zend Framework 2, we could clone GIT version of ZendSkeletonApplication as the basic foundation from our application.
Ok here we go.

First, clone the skeleton by using terminal or everything that could clone it :
git clone --recursive git://github.com/zendframework/ZendSkeletonApplication.git
After we clone, there must be a structure directory like this :


Tuesday 2 October 2012

Ubuntu Terminal Command

Lately, I usually use ubuntu to help doing some task on my office. Actually, I could install windows operating system on my pc, but I've decided to use and try non privacy protection software such microsoft so I consider to use open source software exactly Ubuntu for doing my job.

On ubuntu its self, we know about terminal program that functionality could execute instruction. It could be more interactive than GUI, and quicker to be executed. You can try terminal program on your ubuntu and start running some of command.

Here is the list of some useful command in terminal that you could try and use for some task, but before that you could press Ctrl+Alt+T to open Terminal .

Auto Generate Image CSS

When we would make image gallery on our site, we want every image looks neat and but sometimes to make it, we have to make a php class to generate and make it as thumbnail picture. But I have alternative solution to make gallery image neat looking without php class just by using css.

Here is a trick that could be solve the problem,

Firstly, we make an html file with div name class img_box
After that we put css code to manipulate the image and img_box div
       
    
Then here we go, we could see the preview in the browser. For example, I put my preview image like this :


source image  :
  1. http://jonasdero.deviantart.com/?rnrd=6690#/d5ff1qw
  2. http://jonasdero.deviantart.com/?rnrd=6690#/d5ewhkw 
  3. http://jonasdero.deviantart.com/?rnrd=6690#/d5gctpk

Cross Browser Font Style Using CSS3

Sometimes on our website, we want to use several even more different and particular font that doesn't installed on the operating system. The solution that usually we use for solve that problem is we use static image to display the character which use that font. But after being supported CSS3 by many browser then we could use better option by using inclusion of a particular font on the server side and accessed via css web pages.

So here's the example for call a particular font that stored on the server command with CSS3 :
@font-face {
    font-family: MyFontName;
    src: url("path/to/font.ttf")
}

Next for for, calling that fonts we could do as usual.
.style1 {
    font-family: MyFontName, Arial, Tahoma, Verdana;
}

Note : for internet explorer, font that could be used not TTF (TrueType Font) but use EOT (Embedded OpenType) format. To change font a TTF become an EOT we could use ttf2eot application that provided by google or other application. 

Reference :
  1. http://batikpress.com/2012/02/cross-browser-font-style-menggunakan-css3.html 
Monday 1 October 2012

Introduction of Zend Framework

In this session, I would like to make a post about Zend Framework.

Zend Framework is an open source php framework, that could help you to build web faster and robust. This framework was created by the company main supporters of PHP. Zend also supporting web 2.0 and cloud computing technologies.

Reason why use Zend are :
  1. Free and open source framework (licensed under the New BSD License).
  2. Extreme Simplicity.
  3. High productivity.
  4. Flexible Architecture.
  5. Supported by more than 300 contributor, include IBM and other major companies. 
You can try and use this framework by download at:  http://framework.zend.com/. On that site you also can find the framework user community. For the requirements , Zend Framework requires PHP 5.2.4 or later since version 1.7.0. Previous versions required PHP 5.1.4 or later, although the ZF Programmer's Reference Guide strongly recommended PHP 5.2.3 or later for security and performance improvements included in these versions of PHP. Zend Framework 2.0 will require PHP 5.3.3 or later. For next posting, I'll focus on Zend Framework 2.0.

Beside that, make sure that on your pc have installed web server like Apache, database server like MySQL. The most important thing is zend framework is recommended to build the web with sufficient complexity.

So let's use Zend Framework !!  :D

References :
  1. http://www.phpeveryday.com/articles/Zend-Framework-Basic-Tutorial-P840.html
  2. http://en.wikipedia.org/wiki/Zend_Framework
Copyright © 2012 Clighter | Powered by Blogger