Expression Engine extensibility
A recent project used Expression Engine which was on the whole a pleasant experience there was however an inevitable sour note. I found the process of developing a module slightly cumbersome. They seem to have emulated WordPress (or vice versa) with regard to the basic hooks and filters approach, which although meeting some simple needs, falls short of full utility.
My aim was to create a module that among other things would add a new member to the site under a specific member group. This seemed like it would be a common use case that would be well covered by the core libraries. I started off digging through the user guide with no success so moved on to the forums. Here again I was stumped mainly being pointed in the direction of third party modules like the Solspace User module. I decided i would look at the ExpressionEngine core to see how it was done there before shelling out $99 on something i might not need.
After a dig about the result was the member module containing the register_member method which used the Member_register class, Bingo! A cursory check showed that it could meet my needs but being PHP4 and having no DocBlock i was worried that it might be intended to be a private method and subject to change. I posted a simple query to the official support forum, which was awarded with defining silence. This point i am a little disappointed in given that ExpressionEngine is a commercial product.
Moving on i dug deeper into the register_member function and discovered quite apart from my expectations that it was getting it’s data directly from $_POST and littered with calls to output methods. This class is seems, is to be used for one thing only: adding members based on the specific input of the registration form. I was left with rolling my own member code and inserting them directly into the database.
This strikes me as a missed opportunity for ExpressionEngine both for maintaining the quality of plugins and easing developer involvement. By providing and API for modules to perform CRUD operations on the database you could better ensure the quality of the data and the security of the system. The following code is an example of how this interface might function:
1 2 3 4 5 6 7 8 9 10 | try { $this->EE->load->library('member'); $user_id = $this->EE->Member->addMember(array( 'username' => 'dave', 'password' => 'ilovehorses', 'email' => 'dave@example.com' )); } catch( Exception $e) { // Do stuff } |
Hopefully EllisLabs are moving towards this sort of core, as providing this sort of API not just for members but for all CRUD operations that a module would need could massively improve the ExpresisonEngine ecosystem for developers. An additional benefit of creating these APIs and making the core classes consumers of them is that you make it easier to run unit tests on ExpressionEngine.