Overloading So That empty() works in PHP

Posted on August 13th, 2008

Overloading PHP So That empty() Works

PHP5 has a much improved object oriented feature set. With great MVC PHP frameworks such as CodeIgniter, CakePHP, and the Zend Framework you should certainly be writing your own classes and taking advantage of objects in your coding. Using the magic methods that you get with PHP5 you can overload your classes so that you can do some very cool stuff.

PHP’s overloading deviates from the way other programming languages work. Overloading in most other languages enables you to define several different methods all with the same name but taking different types of paramters. PHP, on the other hand, uses overloading to handle calls to object members or methods that have not been defined or are not visible in the current scope of the caller.

A Quick Example Of Overloading

Read the rest of this entry »

TheWebLessons.com PHP Screencast Tutorials

Posted on August 5th, 2008



PHP Screencasts, PDF books, and source code. Lessons will be cover PHP Development, and the CodeIgniter PHP Framework.

As of today, TheWebLessons.com is open. If you register during the beta phase, you will receive a 50% discount on all of the lessons that will ever be published.

Lesson Topics Will Include

  • Object Oriented Programming in PHP5
  • Setting Up A CodeIgniter Project
  • Understanding MVC Architecture
  • Using Your Own Libraries With CodeIgniter
  • Working with Sessions
  • Databases and CodeIgniter
  • Working With Forms
  • Sending Email
  • Testing Your Code
  • And more…

Sign up today to lock in your discount.

My 2 Cents On Web Hosting

Posted on July 18th, 2008

People regularly ask me where to host their websites. This is pretty much what I tell everybody.

RackSpace Is The Best

Unless You Don’t Want To Pay For Managed Hosting
Or You Want Ruby on Rails Support

An entry level server at RackSpace will cost you about $500/month. If you can afford a managed, dedicated server, and your are working with PHP host with RackSpace. I have several servers with RackSpace and have been working with them now for over 5 years. The service, support, and reliability are fantastic unless you intend to host Ruby on Rails applications. RackSpace does not “officially support” Rails. When you are talking to the sales department they say they will help with Rails issues even though it’s not officially supported. My experience is that you are totally on your own with Ruby on Rails at Rackspace.

RimuHosting Is The Best For Non-Managed Servers

The Best VPS, Semi-Dedicated and Dedicated Servers

So if you want to run Rails apps or you don’t need a managed dedicated server, host with RimuHosting. This blog is hosted at RimuHosting and for the past 2 years I have had both VPS accounts and Dedicated servers there. The uptime, performance and reliability has been extremely good although not quite flawless. There was one time when one of my semi-dedicated VPS accounts was unavailable for about an hour and it was not a scheduled maintenance period. Even with that one blip in the service, my overall experience has been excellent and I highly recommend RimuHosting if you want a VPS account or a non-managed dedicated server. The support is extremely fast and helpful – albeit via email only. I prefer email though, as long as it’s attended to promptly. In your customer control panel, you can see the status of your support ticket, how long it has been since you have submitted it, whether or not anyone is working on it, etc. It really is better than phone service in my opinion.

HostICan

The Best Shared Hosting Package I’ve Ever Seen

If you just want a low cost shared hosting account, I have never seen a package that is better than the BaseHost package with HostICan. It is $6.95/month and you get 2,000 GB – yes about 2 Terabytes of data storage. You can host 2 different domain names and get a free domain name for life when you sign up. The free domain name is at least worth the cost of one month of hosting each year. They offer a 99.9% uptime guarantee. If you want a WordPress blog, the WordPress software is already there and ready to go. So this is great account to have if you want to host your own blog. You can even get SSH access but that adds a little to your monthly cost. They no longer support Ruby on Rails. But, if your building Rails apps, get a VPS account at RimuHosting.

Mac Mail: Signature With A Link

Posted on July 15th, 2008

I’ve been asked a few times how to make a signature with a link in Mac Mail. I’m using Leopard and I agree that it’s not very obvious how to pull this off. The steps are fairly simple as long as you know what to do.

  • Open a new mail message
  • Create a link in your mail message
  • Copy your link into your signature

Here is a quick screencast to show you how to pull this off. Not only does this work with links, but it also works with any other types of formatting in your mail message – bold, italics, fonts, etc.

Read the rest of this entry »

IDs With Square Brackets And jQuery

Posted on July 8th, 2008

I have recently become quite fond of using jQuery as my javascript library in conjunction with my CodeIgniter PHP projects. In PHP, I often name my form fields in the format of…

model_name[attribute_name]
For Example...
contact[first_name]
contact[last_name]
etc.

I do this so that I can easily retrieve all the attributes for each model and then quickly store them to the database using CodeIgniter’s database helper functions. For example, taking advantage of the Active Record Insert Syntax, I might write PHP code like this…

$contact = $_POST['contact'];
$this->db->insert("contacts", $contact);

When I started to use jQuery to do some client side javascript validation on my forms it was not immediately obvious to me that I needed to escape the square brackets in the jQuery calls.


Due to javascript’s encoding, you need to use double slashes – not just a single slash – to escape the square brackets.

Ecommerce with CodeIgniter

Posted on May 15th, 2008

Ironically the Zend Framework is marketed with the phrase “Extreme Simplicity & Productivity”. I have developed a few sites with it now and I find it to be anything but simple and productive. It’s complicated, has a steep learning curve, and (in my opinion) needs a lot more work. I realize that I’m coming from a RoR background and that is a lot for a PHP framework to try to match. Nevertheless, I am quitting all Zend Framework development until more work can be done on the framework. Then, maybe I’ll reconsider.

I have found CodeIgniter and have now built 3 sites with it. It’s simple, easy to use, speeds up development, has great documentation and, best of all, has won me as a fan. My most recent CodeIgniter project is an educational/e-commerce site about Rebounding with the Cellerciser While developing the site and reading the site content, I was convinced of the many reasons to use a Cellerciser I’ve now been using a Cellerciser for about 3 months and I love this thing!

Read the rest of this entry »

How To Tar A Directory

Posted on February 23rd, 2008

I constantly forget how to tar a directory. I think the ln command and the tar command have their parameters in different orders and I can never seem to remember which parameter is the dir you are archiving and which one is the name for the archive. So here it is:

tar -czf archive.tgz dirName

How To Sort A Zend_Db_Table_Rowset

Posted on February 14th, 2008

So you figured out how to define the relationships between your Zend_Db_Tables and you have issued a call to findDependentRowset(). You get your Rowset back but you need to sort the results by one of the columns in the dependent table. How do you do that?

The short answer is, you can’t! Unfortunately, this functionality won’t be available until the 1.5 release of the Zend Framework. But you can write your own utitlity function to sort your Rowset for you.

Read the rest of this entry »

How To Implement Partials In Zend Framework 1.0.3

Posted on February 11th, 2008

The pre release of Zend Framework 1.5 has been out for a few days and includes an implementation for partials – among other things. But the GA release is still at least a few weeks off and I’ve got a project that needs to go live very soon. So, I’m using version 1.0.3 of the Zend Framework released on 11/30/2007, and I want to make use of partials in my project. The trick involves three steps.

  1. Create a View Helper
  2. Access your Zend_View object from the View Helper (or instantiate a new one)
  3. Render a view script from within the View Helper

Read the rest of this entry »

How To Implement A Ruby on Rails style before_filter With The PHP Zend Framework

Posted on January 30th, 2008

I often use this when implementing a simple login screen for a password protected section of my application. In a Zend Framework application you can implement a preDispatch() function in a Zend_Controller_Action which will run before an action is dispatched. This lets you setup your filter to check to see if the visitor is logged in or not. If the visitor is not logged in, you can redirect them to the login screen of your application.

Setting Up Exceptions For preDispatch

If your login screen is managed by a different controller, the setup described above is fine. If, however, your login screen is managed by an action in the same controller as the protected actions, you will want to allow unauthenticated access to the login screen. To do this, we need to exclude certain actions from the authentication check. Ruby on Rails let’s you define :except => :actionName to allow certain actions to skip the before_filter. With the Zend Framework, we have to implement that functionality on our own… but it’s easy.

What Action Is Being Called?

To set up your preDispatch function to skip checking to see if a user is logged in for certain actions you need to know which action is being called. You do that like this…

$action = $this->_request->getActionName();

Example Code

Now all you have to do is see if the action that is being called is one of the actions that you want to skip. I set up a private function called verify() to check whether or not the visitor is logged in. If the user is not logged in, I forward them to the loginAction() function. Since an unauthenticated user needs to be able to access the login screeen, we tell the preDispatch() function not to verify visitors requesting the login action. My controller ends up looking someting like this.

class AccountController extends Zend_Controller_Action {

  function preDispatch() {
    // Discover what action is being requested
    $action = $this->_request->getActionName();

    // Create a list of actions which allow unauthenticated access
    $exclusions = array("login");
    if(!in_array($action, $exclusions)) {
      $this->verify();
    }
  }

  /**
   * Check to see if the visitor is logged in. If not, send to loginAction
  */
  private function verifty() {
    $auth = Zend_Auth::getInstance();
    if(!$auth->hasIdentity()) {
      $this->_forward("login");
    }
  }

  function loginAction() {
    // Display your login screen
  }

  // Continue the rest of your class...
}
Get Adobe Flash playerPlugin by wpburn.com wordpress themes