My PHP framework dilemma

Posted on 2008.10.09
Categories: PHP; Tagged with: , ,

I use several pieces of PHP software very often:

All of the above tools are indispensable tools, particularly the blogging platform that runs four of my Web sites and that is used by millions of other people. But my dilemma rests with the last two products.

Recently, I’ve been working on three projects — SiteElements, FriendStalkr, and one other project. All three of these projects have been built on top of the Model-View-Controller structure provided by CodeIgniter, an excellent, efficient, and lightweight PHP framework.

My previous Web developments have never used an MVC structure, where the content (view) is separated from (yet dependent on) the backend (controller), which is separated from the data processing (model). Yet I believe that my choice to use MVC for these three sites is a good decision, since MVC makes code maintainable and probably will also help if the database structure or the site design are ever changed.

My previous Web developments on PHP also didn’t use CodeIgniter. The creator of PHP himself recommended CodeIgniter because it was the most lightweight of all of the viable frameworks and fastest (right behind core functions). Zend Framework, my framework of choice, is much less efficient, perhaps due to the number of files that need to be loaded when many classes are used.

I like CodeIgniter because it is extremely efficient, and its MVC structure is quite easy to use. The framework can be extracted and used as-is, since the ZIP archive contains the directory structure that is used by default. CodeIgniter also makes it easy to use built-in classes as well as extra helpers to simplify development and enhance functionality.

However, CodeIgniter lacks the comprehensive functionality of Zend Framework, and cannot, by any means, compete with Zend Framework on that level. Zend Framework is the most powerful and extensive set of libraries that I know of, which is why I began using it in the first place. Unfortunately, Zend Framework loses out to CodeIgniter and many other PHP frameworks in its MVC implementation (which is optional), and sometimes awkward to use.

My dilemma is simple: I want the simple structure, lightweightedness, and speed of CodeIgniter, while also making use of the powerful libraries in Zend Framework. Although it should be possible to combine the two and use both frameworks, doing so would inevitably slow down the site — unless memory caching was implemented, which I cannot do at this point.

I have not considered switching any of the sites to another PHP framework like CakePHP or Symfony, perhaps because I want to stick to the frameworks that I prefer, and also because many developers have the same closed-mindedness that prompts them to use what they know rather than what’s new or better. Nevertheless, I will not use CakePHP or Symfony; Zend Framework and CodeIgniter are, by far, the best frameworks for my purposes, as well as the best documented.

What can I do? In my mind, I can do nothing.

But I also believe that the possibility of switching to the less efficient Zend Framework exists. For sites that may require speed, such a switch could not be possible. However, for a development such as SiteElements — which will require advanced API functionality present in Zend Framework and not CodeIgniter — it is conceivable that I could choose to use Zend Framework.

What can I do? Perhaps the better question is, “what should I do?”

1 Star2 Stars3 Stars4 Stars5 Stars (5 votes, average: 4 out of 5)
Loading ... Loading ...

PHP coding shortcut: the ternary operator

Posted on 2008.01.28
Categories: PHP; Tagged with: , , , , ,

Many of us coding or able to code in PHP often take the long route to do a simple task. Some completely “reinvent the wheel” with custom string handling functions. Others use complex while loops with simple tasks.

Most use the classic if… (then)… else… style conditional statement. Things such as the following:

<?php
if($_SERVER['REQUEST_URI']=='/index.php') {
	echo('Hello World!');
} else {
	echo('This is some other page');
}
?>

Some may have moved beyond such rudimentary coding to blocks like the following:

<?php
$request_uri = $_SERVER['REQUEST_URI'];
switch($request_uri) {
	case '/index.php':
		echo('Hello World!');
		break;
	default:
		echo('This is some other page');
}
?>

Clearly, the second takes more work. Given something as simple as echo-ing a phrase like “Hello World!” or “This is some other page”, using the switch-case syntax simply doesn’t make sense. Even the if-else syntax is a bit overkill.

That’s why programmers and coders who perform simple tasks should use the ternary operator (available in PHP and JavaScript):

<?php
echo ($_SERVER['REQUEST_URI']=='/index.php') ? 'Hello World!' : 'This is some other page';
?>

Simple, right? Right.

It follows the pattern of (expression 1) ? (expression 2) : (expression 3) where this statement evaluates to expression 2 if expression 1 returns TRUE and the statement will evaluate to expression 3 if expression 1 returns FALSE.

For more information, consult the PHP manual.

1 Star2 Stars3 Stars4 Stars5 Stars (1 votes, average: 3 out of 5)
Loading ... Loading ...

A Useful Tag: base href

Posted on 2007.11.26
Categories: XHTML; Tagged with: , , , , ,

If you’re coding in XHTML or if you’re creating a site in PHP, one of the pains is making sure that your relative paths are correct. Surely having to type in the full site URL is a pain, even though that would usually eliminate the relative paths problem; but instead of using
<link href="../../style/style.css" rel="stylesheet" media="screen" />
and trying to make sure that the above code works for every page of your design, you could simply utilize the easy and simple,
<base href="http://www.example.com/" />
tag!

(more…)

1 Star2 Stars3 Stars4 Stars5 Stars (No Ratings Yet)
Loading ... Loading ...