Bangali Web design tutorials

Hello Academy's Profile Photo
Hello Academy  provide free web design tutorials in bangali language.  Anybody who doesn’t have any programming language knowledge can now develop web site easily with those tutorials. Here I add those YouTube links step by steps:

Basic web design:

1. গল্পে গল্পে ওয়েব ডিজাইনের ১ম পর্ব (ওয়েব ডিজাইনের শুরুর গল্প)

2. গল্পে গল্পে ওয়েব ডিজাইনের ২য় পর্ব (ওয়েব ডিজাইনের হাতেখড়ি-১ )

3. গল্পে গল্পে ওয়েব ডিজাইনের ৩য় পর্ব (ওয়েব ডিজাইনের হাতেখড়ি-১ )

4.গল্পে গল্পে ওয়েব ডিজাইনের ৪থ পর্ব (ওয়েব ডিজাইনের হাতেখড়ি-২ )

5.গল্পে গল্পে ওয়েব ডিজাইনের ৫ম পর্ব (ওয়েব ডিজাইনের হাতেখড়ি-৩ )

6.গল্পে গল্পে ওয়েব ডিজাইনের ৬ষঠ পর্ব (কমেন্টস এর গল্প )

7.গল্পে গল্পে ওয়েব ডিজাইনের ৭ম পর্ব (রেস্পন্সিভ এর গল্প )

PSD to HTML Basic:

8. গল্পে গল্পে ওয়েব ডিজাইনের ৮ম পর্ব (Psd to Html করার সাহসী গল্প part-1)

9. গল্পে গল্পে ওয়েব ডিজাইনের ৯ম পর্ব (Psd to Html করার সাহসী গল্প part-2)

10. গল্পে গল্পে ওয়েব ডিজাইনের ১০ম পর্ব (Psd to Html করার সাহসী গল্প part-3)

11. গল্পে গল্পে ওয়েব ডিজাইনের ১১তম পর্ব (Psd to Html করার সাহসী গল্প part-4)

12. গল্পে গল্পে ওয়েব ডিজাইনের ১২তম পর্ব (Psd to Html করার সাহসী গল্প part-5)

13. গল্পে গল্পে ওয়েব ডিজাইনের ১৩তম পর্ব (Psd to Html করার সাহসী গল্প part-6)

14. গল্পে গল্পে ওয়েব ডিজাইনের ১৪ তম পর্ব (রেস্পন্সিভ part-7)

Bootstrap basic:

১/ বুটিসট্র্যাপ বেসিক টিউটোরিয়াল ১ম পর্ব (প্রাথমিক ধারণা)

২/ বুটিসট্র্যাপ বেসিক টিউটোরিয়াল ২য় পর্ব (ড্রপডাউন মেন্যু)

৩/ বুটিসট্র্যাপ বেসিক টিউটোরিয়াল ৩য় পর্ব (স্লাইডার)

৪/ বুটিসট্র্যাপ বেসিক টিউটোরিয়াল ৪র্থ পর্ব (accordion)

Web Design Advance with Bootstrap-PSD to HTML with Bootastrap:

১/ বুটিসট্র্যাপ দিয়ে PSD to HTML (১ম পর্ব)

২/ বুটিসট্র্যাপ দিয়ে PSD to HTML (২য় পর্ব)

৩/ বুটিসট্র্যাপ দিয়ে PSD to HTML (৩য় পর্ব)

৪/ বুটিসট্র্যাপ দিয়ে PSD to HTML (৪র্থ পর্ব)

৫/ বুটিসট্র্যাপ দিয়ে PSD to HTML (৫ম পর্ব)

৬/ বুটিসট্র্যাপ দিয়ে PSD to HTML (৬ষ্ঠ পর্ব)

৭/ বুটিসট্র্যাপ দিয়ে PSD to HTML (৭ম পর্ব)

৮/ বুটিসট্র্যাপ দিয়ে PSD to HTML (৮ম পর্ব)

৯/ বুটিসট্র্যাপ দিয়ে PSD to HTML (৯ম পর্ব)

১০/ বুটিসট্র্যাপ দিয়ে PSD to HTML (১০ম পর্ব)

১১/ বুটিসট্র্যাপ দিয়ে PSD to HTML (১১তম পর্ব)

১২/ বুটিসট্র্যাপ দিয়ে PSD to HTML (১২তম পর্ব)

jQuery basic:

1/জেকুএরির ১ম পর্ব

2/জেকুএরির ২য় পর্ব

3/জেকুএরির ৩য় পর্ব

4/জেকুএরির ৪থ পর্ব

5/জেকুএরির ৫ম পর্ব

6/জেকুএরির ৬ষঠ  পর্ব

 7/জেকুএরির ৭ম  পর্ব

PHP Basic:

১/ PHP ১ম পর্ব (Introduction)

২/ PHP ২য় পর্ব (Data Types & Variables)

৩/ PHP ৩য় পর্ব (Arithmatic Operatos)

৪/ PHP ৪র্থ পর্ব (Assignment operator)

৫/ PHP ৫ম পর্ব (Logical Operator-1)

৬/ PHP ৬ষ্ঠ পর্ব (Logical Operator-2)

৭ / PHP ৭ম পর্ব (Index Array)

৮/ PHP ৮ম পর্ব (Associative Array)

৯/ PHP ৯ম পর্ব (Multidimensional Array)

১০/ PHP ১০ম পর্ব (For loop)

১১/ PHP ১১তম পর্ব (While loop)

১২ / PHP ১২তম পর্ব (Foreach loop)

How to prepare ur Macbook for webdev

Install XAMPP:At first u have to download XAMPP for Mac OS X from this link and install as per their suggestion:http://www.apachefriends.org/en/xampp-macosx.html
installing XDebug on Mac OS X’s default PHP installation:
1. You are going to need to  download the source code from the XDebug website. (I suggest into your “Downloads” folder to make the rest of the process easier.
2. Unzip the archive from the finder.
3. Open up the Terminal, paste the following command in and hit enter: cd ~/Downloads/xdebug-2.0.3/xdebug-2.0.3/
4. Do the same for this command: phpize
5. This one too: MACOSX_DEPLOYMENT_TARGET=10.5 CFLAGS=”-arch ppc -arch ppc64 -arch i386 -arch x86_64 -g -Os -pipe -no-cpp-precomp” CCFLAGS=”-arch ppc -arch ppc64 -arch i386 -arch x86_64 -g -Os -pipe” CXXFLAGS=”-arch ppc -arch ppc64 -arch i386 -arch x86_64 -g -Os -pipe” LDFLAGS=”-arch ppc -arch ppc64 -arch i386 -arch x86_64 -bind_at_load” ./configure –enable-xdebug
6. And finally this one: make
7. We have just compiled the xdebug module. We now need to copy the compiled file binary file into a place where PHP can find it. From the terminal (again) run the following command: cp modules/xdebug.so /usr/lib/php/extensions/no-debug-non-zts-20060613/
8. Finally we need to edit the /etc/php.ini file so that PHP is aware of the new module. From the terminal run this command: open /etc/. This will open the /etc folder in the Finder allowing you to right-click on the php.ini file and open it in your preferred text-editor (TextEdit or TextMate for example).
9. At the very bottom of that file add the following:
zend_extension=/usr/lib/php/extensions/no-debug-non-zts-20060613/xdebug.so
xdebug.file_link_format = “txmt://open?url=file://%f&line=%l”
xdebug.remote_enable=1
xdebug.remote_host=localhost
xdebug.remote_port=9000
xdebug.remote_autostart=1
10. In the terminal, for the last time (I promise), run the command: apachectl restart or simply restart your computer.

Now for installation test create a PHP script with a pile of errors in it and you should see colourful error messages when run in a browser (as apposed to plain old black and white text). Or you can download something like MacGDBp – a native debugging application for the Mac.

Display images in CakePHP

Today I face a problem as a beginner of CakePHP …How can I display image button with link in Cake. I wanted to use images as my buttons to edit and delete records and  navigate the admin pages.

1. Have to use HTML Helpers Image and Link, and we shall combine this 2. The CakePHP link helper is a handy tool to create links in your application. Here is the basic syntax:

<?php echo $html->link(’help!’,’/help’); ?>

And there’s a helper for creating images, too:

<?php echo $html->image(’add.gif’); ?>

Show HTML code of the image as the link:

<?php echo $html->link($html->image(’add.gif’),’/customers/add’)?>

2. For Image,
Syntax:

$html->image(string $path, array $htmlAttributes, boolean $return = false);

Example:

$html->image(’/img/images/cancel.png’, array(’class’ => ’save_button’));
3. For Link, the Syntax:

$html->link(string $title, string $url, array $htmlAttributes, string $confirmMessage = false, boolean $escapeTitle = true, boolean $return = false);

Example:

$html->link(’SAVE’, ‘/registers’, array(), false, false, false);

4. So to make an image clickable,

<?php echo $html->link($html->image(’/img/images/cancel.png’,array(’class’ => ’save_button’)), ‘/registers’, array(), false, false, false); ?>

And the best code is:
<?php echo $html->link($html->image(’add.gif’),’/customers/add’,array(’escape’=>false))?>

Hope it will help you to save time.

Top sites in CakePHP

CakePHP is a rapid development framework for PHP that provides an extensible architecture for developing, maintaining, and deploying applications. Using commonly known design patterns like MVC and ORM within the convention over configuration paradigm, CakePHP reduces development costs and helps developers write less code. Wanna learn CakePHP…..You have to find best sites on it. Given below are some of them:

1. CakeForge: CakeForge is a free service provided to Open Source developers offering easy access to the best in SVN, mailing lists, bug tracking, message boards/forums, task management, site hosting, permanent file archival, full backups, and total web-based administration.

2. CakePHP :It is most popular site for download, install and learn CakePHP.

3. Cakebaker:a rich site on Cake to bake. Learning a new framework should help me to grow as a developer.

4. CakePHP Bakery: Here u find resources, articles and much more… dont miss it.

5. Cakephp.nu:have some tutorials on Cake.

6. Cake for Beginners: article on style sheets.

7. 21 Things I Learned About CakePHP: Its really a nice one to learning.

8. The CakePHP Framework: A SitePoint Tutorial:

Can know the CakePHP’s Approach to the MVC Architecture

9. Cake.Insert Design Here: its features are:

10. Moving To CakePHP: another resource on Cakephp.

Lets enjoy the tour….

Using Style sheets in CakePHP

https://i1.wp.com/squio.nl/blog/wp-content/2008/02/cake12b.png

Recently I’m start working with CakePHP for one of my official project ‘The Bangabhaban website’. This is my second local project. First one was ‘votebd.com’ developed with CodeIgniter. I’m very happy to being developer of such a project. Lets happy starting.
I had to develop a template for demo purpose. here I discussed some CSS related problem solving tricks:
1. External Style Sheets: For access all images and style sheets you have to add following codes into .htaccess file.

RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^(.*)$ – [L]

2. AssetHelper: is a great  helper for
CSS and JS compression. You can find it in http://www.pseudocoder.com .

3. CSS Tidy: is an opensource CSS parser and optimiser. CSSTidy has full CSS2 support and a higher reliability. Any way to configure the helper and/or CSS Tidy to just combine all of
my CSS files into one:

$this->settings[‘remove_bslash’] = false;
$this->settings[‘compress_colors’] = false;
$this->settings[‘compress_font-weight’] = false;
$this->settings[‘lowercase_s’] = false;
$this->settings[‘optimise_shorthands’] = 0;
$this->settings[‘remove_last_;’] = false;
$this->settings[‘case_properties’] = 0;
$this->settings[‘sort_properties’] = false;
$this->settings[‘sort_selectors’] = false;
$this->settings[‘merge_selectors’] = 0;
$this->settings[‘discard_invalid_properties’] = false;
$this->settings[‘css_level’] = ‘CSS2.1’;
$this->settings[‘preserve_css’] = true;
$this->settings[‘timestamp’] = false;

The votebd.org website

votebd.org site

The votebd.org site

In the governance of a country, it is very important in this age to be informed about the people who will be running the country and representing it. Shushashoner Jannoy Nagorik’s Votebd.org does exactly this. Votebd.org tracks all the information related to contesting politicians and makes it available to people of Bangladesh. This is an effort in the direction of reducing corruption by making use of technology for transparency. In the past, even the voter list was not available to the common people. Shujan made the voter list available through this web site. Hopefully, an improvement in the political solution may eventually encourage an environment for honest, competent and devoted persons to join the politics.

Description:

Democracy is a government of the people, for the people, by the people. But do we have a medium to turn this theory into a practical reality. The website http://www.votebd.org has been developed for this purpose, to disseminate the personal information of the candidate who will contest in the local and national elections among the voters. Ironically, this effort is happening in Bangladesh. The information disseminated are educational qualification, criminal records (present and past), statements of assets and liabilities of candidates and dependents, profession, loan from bank and financial institutions, statement of income tax returns, source of election expenses, statement of actual election expenses etc. In addition, about 2,500 news published in the leading national dailies on corruption and criminalization made by politician, businessmen, government officials and others also posted in this site. It is being regularly updated.

Site link: http://www.votebd.org/

One of my projects Votebd.org won the Manthan Award 2008

Manthan Award 2008

Manthan Award 2008

Hi friends,

Hurrah! We have won the award. We deserved it. Its also a very good news for Bangladesh. One of my projects Votebd.org won the Manthan Award 2008 on E-Governance category. Bangladesh won five more awards- Roobon received more 2 awards on behalf of ankur and Unnayan TV. We had a big pavilion, hadn’t much logistics and not well furnished. Though we had a poor participation, we won 6 awards. It is really tremendous.

Roobon in the pavilion with Osama Manzar, the founder of Manthan

Roobon in the pavilion with Osama Manzar, the founder of Manthan

Address is:http://votebd.org/

Manthan Award 2008 News Links:

News in Gulf-Times
http://www.gulf-times.com/site/topics/article.asp?cu_no=2&item_no=249411&version=1&template_id=44&parent_id=24

The Daily Star of Bangladesh
http://www.thedailystar.net/pf_story.php?nid=59806

Prothom Alo
http://www.prothom-alo.com/index.news.details.php?nid=MTk1MzQ=

Unnayan News of Bangladesh
http://www.unnayannews.net/?p=783

Financial News of Bangladesh
http://www.thefinancialexpress-bd.info/search_index.php?page=detail_news&news_id=48626

Award committee have posted some photos and description.
http://manthanaward.org/index.asp
http://manthanaward.org/section_full_story.asp?id=652

Posted a news in Techtunes

http://techtunes.com.bd/news/tune-id/1561/

The Daily Ittefaq (IT page)- 24.10.2008
The Daily Sangbad (IT page)- 25.10.2008
The Daily Naya Diganta (IT Corner)- 25.10.2008
The Daily Amar Desh (IT corner)- 26.10.2008

For learn more please visit: www.manthanaward.org

Top open-source version control systems

Version control is an excellent way to allow unlimited number of people working on the same code base, without having to constantly send files back and forth. Designers and developers can both benefit from using such systems to keep copies of their files and designs. They can revert to earlier versions if something happens. Here I discuss some popular version control systems:

CVS is the Concurrent Versions System, the dominant open-source network-transparent version control system. It was first released in 1986. CVS is the de facto standard and is installed virtually everywhere. It’s useful for any designer or developer for backing up and sharing files. Tortoise CVS is a great client for CVS on Windows, and there are many different IDEs, such as Xcode (Mac), Eclipse, NetBeans and Emacs, that use CVS.

SVN or Subversion is the most popular version control system. Most open-source projects (SourceForge, Apache, Python, Ruby and many others) use it as a repository. Google Code uses Subversion exclusively to distribute code. For Windows, Tortoise SVN is a great file browser for viewing, editing and modifying your Subversion code base. For Mac, you have to use Versions. For Apple’s developer environment you have to use Xcode.

Bazaar have a very friendly user experience. It supports many different types of workflows, from solo to centralized to decentralized, with many variations in between. People have used it to version pretty much anything: single-file projects, your /etc directory and even the thousands of files and revisions in the source code for Launchpad, MySQL and Mailman. You can use it to fit almost any scenario of users and setups. It’s easy to modify and also embeddable, so you can add it to existing projects. Bazaar runs on GNU/Linux, UNIX, Windows and OS X out of the box. Bazaar is friendly, smart, fast, lightweight, extensible, embeddable, safe and free. Lists of plug-ins for Bazaar that are available under a free software license are given their plug-ins page. The page UsingPlugins gives detailed explanations about the plugin concept and installation instructions for plugins.

Git is a distributed version control systems initially developed by Linux kernel creator Linus Torvalds. Different branches hold different parts of the code instead one centralized code base to pull the code from. Git prides itself on being a fast and efficient system, and many major open-source projects use Git to power their repositories like Linux Kernel, Ruby on Rails, WINE, Fedora, X.org, Rubinius, and VLC etc. Git is used for version control of files, much like tools such as Mercurial, Subversion, CVS, Perforce, Bitkeeper, and Visual SourceSafe. GitHub has recently helped establish Git as a great version control system. It’s much harder to use for a beginner.

Mercurial is a cross-platform, distributed revision control tool for software developers. It was designed for larger projects, most likely outside the scope of designers and independent Web developers. It is extremely fast, and the creators built the software with performance as the most important feature. It’s easy to use because it’s functions are similar to those in other CVS systems. The creator and lead developer of Mercurial is Matt Mackall. Mercurial was initially written to run on Linux. It has been ported to Windows, Mac OS X, and most other Unix-like systems. Some projects using the Mercurial distributed RCS are Aldrin, Audacious, Dovecot IMAP server, Growl, MoinMoin wiki software, Mozilla, Netbeans, OpenJDK, SAGE and Sun’s OpenSolaris.

LibreSource is a versatile collaborative platform. It is used to manage collaborative projects. Open Source, modular and highly customizable, LibreSource is adapted to collaborative software development (forge), groupware, community leading, e-archiving and Web publishing. It has built-in features such as Wiki pages, forums, trackers, Synchronizers, Subversion repositories, files, download areas, drop boxes, forms, instant messaging and more. LibreSource is perfect for the developer or designer who doesn’t want to learn lots of technical jargon and wants to focus more on communication with the project’s members. LibreSource uses most of the advanced services provided by the ObjectWeb application server called JOnAS. Effective communication is a fundamental requirement for agile project management. LibreSource includes a Software Configuration Management tool called LibreSource Synchronizer which is innovative, simple and united. LibreSource simplifies the creation of a dynamic community and help to maintain and enhance team relationship in order to improve the cooperative efficiency. Just install the package and start collaborating.

Monotone is another distributed revision control system. Monotone is fairly easy to learn if you’re familiar with CVS systems, and it can import previous CVS projects.

Source Jammer is a source control and versioning system written in Java. It consists of a server-side component that maintains the files and version history, and handles check-in, check-out, etc. and other commands; and a client-side component that makes requests of the server and manages the files on the client-side file system. SourceJammer is coded in 100% Java, so it is platform independent.

GNU arch is a distributed revision control system that is part of the GNU Project and licensed under the GNU General Public License. It is used to keep track of the changes made to a source tree and to help programmers combine and otherwise manipulate changes made by multiple people or at different times. Being a distributed, decentralized versioning systems, each revision in GNU arch is uniquely globally identifiable; such identifier can be used in a distributed setting to easily merge or cherry-pick changes from completely disparate sources. Its other features are Atomic commits, Changeset oriented, easy branching, advanced margin, cryptographic signature, renaming and metadata tracking.

Version control Tools:

Design Pattern in PHP5- Abstract Factory

Abstract Factory:

A software design pattern, the Abstract Factory Pattern provides a way to encapsulate a group of individual factories that have a common theme. In normal usage, the client software would create a concrete implementation of the abstract factory and then use the generic interfaces to create the concrete objects that are part of the theme. The client does not know (or care) about which concrete objects it gets from each of these internal factories since it uses only the generic interfaces of their products. This pattern separates the details of implementation of a set of objects from its general usage.

How to use it:

Class diagram of Amazon Online Book Shop:

In this example we have an abstract factory, AbstractBookFactory, that specifies two classes, AbstractPHPBook and AbstractMySQLBook, which will need to be created by the concrete factory.

The concrete class OReillyBookfactory extends AbstractBookFactory, and can create the OReillyMySQLBook and OReillyPHPBook classes, which are the correct classes for the context of OReilly. Thanks goes to FluffyCat.com as their article helps me a lot.

Examples Codes given below:

AbstractBookFactory.php

  abstract class AbstractBookFactory {

    abstract function makePHPBook();

    abstract function makeMySQLBook();

  }
download source, use right-click and “Save Target As…” to save with a .php extension.

OReillyBookFactory.php

  include_once('AbstractBookFactory.php');

  include_once('OReillyPHPBook.php');
  include_once('OReillyMySQLBook.php');

  class OReillyBookFactory extends AbstractBookFactory {

    private $context = "OReilly";  

    function makePHPBook() {return new OReillyPHPBook;}

    function makeMySQLBook() {return new OReillyMySQLBook;}

  }
download source, use right-click and “Save Target As…” to save with a .php extension.

SamsBookFactory.php

  include_once('AbstractBookFactory.php');

  include_once('SamsPHPBook.php');
  include_once('SamsMySQLBook.php');

  class SamsBookFactory extends AbstractBookFactory {

    private $context = "Sams";   

    function makePHPBook() {return new SamsPHPBook;}

    function makeMySQLBook() {return new SamsMySQLBook;}

  }
download source, use right-click and “Save Target As…” to save with a .php extension.

AbstractBook.php

    abstract class AbstractBook {

    abstract function getAuthor();

    abstract function getTitle();

    abstract function getPicture();
 }
download source, use right-click and “Save Target As…” to save with a .php extension.

AbstractMySQLBook.php

    include_once('AbstractBook.php');

    abstract class AbstractMySQLBook {

    private $subject = "MySQL";

  }
download source, use right-click and “Save Target As…” to save with a .php extension.

OReillyMySQLBook.php

  include_once('AbstractMySQLBook.php');

  class OReillyMySQLBook extends AbstractMySQLBook {

    private $author;

    private $title;

    private $picture;

 function __construct() {

      $this->author = 'George Reese, Randy Jay Yarger, and Tim King';
      $this->title  = 'Managing and Using MySQL';
      $this->picture = 'images/book3.jpg';
    }

    function getAuthor() {return $this->author;}

    function getTitle() {return $this->title;}

    function getPicture() {return $this->picture;}
  }
download source, use right-click and “Save Target As…” to save with a .php extension.

SamsMySQLBook.php

  include_once('AbstractMySQLBook.php');

  class SamsMySQLBook extends AbstractMySQLBook {

    private $author;

    private $title;

    private $picture;

 function __construct() {

      $this->author = 'Paul Dubois';
      $this->title  = 'MySQL, 3rd Edition';
      $this->picture = 'images/book6.jpg';
    }

    function getAuthor() {return $this->author;}

    function getTitle() {return $this->title;}

    function getPicture() {return $this->picture;}
 }
download source, use right-click and “Save Target As…” to save with a .php extension.

AbstractPHPBook.php

    include_once('AbstractBook.php');

    abstract class AbstractPHPBook {

    private $subject = "PHP";

  }
download source, use right-click and “Save Target As…” to save with a .php extension.

OReillyPHPBook.php

  include_once('AbstractPHPBook.php');

  class OReillyPHPBook extends AbstractPHPBook {

    private $author;

    private $title;

    private $picture;

    private static $oddOrEven = 'odd';

    function __construct() {

      //alternate between 2 books

      if ('odd' == self::$oddOrEven) {
        $this->author = 'Rasmus Lerdorf and Kevin Tatroe';
        $this->title  = 'Programming PHP';
        $this->picture = 'images/book2.jpg';
        self::$oddOrEven = 'even';
      } else {
        $this->author = 'David Sklar and Adam Trachtenberg';
        $this->title  = 'PHP Cookbook';
        $this->picture = 'images/book1.jpg';
        self::$oddOrEven = 'odd';
      }
    }

    function getAuthor() {return $this->author;}

    function getTitle() {return $this->title;}

    function getPicture() {return $this->picture;}
 }
download source, use right-click and “Save Target As…” to save with a .php extension.

SamsPHPBook.php

  include_once('AbstractPHPBook.php');

  class SamsPHPBook extends AbstractPHPBook {

    private $author;

    private $title;

    private $picture;

   function __construct() {

      //alternate randomly between 2 books

      mt_srand((double)microtime()*10000000);
      $rand_num = mt_rand(0,1);      

      if (1 > $rand_num) {
        $this->author = 'George Schlossnagle';
        $this->title  = 'Advanced PHP Programming';
        $this->picture = 'images/book4.jpg';
      } else {
        $this->author = 'Christian Wenz';
        $this->title  = 'PHP Phrasebook';
        $this->picture = 'images/book5.jpg';
      }
    }

    function getAuthor() {return $this->author;}

    function getTitle() {return $this->title;}

    function getPicture() {return $this->picture;}
 }
download source, use right-click and “Save Target As…” to save with a .php extension.

testAbstractFactory.php

  <?php

  include_once('OReillyBookFactory.php');
  include_once('SamsBookFactory.php');

  echo tagins("html");
  echo tagins("head");
  echo tagins("/head");
  echo tagins("body");
//
echo '<img src="images/header.gif" width="100%">';
//
  echo "<h3>Amazon Online Book Shop</h3>";
  echo tagins("br");

  echo 'All OReillyBooks'.tagins("br");
  $bookFactoryInstance = new OReillyBookFactory;
  testConcreteFactory($bookFactoryInstance);

  echo tagins("br");

  echo 'All SamsBooks Factory'.tagins("br");
  $bookFactoryInstance = new SamsBookFactory;
  testConcreteFactory($bookFactoryInstance);  

  echo tagins("br");
  echo "";
  echo tagins("br");
  //
	echo '<img src="images/footer-toptile.gif">';
//
  echo tagins("/body");
  echo tagins("/html");

  function testConcreteFactory($bookFactoryInstance) {
    $phpBookOne = $bookFactoryInstance->makePHPBook();
    echo '<img src="'.$phpBookOne->getPicture().'">'.tagins("br");
    echo 'Author: '.
	  $phpBookOne->getAuthor().tagins("br");
    echo 'Title: '.
	  $phpBookOne->getTitle().tagins("br");
//
	echo '<p class="MsoNormal" style="text-align: center;
line-height: 12pt; margin-top: 2px; 

margin-bottom: 2px;"><span style="font-family: Verdana;
 font-size: xx-small;"> <a 

href="http://www.edutechindia.org/currency.asp?id=1&amp;catid=
1&amp;p=m"> Add to Cart 

</a></span></p>';
//
    $phpBookTwo = $bookFactoryInstance->makePHPBook();
    echo '<img src="'.$phpBookTwo->getPicture().'">'.tagins("br");
    echo 'Author: '.
	  $phpBookTwo->getAuthor().tagins("br");
    echo 'Title: '.
	  $phpBookTwo->getTitle().tagins("br");
    //
	echo '<p class="MsoNormal" style="text-align: center;
line-height: 12pt; margin-top: 2px; 

margin-bottom: 2px;"><span style="font-family: Verdana;
font-size: xx-small;"> <a 

href="http://www.edutechindia.org/currency.asp?id=1&amp;catid=
1&amp;p=m"> Add to Cart 

</a></span></p>';
//
	$mySqlBook = $bookFactoryInstance->makeMySQLBook();
   echo '<img src="'.$mySqlBook->getPicture().'">'.tagins("br");
    echo 'MySQL Author: '.
	  $mySqlBook->getAuthor().tagins("br");
    echo 'MySQL Title: '.
	  $mySqlBook->getTitle().tagins("br");
//
	echo '<p class="MsoNormal" style="text-align: center;
line-height: 12pt; margin-top: 2px; 

margin-bottom: 2px;"><span style="font-family: Verdana; font-size:
 xx-small;"> <a 

href="http://www.edutechindia.org/currency.asp?id=1&amp;catid=
1&amp;p=m"> Add to Cart 

</a></span></p>';
//
  }

  //doing this so code can be displayed without breaks
  function tagins($stuffing) {
    return "<".$stuffing.">";
  }

?>
download source, use right-click and “Save Target As…” to save with a .php extension.

output of testAbstractFactory.php

DESIGN PATTERNS in PHP

In software engineering, a design pattern is a general reusable solution to a commonly occurring problem in software design. The advantage of knowing and using these patterns is save time as well as give developers a common language in software design. Here I discuss the implementation of some common design patterns that are easily adapted to PHP.

1. Strategy Pattern:

The strategy pattern is typically used when your programmer’s algorithm
should be interchangeable with different variations of the algorithm. For
example, if you have code that creates an image, under certain circumstances, you might want to create JPEGs and under other circumstances, you might want to create GIF files.
The strategy pattern is usually implemented by declaring an abstract
base class with an algorithm method, which is then implemented by inheriting concrete classes. At some point in the code, it is decided what concrete strategy is relevant; it would then be instantiated and used wherever relevant.
Our example shows how a download server can use a different file selection
strategy according to the web client accessing it. When creating the
HTML with the download links, it will create download links to either .tar.gz
files or .zip files according to the browser’s OS identification. Of course, this
means that files need to be available in both formats on the server. For simplicity’s sake, assume that if the word “Win” exists in $_SERVER[“HTTP_
USER_AGENT”], we are dealing with a Windows system and want to create .zip
links; otherwise, we are dealing with systems that prefer .tar.gz.
In this example, we would have two strategies: the .tar.gz strategy and
the .zip strategy, which is reflected as the following strategy hierarchy (see
Figure 1).


Figure 1: Strategy hierarchy.

The following code snippet should give you an idea of how to use such a
strategy pattern:
abstract class FileNamingStrategy {
abstract function createLinkName($filename);
}
class ZipFileNamingStrategy extends FileNamingStrategy {
function createLinkName($filename)
{
return “http://downloads.foo.bar/$filename.zip&#8221;;
}
}
class TarGzFileNamingStrategy extends FileNamingStrategy {
function createLinkName($filename)
{
return “http://downloads.foo.bar/$filename.tar.gz&#8221;;
}
}
if (strstr($_SERVER[“HTTP_USER_AGENT”], “Win”)) {
$fileNamingObj = new ZipFileNamingStrategy();
} else {
$fileNamingObj = new TarGzFileNamingStrategy();
}
$calc_filename = $fileNamingObj->createLinkName(“Calc101”);
$stat_filename = $fileNamingObj->createLinkName(“Stat2000″);
print <<<EOF
<h1>The following is a list of great downloads<</h1>
<br>
<a href=”$calc_filename”>A great calculator</a><br>
<a href=”$stat_filename”>The best statistics application</a><br>
<br>
EOF;
Accessing this script from a Windows system gives you the following
HTML output:
<h1>The following is a list of great downloads<</h1>
<br>
<a href=”http://downloads.foo.bar/Calc101.zip”>A great calculator<
/a><br>
<a href=”http://downloads.foo.bar/Stat2000.zip”>The best statistics
application</a><br>
<br>

Tip: The strategy pattern is often used with the factory pattern, which is
described later in this section. The factory pattern selects the correct strategy.

2. Singleton Pattern:
The singleton pattern is probably one of the best-known design patterns.
You have probably encountered many situations where you have an object that
handles some centralized operation in your application, such as a logger
object. In such cases, it is usually preferred for only one such application-wide
instance to exist and for all application code to have the ability to access it.
Specifically, in a logger object, you would want every place in the application
that wants to print something to the log to have access to it, and let the centralized
logging mechanism handle the filtering of log messages according to
log level settings. For this kind of situation, the singleton pattern exists.
Making your class a singleton class is usually done by implementing a
static class method getInstance(), which returns the only single instance of
the class. The first time you call this method, it creates an instance, saves it in
a private static variable, and returns you the instance. The subsequent
times, it just returns you a handle to the already created instance.
Here’s an example:
class Logger {
static function getInstance()
{
if (self::$instance == NULL) {
self::$instance = new Logger();
}
return self::$instance;
}
private function __construct()
{
}
private function __clone()
{
}
function Log($str)
{
// Take care of logging
}
static private $instance = NULL;
}
Logger::getInstance()->Log(“Checkpoint”);

The essence of this pattern is Logger::getInstance(), which gives you
access to the logging object from anywhere in your application, whether it is
from a function, a method, or the global scope.
In this example, the constructor and clone methods are defined as private.
This is done so that a developer can’t mistakenly create a second
instance of the Logger class using the new or clone operators; therefore, getInstance() is the only way to access the singleton class instance.

3. Factory Pattern:

Polymorphism and the use of base class is really the center of OOP. However,
at some stage, a concrete instance of the base class’s subclasses must be created.
This is usually done using the factory pattern. A Factory class has a
static method that receives some input and, according to that input, it decides
what class instance to create (usually a subclass).
Say that on your web site, different kinds of users can log in. Some are
guests, some are regular customers, and others are administrators. In a common
scenario, you would have a base class User and have three subclasses:
GuestUser, CustomerUser, and AdminUser. Likely User and its subclasses would
contain methods to retrieve information about the user (for example, permissions
on what they can access on the web site and their personal preferences).
The best way for you to write your web application is to use the base class
User as much as possible, so that the code would be generic and that it would
be easy to add additional kinds of users when the need arises.
The following example shows a possible implementation for the four User
classes, and the UserFactory class that is used to create the correct user object
according to the username:
abstract class User {
function __construct($name)
{
$this->name = $name;
}
function getName()
{
return $this->name;
}
// Permission methods
function hasReadPermission()
{
return true;
}
function hasModifyPermission()
{
return false;

}
function hasDeletePermission()
{
return false;
}
// Customization methods
function wantsFlashInterface()
{
return true;
}
protected $name = NULL;
}
class GuestUser extends User {
}
class CustomerUser extends User {
function hasModifyPermission()
{
return true;
}
}
class AdminUser extends User {
function hasModifyPermission()
{
return true;
}
function hasDeletePermission()
{
return true;
}
function wantsFlashInterface()
{
return false;
}
}
class UserFactory {
private static $users = array(“Andi”=>”admin”, “Stig”=>”guest”,
“Derick”=>”customer”);
static function Create($name)
{
if (!isset(self::$users[$name])) {
// Error out because the user doesn’t exist
}
switch (self::$users[$name]) {

case “guest”: return new GuestUser($name);
case “customer”: return new CustomerUser($name);
case “admin”: return new AdminUser($name);
default: // Error out because the user kind doesn’t exist
}
}
}
function boolToStr($b)
{
if ($b == true) {
return “Yes\n”;
} else {
return “No\n”;
}
}
function displayPermissions(User $obj)
{
print $obj->getName() . “‘s permissions:\n”;
print “Read: ” . boolToStr($obj->hasReadPermission());
print “Modify: ” . boolToStr($obj->hasModifyPermission());
print “Delete: ” . boolToStr($obj->hasDeletePermission());
}
function displayRequirements(User $obj)
{
if ($obj->wantsFlashInterface()) {
print $obj->getName() . ” requires Flash\n”;
}
}
$logins = array(“Andi”, “Stig”, “Derick”);
foreach($logins as $login) {
displayPermissions(UserFactory::Create($login));
displayRequirements(UserFactory::Create($login));
}
Running this code outputs
Andi’s permissions:
Read: Yes
Modify: Yes
Delete: Yes
Stig’s permissions:
Read: Yes
Modify: No
Delete: No
Stig requires Flash
Derick’s permissions:
Read: Yes
Modify: Yes
Delete: No
Derick requires Flash
This code snippet is a classic example of a factory pattern. You have a class
hierarchy (in this case, the User hierarchy), which your code such as displayPermissions() treats identically. The only place where treatment of the classes differ is in the factory itself, which constructs these instances. In this example, the factory checks what kind of user the username belongs to and creates its class accordingly. In real life, instead of saving the user to user-kind mapping in a static array, you would probably save it in a database or a configuration file.

Tip: Besides Create(), you will often find other names used for the factory
method, such as factory(), factoryMethod(), or createInstance().

4. Observer Pattern:

PHP applications, usually manipulate data. In many cases, changes to one
piece of data can affect many different parts of your application’s code. For
example, the price of each product item displayed on an e-commerce site in the
customer’s local currency is affected by the current exchange rate. Now,
assume that each product item is represented by a PHP object that most likely
originates from a database; the exchange rate itself is most probably being
taken from a different source and is not part of the item’s database entry. Let’s
also assume that each such object has a display() method that outputs the
HTML relevant to this product.
The observer pattern allows for objects to register on certain events
and/or data, and when such an event or change in data occurs, it is automatically
notified. In this way, you could develop the product item to be an observer
on the currency exchange rate, and before printing out the list of items, you
could trigger an event that updates all the registered objects with the correct
rate. Doing so gives the objects a chance to update themselves and take the
new data into account in their display() method.
Usually, the observer pattern is implemented using an interface called
Observer, which the class that is interested in acting as an observer must
implement.
For example:

interface Observer {
function notify($obj);
}
An object that wants to be “observable” usually has a register method
that allows the Observer object to register itself. For example, the following
might be our exchange rate class:

class ExchangeRate {
static private $instance = NULL;
private $observers = array();
private $exchange_rate;
private function ExchangeRate() {
}
static public function getInstance() {
if (self::$instance == NULL) {
self::$instance = new ExchangeRate();
}
return self::$instance;
}
public function getExchangeRate() {
return $this->$exchange_rate;
}
public function setExchangeRate($new_rate) {
$this->$exchange_rate = $new_rate;
$this->notifyObservers();
}
public function registerObserver($obj) {
$this->observers[] = $obj;
}
function notifyObservers() {
foreach($this->observers as $obj) {
$obj->notify($this);
}
}
}
class ProductItem implements Observer {
public function __construct() {
ExchangeRate::getInstance()->registerObserver($this);
}
public function notify($obj) {
if ($obj instanceof ExchangeRate) {
// Update exchange rate data
print “Received update!\n”;
}
}
}
$product1 = new ProductItem();
$product2 = new ProductItem();
ExchangeRate::getInstance()->setExchangeRate(4.5);
This code prints
Received update!
Received update!

Although the example isn’t complete (the ProductItem class doesn’t do
anything useful), when the last line executes (the setExchangeRate() method), both $product1 and $product2 are notified via their notify() methods with the new exchange rate value, allowing them to recalculate their cost.
This pattern can be used in many cases; specifically in web development,
it can be used to create an infrastructure of objects representing data that
might be affected by cookies, GET, POST, and other input variables.

Thanks to the advances of PHP 5, using common OO methodologies, such as
design patterns, has now become more of a reality than with past PHP versions. For more you can visit http://www.cetus-links.org/.