Greg Aker

Entries Tagged with: CodeIgniter

Know what ORMs and Query Builders do!

Filed in: Django, ExpressionEngine, CodeIgniter

September 2, 2011

ORMs and Query Builders such as the Django ORM and CodeIgniter Active Record classes are great time savers. But you can get yourself into performance trouble if you're not paying attention to what these are doing behind the scenes. I think the biggest mistake people make is they use tools like this as crutches for not understanding how to write simple SQL statements. Don't fall into this group! If you're in it, work hard to get out!

I'll show a couple of examples from both to illustrate how you can give your applications a performance boost ...

Read More

CodeIgniter Conference 2011 Roundup

Filed in: Blobbing, CodeIgniter

August 22, 2011

It's 3:30am, and I'm waiting to take a car to the airport after my weekend in New York for the CICon 2011 Conference. To help trick my body into not wanting to sleep, I decided to do a write up about my weekend experiences.

First, hats off to Adam Fairholm, Kenny Katzgrau and Phil Sturgeon with the the great job they did organizing the conference. I'm extremely pleased and impressed with the amazing venue, accommodations, speakers and overall experience they provided for us.

I was honored to announce to the community two things I think are ...

Read More

var_dump($this) in EE/CI with no recursion

Filed in: PHP, ExpressionEngine, CodeIgniter

August 18, 2011

Here's a quick little tip for all you EE addon developers out there. I've seen some people moaning on Twitter about how a var_dump() can be hard on the browser due to the recursion in the CodeIgniter singleton. So check how I like to roll in my CI libraries/EE addons.

<?php

class Foo {

    protected $_foo;

    public function __construct()
    {
        $this->_foo = $this->config->item('something');
    }
}

Look maw, no $this->CI

Did you know you you can do this in a CodeIgniter library or an ExpressionEngine mcp/mod/extension/plugin/accessory file? It's pretty easy to accomplish, and ...

Read More

DB Results in ExpressionEngine and CodeIgniter

Filed in: ExpressionEngine, CodeIgniter

June 9, 2011

I learned PHP by forcing myself to try to create ExpressionEngine addons. I studied the 1.x code. I poured over the CodeIgniter core, trying to figure out how the heck it worked. One thing that confused me was how the heck do I get a single result from an active record query! If you're in this boat, I hope this might help clear it up for you a bit.

In ExpressionEngine 2.x, unless you're doing something extremely complex, using the CodeIgniter Active Record class is the way to go.

For instance, if we want to do ...

Read More

What is xss_clean in CodeIgniter, and why should I use it?

and just as importantly, when should I not use it

Filed in: Security, PHP, CodeIgniter

March 30, 2011

If you're new to CodeIgniter, you've probably seen xss_clean() mentioned in the docs. When I was first starting with PHP and CodeIgniter, every time I saw xss_clean() mentioned, I'd think to myself "what the hell is that?!" So I hope I can show you what it is, why it's important to use and when you shouldn't use it.

What's XSS?

If you haven't heard the term XSS before, read over at Wikipedia about Cross Site Scripting.

A really quick example of an XSS attack would be to build a script like:

<?php

echo ...

Read More

Automagic CodeIgniter base_url

Filed in: CodeIgniter

March 29, 2011

I posted this on Forrst a while back, but I thought I'd post it here. Forrst seems cool, but I honestly rarely use that service as it's yet another login to remember, and finding things if you're not logged in seems hard...but I digress.

In CodeIgniter Core projects, I like a 'dynamic' base_url, and it's easy to accomplish in your config.php file with the following code.

<?php
// Chop of the DOCUMENT_ROOT part of the $path.  This will
// Give us everything after http://example.com/
$path = ltrim(str_replace(rtrim($_SERVER['DOCUMENT_ROOT'], '/'), '',
                    rtrim(FCPATH, '/')) . '/', '/');

// Running HTTPS ...

Read More

Extending CodeIgniter's Controller

Filed in: PHP, CodeIgniter

March 18, 2011

I think it's safe to assume that I'm not in the minority when I say that I learned to program with CodeIgniter. I started in mid-2007 learning HTML/CSS while learning ExpressionEngine. Within a year or so, CodeIgniter seemed to be the logic step on what to learn, so I dove in head first. Lisa Wess gives me grief to this day for my forum post asking for someone to explain to me how the exp:weblog:entries tag worked. Her answer was correctly, "go look at the code." :)

When I was new to programming and CodeIgniter, one ...

Read More

Constructor-structor, what's your function?

Filed in: ExpressionEngine, CodeIgniter

March 10, 2011

I'd like to set the record straight on the usage of class constructors in CodeIgniter and ExpressionEngine apps/addons. I have seen EE-addons and CI code examples using them where they are not necessary. To illustrate this point and make things a bit more clear, I removed the class constructor from the CodeIgniter 'welcome' controller last night. Since your controllers in CI extend CI_Controller, you automatically inherit all the code that is contained in CI_Controller::__construct().

So for instance, if you have a controller like:

<?php

class Foobar extends CI_Controller {

    public function index()
    {
        $this->load->view('foobar');
    }
}

or a ...

Read More

CodeIgniter Reactor's Caching Drivers

Filed in: PHP, CodeIgniter

February 12, 2011

Before Reactor dropped, I snuck in some caching drivers (Docs Link) that Pascal had been tossing back and forth for several months. I've seen a few people talk about them, but I think they are still generally unknown so I want to give a brief intro on how to use them.

At this time, there are drivers available for APC, Memcached, file-based caching, and a dummy cache. If you haven't already, head over to BitBucket and get cloning or forking.

Examples

Caching API Calls

We can cache API calls pretty easily within controllers. Let's say we want ...

Read More

Updating EE CodeIgniter version after the big PHP5 changes.

Filed in: ExpressionEngine, CodeIgniter

December 15, 2010

As I've mentioned before, we use a subrepo for CodeIgniter on our products at EllisLab. So, we occasionally update the sub repo as we want to pull changes in CodeIgniter into the project. So a few weeks ago starting with this revision, Pascal and I went hog wild ripping PHP4 dependencies from CodeIgniter. It was a joyous and liberating experience to say the least. So now the scary part. We need to merge these CI changes into ExpressionEngine and MojoMotor. Well, we took a deep breath, updated that subrepo to the latest version of CI and went to work ...

Read More