Greg Aker

Entries Tagged with: PHP

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

Showing PHP Memory Usage through your Template

Filed in: Performance, PHP, ExpressionEngine

June 18, 2011

Ever been deep in troubleshooting performance issues in your ExpressionEngine site and wondered what kind of memory is a certain plugin/weblog tag, etc is taking up? Unless you're holding out from blogging about it, there's absolutely no way I'm aware of that you're getting that info from shell on the server. So, here's a quick and dirty hack to EE's template parser that will show you this info.

Pop open system/expressionengine/libraries/Template.php and look for:

<?php

function log_item($str)

Now, a quick addition in there and you're good to ...

Read More

Session Cache in ExpressionEngine

Filed in: PHP, ExpressionEngine, tutorial

June 14, 2011

I think the session cache may quite possibly be one of the more under used tools in the third-party ExpressionEngine developers toolbox. The speed/performance increases from strategically caching items in this can be substantial. As with anything you do while developing your addon, benchmarking needs to be done every step of the way to ensure you aren't overdoing it and actually causing issues. I want to illustrate how adding something to the session cache can give a nice performance boost.

What is the session cache?

First, see the docs.

If you're a developer and haven't had ...

Read More

CURLOPT_FOLLOWLOCATION errors and what you can do

Filed in: PHP

April 23, 2011

I see this come up in waves every so often on Twitter or the ExpressionEngine forums.

Warning: curl_setopt() [function.curl-setopt]: 
CURLOPT_FOLLOWLOCATION cannot be activated when safe_mode is enabled or 
an open_basedir is set in /var/www/test.php on line 10

So what in the world does this mean, and what can you do about it?

First off, if we read the error, it's crystal clear. If you're using code that calls CURLOPT_FOLLOWLOCATION when safe_mode is enabled or open_basedir is in effect, you get this error. Bam!

Safe Mode, is generally thought of as an abomination, is off ...

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

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

Let's build an ExpressionEngine Module!

Control Panel Page (mcp file) and model. Part One

Filed in: PHP, ExpressionEngine, tutorial

March 16, 2011

  1. Project Setup and Module Installation
  2. Control Panel Page (mcp file) and model. Part One
  3. Control Panel Page (mcp file) and model. Part Two
  4. Front End Template Tag

I decided to break the control panel portion into two parts, so this will now be a four part series. First, we're going to build the form to submit a short link. This will include a model, view and controller (mcp file).

So, let's start by setting up the base for the module control panel file (mcp.shortee.php). Open that up in your editor, and let's get to work ...

Read More

Let's build an ExpressionEngine Module!

Intro & Install/Update File

Filed in: PHP, ExpressionEngine, tutorial

March 13, 2011

  1. Project Setup and Module Installation
  2. Control Panel Page (mcp file) and model. Part One
  3. Control Panel Page (mcp file) and model. Part Two
  4. Front End Template Tag

I think I'm a bit different than most in how I view the ease in which to build the different types of ExpressionEngine addons, but I definitely think that in most cases modules are not a heck of a lot more difficult than Plugins. Personally, I find Extensions the most difficult as you have to develop with a keen eye to ensure your extension is playing nice with the rest of the ...

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