Read the latest web development and design tips at Fred Wu's new blog! :-)
Poke me on GitHub

Posts Tagged ‘PHP’

CodeIgniter – Loading Models and Database in One Hit

Most models I create need to access the database. You can easily have CI automatically load the database class by setting a 3rd parameter to true when loading your model:

$this->load->model('your_model', '', true);

The 2nd parameter, which in this case was left blank, is used if you want to assign a different object name to the model – something that I have never used.

Has anyone ever actually used a different object name? The reason I ask is because it’s so easy to forget about the 2nd parameter, and sometimes I try to put the true parameter to auto-load the database in the 2nd slot like this:

$this->load->model('my_model', true); // WRONG!

Of course, the easiest solution is to autoload the database through the config, but that can be a little inefficient for apps that don’t use the DB on every page.

Related posts

Release: [Kohana Module] Authlite, for User Authentication

Latest release: v1.2.3

Initially I was going to wait for my Layerful Framework (a transparent layering framework for Kohana) to mature before releasing its bundled modules. However, since this Authlite module can be used independently to Layerful, I am releasing it now.

What is Authlite

Authlite is a user authentication module for Kohana.

What’s the difference between Authlite and Auth?

Kohana comes with an official Auth module which does exactly what was described in the last paragraph, so why another module then?

It is because Authlite offers greater flexibilty. Please read the features outlined below to find more.

Features

  • Legacy database compatibility
  • Configurable database columns
  • Multiple instances of Authlite
  • Does not enforce user roles
  • Auth-like syntax and usage
  • Lightweight

(more…)

Related posts

Comparison: Ruby vs PHP, the Pros

Just to be clear, this is NOT a fanboyism post nor do I encourage the debate between which language is superior. My personal belief is to use the appropriate tool for appropriate projects.

PHP Pros

  • Widely available libraries (including PEAR and PECL)
  • An absolutely outstanding online manual
  • Relatively easy to learn (can hack together some code without deep understanding of the language)
  • Widely used (easy to find clients, etc)
  • Most if not all control panels have PHP integration
  • Development packages (XAMPP, WAMP, MAMP, LAMP, etc)
  • C style syntax (easier transition for people with C/C++/Java background)
  • Powerful array feature (Ruby’s equivalent to PHP’s associative array is Hash, which is not interchangeable with array)
  • PhpDoc is better than RDoc (this might be because I am too used to PhpDoc)

Ruby Pros

  • Fully object oriented
  • Rake (Ruby’s Make)
  • RubyGem (Ruby’s apt/yum)
  • Code blocks
  • ‘Ghost’ classes
  • Modules (aka namespace/package, PHP 5.3 will have namespace too, but with much uglier syntax)
  • lambda functions (PHP 5.3 will have this too, but not as powerful)
  • Children-aware parent classes (‘inherited’ hook)
  • Multi-inheritance through Mixins (PHP is single-inheritance)
  • Ruby 1.9 is unicode friendly (PHP 6 will be)
  • For what I do, Ruby on Rails > all PHP frameworks combined
  • Regular Expression built into the language core

I am pretty sure there’s heaps of pros for both PHP and Ruby missing from the list, but at least it gives you a rough idea on what to look for if you are not very familiar with them.

Please share your experience with us too (and I will update this post accordingly). :)

Related posts

PHP Namespace – $this->sux

Federico makes an interesting point about the PHP Namespaces Controversy on his PHP::Impact blog. I never thought about the mess that is PHP until I saw his comparison table:

Java:
Attribute/Method access: foo.bar
Static method access:    Foo.bar
Package access:          foo.bar.baz

C#:
Attribute/Method access: foo.bar
Static method access:    Foo.bar
Namespace access:        foo.bar.baz

Python:
Attribute/Method access: foo.bar
Static method access:    Foo.bar
Module access:           foo.bar.baz

PHP:
Attribute/Method access: $foo->bar
Static method access:    Foo::bar
Namespace access:        C:\foo\bar\baz

I guess I can’t complain though as the syntax of PHP is still a lot closer to more “traditional” languages than something like Ruby (not talking about the namespace, just the language in general)… :)

Related posts

Ruby on Rails, Passenger (ModRails) vs CodeIgniter and Kohana

Disclaimer: This is a very simple, ‘Hello World’ benchmark which has no impact to any real world applications. A more thorough benchmark test (by building two real world applications) is planned. :)

Disclaimer 2:I apologise for posting such a useless benchmark (I certainly didn’t expect it to hit the DZone front page), but I think most of you missed the point. I merely posted this as a result of surprise (to me anyway). At a later stage I will conduct a much more meaningful comparison between some of the frameworks. Until then, please ignore this post. :)

Last few days I have been playing with Ruby and Rails, again.

Today, when someone was asking on a forum about the efficiency of web frameworks, I thought I’d give the few frameworks I work with some more benchmark testing.

So I went ahead and benchmarked CodeIgniter, Kohana and Rails, using a simple ‘Hello World!’ page. Now before I post any benchmark results, you should know that I have previously done a benchmark test on CodeIgniter, Kohana and CakePHP. CodeIgniter and Kohana shared similar results.

(more…)

Related posts

Another CodeIgniter book coming soon-ish

Elliot Haughin, a fellow CodeIgniter user has started writing a book on CodeIgniter. This is now the second book, after CodeIgniter for Rapid PHP Application Development by David Upton.

It is really nice to see the CI community grow. Personally I think the user guide is sufficient for a user to get the feet wet, but I understand some people prefer to have a top-down learning approach.

The book is scheduled to finish by August, according to Elliot.

Related posts