Extending CodeIgniter Parser to support Objects

CodeIgniterI really like codeIgniter, since it’s super lightweight, and its learning curve is super small. You can get to build a whole website within just a couple days, even with database support.

I’ve written myself a e-commerce website in just two weeks, without having previous knowledge on the technology. Now, let’s get to business.

What happens when you’re writing a view (php based), and you need to display a variable?. Well, you’ve got, essentially, two options. To begin with, you can simply invoke the php ‘echo’ routine, by doing something like this:

[cc lang=”php”][/cc]

Now, if you wanna keep your code really clean, you can rely on CodeIgniter built in parser. How do you implement it?… super simple…:


1. Initialize the Parser Library:

[cc lang=”php”]$this->load->library(‘parser’);[/cc]

2. Replace the ‘<?php echo $blog_title; ?>’ routines with the following syntax:

[cc lang=”php”]{blog_title}[/cc]

So far so good. Now… here’s something interesting. What happens if you wanna print an object’s property? or an object’s method?. Well, CodeIgniter doesn’t support that scenario. It will only work with strings, and with arrays (of strings). So… i’ve extended a bit the library, in order to support ‘printing object’s properties’.

You can download right here my extended version of the parser. We won’t be analyzing the code i’ve written. It’s not complex, and you’re invited to run a diff between the original, and my patch.

Now… how do we use it?. Simple…

1. Install the sf_parser library

You should copy the ‘sf_parser.php’ file to ‘/application/libraries/sf_parser.php’. That’s it. No more no less. Simplicity is one of the things i love the most about CI framework.

2. Initialize the sf_parser library

Instead of initializing the CI’s default parser, we’re gonna need to load our custom library. We can achieve that by doing the following:

[cc lang=”php”]$this->load->library(‘sf_parser’);[/cc]

3. Use the new syntax!

The goal of this library is to enable you (the user!) to print any object’s properties, or getter’s results. Which means that… instead of using the following syntax, in your view.php file:

[cc lang=”php”]get_title();>[/cc]

You can now do something far more elegant… which looks something like this:

[cc lang=”php”]{blog:get_title}[/cc]

If you found it useful… if you found a bug… or if you’ve extended it further, i’d love to hear from you!

Xcode 4.6 Released!

Head your browsers to Apple’s Development Center. Apple has just released Xcode 4.6, with iOS 6.1 support (Release!).

So far it has proven to be sooooo much stable. The previous release was a nightmare, specially during summertime. (Those of you who run Xcode on macbooks understand me… the entire machine turns into an iron!).

However, i’ve been reading quite a lot of reports, from many different sources, pointing out that although 4.6 *freezes less*, it still has a couple of severe bugs, that will lower your productivity.

Xcode

Disabling Jetpack Stats

So… you just connected Jetpack to wordpress.com, and you can’t figure out how to disable the stats module… right?.

It’s fairly easy. Firt, head to the admin, an click ‘Jetpack’ on the left menu. Then, click the ‘Learn More’ button in the ‘WordPress Stats’ section. You should be seeing the following:

deactivate-jetpack-stats

Notice the ‘Deactivate’ button that appeared, right by the ‘Learn More’ button?. Click it.

That’s it… WordPress Stats should be disabled by now!

We got a new domain!

Well, as you might have noticed, we’ve got a brand new domain: lantean.co. This is sort of an experiment to me, to see if rankings can actually improve by leaving behind the .com.ar domain. (Since this site is written, essentially, in english, and .com.ar is geotargetted for Argentina).

updating-domain-name

What was done in order to attempt to prevent drops in rankings?.

  1. 301 redirects from the old domain. How?. the .htaccess looks like this:[cc lang=”bash”]RewriteCond %{HTTP_HOST} !^www.lantean.co$ [NC]
    RewriteRule ^(.*)$ http://www.lantean.co/$1 [R=301,L][/cc]
  2. I’ve indicated Google Webmaster Tools that the website has been moved. Here are the details.
  3. I’ve crossed my fingers!

Stay tuned for updates!