Category Archives: php

Kohana 3.x Log Viewer module

Kohana Logs are a good way of debugging and monitoring application flow. It has various types of log writers for storing and showing logs. But the most commonly used one is the File Writer. One painful thing with this file logs is, downloading, reading and clearing when testing on a remote server.  To reduce this pain, I wrote a module to explore the log files on server with a beautiful interface. It may help many of you who are developing with Kohana.

You can get it from github –  https://github.com/ajaxray/Kohana-Log-Viewer

Kohana Log Viewer screenshot

Continue reading

The first Kohana book : Kohana 3.0 Beginner’s Guide

Kohana 3.0 Beginner’s Guide Cover page

Kohana 3.0 Beginner’s Guide

Codeigniter was my first PHP framework. Though it works nicely for wide range of app types, slowly I felt uncomfortable in some points. For example, lack of OOP practices, untestable structure etc. (Sorry to say, unit-testing in codeigniter was a horror!) Later, among PHP frameworks, I worked a lot with Zend Framework and a little with Symfony . One day Emran Hasan shared IBuildings article about HMVC which presented Kohana as example HMVC framework. That was the starting, in a few days Kohana took the position of primary PHP framework for me. I built website, Enterprise application, Service layer for SOA and few more apps with Kohana comfortably.

But when framework newbies asks me with which one he should start, need to think twice before suggesting Kohana. The main reason is, it’s documentation was not as rich as Codeigniter or Zend Framework. And there was no book. BTW, Kohana unofficial wiki is a BIG try to help in this issue. Besides, recently Packt has published the first book on Kohana “Kohana 3.0 Beginner’s Guide“. Jason D. Straughan wrote this book for Kohana version 3.x. Few days ago, Snehman Kohli from Packtpub has contacted me and requested for reviewing this book. As a fan of Kohana, I’ve happily accepted. So, here is my view on this book.

Continue reading

phpXperts Seminar 2010 – the most exciting event of this year!

Yesterday, we had an excellent day at phpXperts seminar. We did 6.5 hour looong event with total 18 sessions. The participants were around 350 PHP lovers and many more from live webcast. At the end of day, it was a WOW event at phpXperts 2010!

This time, my topic was about “Caching Basics in PHP”. Here is the slide -

Continue reading

Setting up Database testing with Kohana UnitTest module

Kohana Unittest module has made testing in Kohana v3 easy and fun. Lysender wrote a cool, straight forward post about how to set it up and running. I’ll just talk here about how I have set up database testing with Kohana Unittest for my personal use. Not saying “How to set up”. Because it’s obviously not the best way to do this.

Kohana Unittest

The important thing I need to ensure for testing database is, It’s in a known state before running a test. And, changes on database made by one test will not impact on another test. So, I’ll have a separate database for testing. Which will be loaded with a predefined dataset before running each test and will be truncated after test is done. Also, I have to be careful about that, my models are executing quires on test database in testing environment. Here is how I’ve done it? -

Continue reading

Taking Zend Framework workshop on Dec, 09

Bbjobs has arranged a workshop on “Zend framework fundamental” on December, 09  and invited us (me and Emran Hasan) to take it. We agreed happily. This is (so far I know) the first formal Zend Framework workshop in Bangladesh. The workshop has been defined as -

The Zend Framework Workshop is a 5 half-day tutorial-style course that takes an in-depth look at Zend Framework and its components. The workshop is designed for experienced PHP programmers who want to learn to combine ZF concepts and structural elements to utilize the full power of this software development kit for PHP 5 applications.

As per our plan about the context of this workshop, we are going to cover the following 8 basic topics of Zend Framework in 5 days.

Continue reading

Book review: PHP Team Development

PHP Team DevelopmentThree weeks ago, I was contacted by Packt publishing asking if I’d review their new book “PHP Team Development” by Samisa Abeysinghe. I agreed and received the book. But, after reading it, I was wondering about how to tell negative things politely.

In the mean time Lorna Jane, Brandon Savage, Ken Guest, Walter Ebert and some other people wrote their review about this book. And I found, most of their opinion supports my thoughts on it. Actually, most of the things that I thought has already been said in their posts. So, I am not going to repeat them and will tell my views shortly.

This book will introduce teamwork and some development processes (XP, Scrum) to fresh devs . It has brief introduction about source control, bug tracking, continuous integration and many other important terms of software development. These may help a beginner who have made software for university assignments but never worked in a professional team. The author had intention to describe the complexity and some commonly occurring problems of software development with suggesting solutions.

It presents MVC as the way of working of a team and tried to solve everything(!) with it. As some others mentioned, the author has presented his solutions as the only way of doing something. It didn’t enlighten the readers about other available solutions. Also, a few of the topics did not seem to be related with the context of this book title.

This book mentioned about many tools, processes and methods – but most of them are not explained up to such a level that one can implement them after reading the book. Some concepts of the book seemed unrealistic to me. For example, separating teams based on concern (one team will work with model, another with view; and tie them up together later).

Like Walter Ebert said, this book seems to be a “quick ‘n dirty guide on team development” to me. About recommendation, I’d say, if you are a beginner in PHP (also in programming) and just know how to connect and retrieve data from MySQL, then the book can help you know many of the terms which you should study next. If not, then you should spend some time on finding a better book to start with.

Simple PHP PDO Wrapper : light, static, easy

A few days ago, I was looking for a PDO wrapper to work with a small PHP application. I’ve searched around and found fractalizer’s PDO wrapper nearest to my purpose. Then I just wrote my wrapper on the shadow of his one.

Let’s see what’s inside and how it works.

Features

  1. Easy to use.
  2. Works with MySQL and Sqlite.
  3. All pubic functions works statically.
  4. Connection string created internally.

Get the files

From github, you can clone/fork/ download the files.
Github repository https://github.com/ajaxray/static-pdo

The download archive/repository includes -

  • Db.php – the PDO Wrapper class.
  • DbTest.php – Unit testing class for Db.
  • DbExample.php – Example of some common uses.
  • Some other unit test related files.

Continue reading

Advanced bootstrapping : Configure your Zend Framework application for multiple host

This tutorial is intended to explain a way of bootstrapping Zend Framework based MVC application for multiple host/domains. Before starting, let me explain a bit about the situation when it’s needed.

A web application goes through some stages when growing up. Generally, it starts from development and ends at production. There can be some more stages within this two ends. And, in maximum cases this stages are overlapped. The overlapped stages can be hosted in different servers with different settings but shares the same code. In this situations, if we want to keep bootstrap in SVN repo, it needs to setup bootstrap in a little different way. So that, it can handle many server settings with a single bootstrap.

For example, just now I am working on an application which is being developed in 3 local machines (me and two other members of my team) and being tested in our staging server. Besides, our client is monitoring progress of current sprint in their staging server and testing completed sprints in their pre-production server. Here, except the production servers, all hosts contains a checked out copy of code from a single repository. But this hosts have some difference in their library path, database host and authentication etc.

If my assumptions are ok for you, let’s start after downloading.

Assumptions


I have assumed that you are familiar with Zend Framework. And already worked on (atleast one) ZF MVC application. You know the basic things about bootstrapping and using the most common directory structure (shown in image). However, you can tune this technique for your favorite Zend directory stracture.

Download files

Downoad the files from here. The zip file contains -

  1. index.php – This is the bootstrap file. Your .htaccess file points all request to this file.
  2. config.xml – Contains all configurations of your application, for all hosts.
  3. Bootstrap.php – A php class that handles all startup settings in a vary organized way. (I don’t know who first wrote it, Thanks to him)

Continue reading

PunBB modification – Implementing iconized categories for forum topics

PunBB is one of the fastest and minimal forum softwares powered by PHP. PunBB says about itself:

PunBB is a fast and lightweight PHP-powered discussion board. It is released under the GNU General Public License. Its primary goals are to be faster, smaller and less graphically intensive as compared to other discussion boards. PunBB has fewer features than many other discussion boards, but is generally faster and outputs smaller, semantically correct XHTML-compliant pages.

You can see a detailed review about PunBB from forum-software.org.

What’s the purpose this mod?

PunBB has categories for forum. But there is no categorization for Topics like many other forums. This mod implements an iconized category for topics. The end result of this mod is -

  • It will add an excellent looking “Category Icons” fieldset in “Post new topic” form. (see Image#1)
  • Users can (optionally) select a topic category while posting a topic.
  • The category icon will be displayed beside the topic title in forum index page, topic detail page, search result etc. (see Image#2 and Image#3)
  • Clicking on a category icon will show all topics under that category.(see Image#4)

Lets see some screenshot of this modification :

Category icons in "Post new topic" form

Image#1:  Category icons in Post new topic form

Category icons before topic title in forum page

Image#2: Category icons before topic title in forum page

FireShot Pro capture #5 - 'User Contributed Deals _ Television is poluting our culture' - local_deals_com_forum_viewtopic_php_id=5

Image#3: Category icon in topic page

FireShot Pro capture #7 - 'User Contributed Deals _ Search results' - local_deals_com_forum_search_php_search_id=1345131291

Image#4: Filtering by category

Continue reading

Image manipulation in Zend Framework using PHP Thumbnailer Class v2.0

In the huge set of library, Zend Framework have no options for manipulating image. There is a proposal for Zend_Image which aimed to provides easier image manipulation using GD. But the proposal was not considered. Bill Karwin of ZF said,

Proposal not being considered

This proposal has been reviewed. The proposal describes functionality that is very similar to the existing PHP interfaces for ImageMagick or GD.

We are not considering this for inclusion in the Zend Framework at this time.

So, what to do when we need to make image thumbnail, resizeing or cropping image etc in Zend Framework?

The Solution

Zend Framework has the extensive power of integrating any library. So, we can use ImageMagick or GD library or any wrapper class using this libraries for manipulating image.

Here, I am explaining creating image thumbnail using PHP Thumbnailer Class v2.0 in 2 easy steps. I am assuming that, you are using Zend’s MVC with common directory structure and you’ve GD library with your PHP installation.

Step 1 – Create a Model for image manipulation :

Download the PHP5 version of PHP Thumbnailer Class v2.0 and put the class file “thumbnail.inc.php” in your model directory. Now change the file name to “Thumbnail.php” as it’s class name. Now your model is ready for action.

Step 2 – Use this model in Controller :

In your Controller, write a function to make thumbnails using this model. For example, you can use this function below:

<span style="color: #606060">   1:</span> <span style="color: #008000">/**</span>
<span style="color: #606060">   2:</span> <span style="color: #008000"> * Create thumbnail of an image</span>
<span style="color: #606060">   3:</span> <span style="color: #008000"> * </span>
<span style="color: #606060">   4:</span> <span style="color: #008000"> * @author    Anis uddin Ahmad (http://www.ajaxray.com)</span>
<span style="color: #606060">   5:</span> <span style="color: #008000"> * @param     string    Path of source image</span>
<span style="color: #606060">   6:</span> <span style="color: #008000"> * @param     string    Destination path of thumbnail</span>
<span style="color: #606060">   7:</span> <span style="color: #008000"> * @param     number    Width of thumbnail</span>
<span style="color: #606060">   8:</span> <span style="color: #008000"> * @param     number    Height of thumbnail</span>
<span style="color: #606060">   9:</span> <span style="color: #008000"> * @param     number    (optional) thumbnail image quality </span>
<span style="color: #606060">  10:</span> <span style="color: #008000"> */</span>
<span style="color: #606060">  11:</span>
<span style="color: #0000ff">private</span> <span style="color: #0000ff">function</span> _createThumbnail($sourcePath, $destPath, $w, $h, $q = 100)
<span style="color: #606060">  12:</span>  {
<span style="color: #606060">  13:</span>     $thumb = <span style="color: #0000ff">new</span> Thumbnail($sourcePath);
<span style="color: #606060">  14:</span>     $thumb-&gt;resize($w, $h);
<span style="color: #606060">  15:</span>     $thumb-&gt;save($destPath, $q);
<span style="color: #606060">  16:</span>  }

Done. Now you can use this function to resize/make thumbnail of an image. To resize an image with keeping it’s original name, pass the $sourcePath again in $destPath parameter. Then it will overwrite the existing image.

So, was it so though to manipulate image in ZF?