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

Follow

Get every new post delivered to your Inbox.

Join 33 other followers