Zend Framework: Sending Email with attachment in Zend Framework

5 Jul

You may have used Php for sending emails in your application. I haven’t experienced it in plain php, so I don’t know whether its easy or difficult. I, however, know that Zend Framework provide very easy way for sending emails. You can even attach files with your email with single method call.
In this article I am going to discuss how to send email with attachments. Please do tell me whether it helped you or not. Read more here.http://zendgeek.blogspot.com/2009/07/sending-email-with-attachment-in-zend.html

Zend Framework: building complete application using Zend_Session, Zend_Db and Zend_Auth

4 Jul

Sorry this blog is deprecated. you can read full article here.

http://zendgeek.blogspot.com/2009/07/zend-framework-building-complete.html

Well, I have written lots of separate article on Zend Framework. Hopefully most of folk out there searching for valuable help may have gotten some from my articles.
This time my objective is to share everything with you, from basic configuration till to building complete Zend Framework application.
This article will cover
1. How to make initial configuration.
2. How to use Zend_Auth for authentication
3. Using Zend_Session for handling sessions
4. What are models and how to create them
5. Using Zend_Db to handle backend database for storing valuable information.
And much more.
So let’s get started.
1. Creating directory structure and making initial configuration
Zend Framework is based on MVC design patterns. MVC stands for Model, View, Controller. A simple definition of MVC design pattern is to separate business logic from presentation logic.
In order to work with Zend Framework MVC design pattern, you’ll need to make necessary directory structure. There are various ways of making directory structure, I, however will use the most easier to create and understand structure.

The structure I created is.

html_root
    /application
        /controllers
            IndexController.php
        /models
            Users.php
        /forms
            LoginForm.php
        /views
            /scripts
                /dojo
                    index.phtml
    /libaray
        /Zend
/js
    /css
    /images
    /index.phtm

On the top level we have html_root directory, containing application directory, library, js, css and images. It also contain index.phtml called our bootstrap file. This file contain all our configuration code. Further more application directory contain controller, models forms and views directories. Library directory contains Zend components. Js contain all our js files, css contains css files and images contains all images used in our application.

Zend Framework: Storing session data in database using Zend_Session_SaveHandler_DbTable

3 Jul

In one of my previous post I wrote how to save session data in the database. The reason behind saving session data in database is that data become more secure and can be easily retrieved later on.

Let’s look how simple and easy it is to save session data in database using Zend_Session_SaveHandler_DbTable in Zend Framework.

Read full article here.http://zendgeek.blogspot.com/2009/07/zend-framework-storing-session-data-in.html

Zend Framework and Dojo: configuration

1 Jul

Sorry this blog is deprecated. read full article here.

http://zendgeek.blogspot.com/2009/06/zend-framework-and-dojo-configuration.html

Latest version of Zend framework- ZF 1.6.0 ship dojo toolkit. You can find it in ZendFramework-1.6.0/external/ directory when you download ZF.

Recently I come across a problem using third party “calendar”- Java script Calendar, and as Zend has now done collaboration with Dojo, so people using zend will definitely start using Dojo for java scripts and all other functionality Dojo is providing. And that’s why I decided to study and use Dojo and implement it in my application instead of fixing the issue in the third party calendar.

Although Zend has done excellent job and has made things quite easy for those who wish to use dojo in their applications, however novice and those with little experience may find it a bit difficult to configure Zend for Dojo.

It this post I will tell you how to configure Zend for working with Dojo.

The first and most important thing is to copy “external/dojo” into your js directory under www/public folder.

PHP: Taking care of security

28 Jun

Today highly confidential data such as credit card number, social security number etc are stored and handle through web. So it must be your primary goal to make your web application secure enough, so that users/visitor feels confident enough while using your application.

Here in this article I am going to give you some tips that are worthy to be remembered and taken care of in application development process.

  1. You may have heard about register_globals. They make PHP variables usage easy. However they have certain disadvantages such as users can easily sneak into your application by easily passing data through $_POST, $_GET or $_COOKIE etc. So you shouldn’t rely on register_global. Disable them would be nice decision.
  2. Most of the time we use variable directly, without first initializing them. For example

if (condition) {

$flag = TRUE;

}

If you don’t initialize $flag to false, user can easily set it to true using, $_POST, $_GET or $_COOKIE.

  1. Verify all incoming data before processing. Verification highly depends on the type of data. If you need to insert integer data in the database, make sure that proper data is submitted through form.
  2. Be very much careful when using function that run commands on the server. These function include exec(), passthru() and backticks (“) etc.
  3. You must change the directory where session data is stored by default. Another good approach would be to use database to store session information.
  4. When uploading file to the server, it would be good practice to rename the file(s) before storing them. Name must be safe and not guessable.
  5. Don’t reveal error on live site. Errors reveal very important information, so they must be taken care of.
  6. Take care of SQL injection. If user provides malicious information, your SQL query shouldn’t break.

Zend Framework and Dojo: a simple but complete Zend_Dojo_Form tutorial

28 Jun

sorry this blog is deprecated. visit full article here.

http://zendgeek.blogspot.com/2009/07/creating-nice-dojo-form-in-zend.html

Well, after writing few separate article about Zend Framework and dojo, I feel that I’d need to write a complete Zend_Dojo_Form. So here I am with complete example.

I am going to explain everything step by step.

1. Download Zend Framework latest version

Download least stable version from http://www.zend.com. Copy external/dojo to js/.

Hopefully you will create your directory structure as

html_root

/application

/controllers

DojoController.php

/models

/forms

CustomDojoForm.php

/views

/scripts

/dojo

index.phtml

/libaray

/Zend

/public

/js

/dojo

/css

/images

/bootstrap.php

/index.phtm

It’s not compulsory to create the similar directory structure I have created, this can vary. For best practice read Zend Quick start from Zend Framework documentation.

2. Enable dojo in the bootstrap file

I am not going to discuss everything you will need to have in your bootstrap file. I am explaining only the line of code needed to enable dojo.

Zend Framework Form: A simple but complete Zend_Form sample/tutorial

27 Jun

A sample application can be found here“.

Sorry this blog is deprecated.

“Please read complete tutorial here.” http://zendgeek.blogspot.com/2009/07/zend-framework-formzendform-tutorial.html

I got “The Zahir”, a novel by Paula Coelho about a month back, very sweat one and highly intrigued. It was highly entertaining and most importantly author shared his experiences in a nice way. I learned plenty of new ideas.

Eh, you may think that I am insane, supposed to write about Zend Framework, but discussing a novel.

Well, novel can not only be a good companion of yours, but it also put shade of light on simple things from many angles. This make you think dynamically.

If you are solving a puzzle or implementing your logic, do not think straight forward, give multiple tries and chose a more appropriate solution. Solving a problem will not be hard. You should chose a solution that require less code, small maintenance overhead and most importantly one that will be less resource intensive.

Now lets stick to the topic and discuss how you can use Zend_Form component for creating html form easily, handling filters and errors messages and how to see how easily you can fetch data from the data source and present that in html form and let the visitors change/modify the existing data and save changes to the data source.

I am gona break this topic in three steps.

1. Creating Zend_Form

Although I’ve already discussed creation of Zend_Form in some of my articles but it will be better to discuss it here again.

Creating Zend form is simple is this.

<?php

class CustomForm extend Zend_Form

{

public function init()

{

}

}

defined a class by extending it from Zend_Form. This allow access to many of methods already defined in Zend_Form.

The only thing you need to do is to override init() method and create your own element such as input box, select statement, checkboxes, radio buttons and so on.

Sorry this blog is deprecated.

“Please read complete tutorial here.” http://zendgeek.blogspot.com/2009/07/zend-framework-formzendform-tutorial.html

Zend Framework: Zend_Loader::Zend_Loader::registerAutoload is deprecated as of 1.8.0 and will be removed with 2.0.0; use Zend_Loader_Autoloader instead.

17 Jun

Sorry this blog is deprecated. you can read this article here.

http://zendgeek.blogspot.com/2009/06/zend-framework-zendloaderzendloaderregi.html

Seven things you may not know about me

3 Jun

Well, on few places I saw seven things. In the beginning I didn’t understand what it’s all about, however after searching for some time I found what the secret behind the scene was. The idea behind was to write seven things that people don’t know about you and then write about seven people in your address book, mention their names and leave links to their blogs. After doing this, leave comments on their blog or twitter telling them that they have been tagged.

Here goes my seven things.

  1. I belong to Tribal Area of Pakistan. Yes, Its been in media since many year or I’d say after 9/11, when usama bin ladin flee to Tora bora. Keep in mind that Tora bora is an area/border between Pakistan and Afghanistan.

My family is still living in tribal area, however we have a bit peaceful place, free from al-Qaida and Taliban.

  1. Pink is good and I like strawberry.
  2. I was very good soccer player. I was center forward of our college soccer team.
  3. After completing my master I tried hard to get job in Dot Net technologies, but fortunately or unfortunately got PHP job instead.
  4. I started writing my first blog in june 2008. That was in google’s blogspot.
  5. I am Capricorn; always work hard to get to the top of the mountain.
  6. I love reading novels. I am reading “The Zahir” by Paulo Coelho these days. Paulo Coelho is an author of award winning, bestseller “The Alchemist”.

And here goes seven people I know

  1. Gul Hassan

My uncle and mentor who give me strength to be where I am. An intelligent and cool person. Working as an Admin manager in government organization.

  1. James Leong:

A person who inspire me writing my own blog. A Singaporean, who came to Pakistan to establish his own business, cannot say much about him.

  1. Masood Anwar:

My team lead, who has given my lot of favors since my joining. I’ve been working with him since eight months. Full of patience and courage, think dynamically.

  1. Asim Zeeshan:

He is highly motivated, enthusiastic person. We both work in the same organization. He never hesitate in giving helping hand.

  1. Furqan Khan:

My colleague, my teammate. He is nice person and a brilliant developer. We always discuss TV program, best coming movies and other entertainment related stuff.

  1. Syed Zufliqar Hussain

He inspired me to play table tennis. He is working in Dot Net technologies, sober and courageous person. Always give his hand whenever help needed.

  1. Ahsan Shahzad:

A person writing his own blog on Zend Framework and other tool and technologies. Working in the same organization, where I am. Nice person, an intelligent engineer.

Make your children listen to you

31 May

I almost always read Sunday “dawn” and find very useful article touching heart and soul.

I think it would be worthy writing a summery about one of them and give my own opinion as well.

Today an article written by Gulrukh Tausif was fabulous. Though I am single and like to be for some time at least for some months if not years, however the tips about children she has given are worthy to be remembered and passed along in the circle.

These tips are

Let them know their boundaries

You need to tell your children what behavior is acceptable in the house and what is not.

Remind them what you want them to do and then make sure its get done on the appointed time. Parents if firm and consistent to put children to work on certain time, can easily achieved it and will get no complaint what so ever once children get used to it.

Don’t give a child a chance to argue

If your child is glued to certain task, give him an ultimatum and walk out of the room. Don’t give him chance to countermand you. Just say that I’m going out and when I’ll get in you must be on your table doing your home work.

Always mean what you say

Well, this is the most important one and I’ve seen many parents doing so. When a child cross his boundary, parents give an ultimatum that If he do the same again he will be punished, but when child repeat that again parent do nothing. This gives the child a sense that all these are idle threats. Make sure you follow what you say and what you mean.

Keep criticism to the point

Your explanation should be as short as possible, because most children cannot endure long lectures and their brain automatically tune off after the first 30 seconds or so.

I’ve seen parent giving long lecture and the end result is nothing. So stick to the point rather then a long lecture.

Modify your own behavior

If you mange to follow this tip you are half done. I’ve seen people telling children to follow rules that they even themselves don’t follow. Children learn more from your actions than from what you say. If you don’t listen to them they won’t listen to you next time. Give them full attention when they need. Next time when you need attention they would give it to you.

Explain your reasons

Nowadays children question everything and anything. Give them logical reasons instead of bossing them around. If they don’t brush their teeth or don’t concentrate on their homework, tell them pros and cons instead of crying and forcing them to do so.

Always use positive reinforcement

Praise you kid for each and every good little thing he does especially if he does it without your saying. Always say “Please” and “Thank you” and they will jump to fulfill your every command.

Listen to their problems

Your children shouldn’t be shy while telling you his problem. You must be closer to your children like his friends, so that he share everything with you. No matter how busy or tired you are, ask your children about their school, homework, teachers and classmates.

Be there for them

Put your kids need before your own. A bored, tired, hungry, sleepy or sick child is more likely to misbehave and flout your wishes. Cut shot the telephone call, switch of your TV, put down your latest best seller and see to their needs first.