Understanding the MVC framework (PHP)

. Monday, June 9, 2008
0 comments

I have already mentioned about MVC framework and CakePHP in one of my articles, therefore I am going to discuss more about it today. Please note, CakePHP is one of the MVC frameworks written in PHP. Don't get confused that MVC framework means CakePHP.

MVC
MVC stands for Model View Controller. It is ultimately a software design pattern where you can separate your code and make it reusable, thus making you write less code.

Model
For each and every database table, we have a separate model - this is what represents a particular database table. And according to the naming convention of CakePHP, its name is always the singular of its table's name. For example, if the name of the database table is 'users', the model name will be 'User' (first character of the name is always in uppercase).

Controller
A controller is used for managing the logic of a certain section of your application. Generally, it is used for managing a single model. For example, you have a model named 'User', and you will require a controller for managing the logic of user registrations, logins, log outs, account settings, etc. According to the naming convention of CakePHP, controller names are always plural. In this case, the controller name would be 'Users'.

View
A view is a page template, usually named after its controller's action (a controller is a php class with many functions known as its actions). As you can guess, this is responsible for the visual output of your application.

I will show you how to install CakePHP (including the php files) in my next article.

Online htaccess editor

. Saturday, June 7, 2008
0 comments

Ever wanted to have your own custom page for 404 (Bad Request) errors or redirect old web pages using htaccess? But dont have any experience with htaccess yet? This online tool is for you then - http://www.htaccesseditor.com/en.shtml. It takes your information in seven steps and outputs a nicely formatted htaccess file.



Features
Deny all access to files
Basic authentication (.htpasswd required)
Error page
Default page
Setup WWW
Redirect directives
Access restriction

Three column CSS layout with blueprint framework

. Friday, June 6, 2008
2 comments

In one of my previous articles, I mentioned about Blueprint CSS framework. Now I am going to show you how to use it for designing your web layouts. I am using Blueprint 0.6 for this tutorial.

Before we begin, I need to tell you about its grid. Blueprint's default width for all layout is set to 950px consisting of 24 columns (width units). These columns can be controlled directly by your HTML code (divs with class attributes). You will not be required to touch your CSS files for that.

Layout (three column)
In this tutorial, we will follow a three-column layout with a header and a footer.


Directory structure for your files


Create a new HTML document with this code:
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01//EN"
"http://www.w3.org/TR/html4/strict.dtd"
>

<html lang="en">
<head>

<meta
http-equiv="Content-Type"
content
="text/html; charset=utf-8">

<title>frinity.blogspot.com</title>

<link
rel="stylesheet"
href
="blueprint/screen.css"
type
="text/css"
media
="screen, projection">

</head>
<body>

<div class="container">

<h1>Header</h1>
<hr />

<div>
First column here
</div>

<div>
Second column (main content)
</div>

<div>
Third column
</div>

<hr />
<div>Footer</div>

</div>

</body>
</html>


Now its time for adding some 'class' attributes to your HTML for creating the columns. Notice that I said the whole layout consists of 24 columns (or 24 width units). For example, you may want the first column to be 6 units wide, the middle column 12 units, and the third and last column to be 6 units. Therefore, the three columns equal to (6 + 12 + 6) = 24 units.

Notice the code highlighted in bold
<div class="column span-6">
First column here
</div>

<div class="column span-12">
Second column (main content)
</div>

<div class="column span-6 last">
Third column
</div>

Dont forget to add 'last' in the class attribute of your last column. This is important.

Final HTML code:
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01//EN"
"http://www.w3.org/TR/html4/strict.dtd"
>

<html lang="en">
<head>

<meta
http-equiv="Content-Type"
content
="text/html; charset=utf-8">

<title>frinity.blogspot.com</title>

<link
rel="stylesheet"
href
="blueprint/screen.css"
type
="text/css"
media
="screen, projection">

</head>
<body>

<div class="container">

<h1>Header</h1>
<hr />

<div class="column span-6">
First column here
</div>

<div class="column span-12">
Second column (main content)
</div>

<div class="column span-6 last">
Third column
</div>

<hr />
<div>Footer</div>

</div>

</body>
</html>

Save your HTML file, and open it in a browser. Your layout is ready!

Recommended firefox addons for developers

. Thursday, June 5, 2008
0 comments

NoScript


The best security you can get in a web browser! Allow JavaScript, Java and other executable content to run only from sites you trust.

IE Tab

IE Tab - an extension from Taiwan, features: Embedding Internet Explorer in tabs of Mozilla/Firefox. Great tool for designers debugging cross browser css issues.

Firebug

Firebug integrates with Firefox to put a wealth of development tools at your fingertips while you browse. You can edit, debug, and monitor CSS, HTML, and JavaScript live in any web page.

FireFTP

FireFTP is a free, secure, cross-platform FTP client for Mozilla Firefox which provides easy and intuitive access to FTP servers.

Web Developer

Adds a menu and a toolbar with various web developer tools.

FireShot

FireShot is a Firefox extension that creates screenshots of web pages. Unlike other extensions, this plugin provides a set of editing and annotation tools, which let users quickly modify captures and insert text and graphical annotations.
More popular extensions are available here: https://addons.mozilla.org/en-US/firefox/browse/type:1/cat:4?sort=popular

Why choose CakePHP over other frameworks?

.
0 comments

Those who have the slightest experience of Ruby on Rails would understand the importance of MVC (Model View Controller) framework for developing web applications. RoR is awesome, there is no doubt at all. But as a web developer, I have to build websites for others and this means I have to use their web host. Unfortunately, there are a very few web hosts supporting Ruby (compared to PHP).

When it comes to MVC framework in PHP, you would immediately think of CakePHP, CodeIgniter, Symfony or Zend Framework. Now the question is which one serves the purpose best for you.

Server Compatibility
If you want your application to run in most servers, then you cant rely on Symfony much since it requires PHP5 while CakePHP and CodeIgniter both run in PHP4.4.x to PHP5. If you want search engine friendly urls, then you will require mod_rewrite module for apache (not a must though - you can still run it without mod_rewrite).

Documentation
To be fair, CodeIgniter is more organized in terms of documentation, and CakePHP is still updating its Cookbook (for version 1.2 beta). They have Screencasts that beginners will find useful. Most importantly, their community is very strong, and you will get quick response if you get into any problem.

Support
CakePHP has a pretty active community as well. They have the Bakery where users can participate and submit articles, code snippets, etc. Moreover, there is a Google Group and IRC channel where you can ask for help anytime.

I am a big fan of CakePHP, and will stick to it. According to Google Trends, there are more people searching for CakePHP than any other popular php frameworks. I will always support going for that open source project that has a huge community (or has the potential).

Cheat Sheets

. Wednesday, June 4, 2008
1 comments

Its very much likely that you have forgotten the name of a function or its parameters. Cheat sheets can deliver you the information immediately in that case. Here are some that you may require:

Ajax
Prototype Cheat Sheet (PNG)
scriptaculous Combination Effects Cheat Sheet (PDF)

Apache
htaccess cheat sheet
mod_rewrite cheat sheet (PNG)

CSS
CSS cheat sheet (PNG)

HTML/XHTML
HTML & XHTML Tag Quick Reference
XHTML Cheat Sheet v. 1.03 (PDF)

JavaScript
JavaScript Cheat Sheet (PNG)

MySQL
MySQL Cheat Sheet (PNG)

PHP
PHP Cheat Sheet (PNG)
CakePHP Cheat Sheet (PDF)
Regular Expressions Cheat Sheet (PNG)

This list will be updated on a continuous basis.

Frameworks I prefer most for web applications

.
2 comments

According to wikipedia: "web application framework is a software framework that is designed to support the development of dynamic websites, Web applications and Web services. The framework aims to alleviate the overhead associated with common activities used in Web development. For example, many frameworks provide libraries for database access, templating frameworks and session management, and often promote code reuse".

Here are some of the popular frameworks that you will find handy when developing applications.

Blueprint (CSS)
Blueprint is a CSS framework, which aims to cut down on your CSS development time. It gives you a solid CSS foundation to build your project on top of, with an easy-to-use grid, sensible typography, and even a stylesheet for printing.

Script.aculo.us (Javascript)
script.aculo.us provides you with easy-to-use, cross-browser user interface JavaScript libraries to make your web sites and web applications fly. But once you have jQuery, I am sure you will not use any other javascript libraries at all.

jQuery (Javascript)
jQuery is a fast, concise, JavaScript Library that simplifies how you traverse HTML documents, handle events, perform animations, and add Ajax interactions to your web pages. jQuery is designed to change the way that you write JavaScript. Also, dont forget to have a look at jQuery UI.

CakePHP (PHP)
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.