We use cookies to improve your experience. No personal information is gathered and we don't serve ads. Cookies Policy.

ExpressionEngine Logo ExpressionEngine
Features Pricing Support Find A Developer
Partners Upgrades
Blog Add-Ons Learn
Docs Forums University
Log In or Sign Up
Log In Sign Up
ExpressionEngine Logo
Features Pro new Support Find A Developer
Partners Upgrades
Blog Add-Ons Learn
Docs Forums University Blog
  • Home
  • Forums

Extension skeleton is givng me grief...

Development and Programming

ffurger's avatar
ffurger
220 posts
15 years ago
ffurger's avatar ffurger

The following extension literally doesn’t do anything. I am just trying first to figure the basics.

I have read and re-read the EE dev. documentation, I looked into the code of two working extensions. I found a few errors, and tried just about everything I could think of, but this extension just doesn’t work. It doesn’t even load, it gives me a blank screen.

I have stared at this thing for so long, I am just not seeing anything anymore. Any thoughts or suggestions would be very much appreciated!

<?php  

if ( ! defined('BASEPATH')) exit('No direct script access allowed');

/**
 *  Assign group
 * 
 *   Assign group is an ExpressionEngine extension that allows to assign a newly register member to a predefined group upon registration.
 * 
 * @package        ExpressionEngine
 * @category    Extension
 * @author    Franco Furger <[email protected]>
 * @copyright Copyright (c) 2011 Franco Furger
 * @license   http://creativecommons.org/licenses/MIT/  MIT License
 * @version   0.1
 */


class Assign_group_ext
{
        var $settings        = array();
    
        var $name               = 'Assign group';
        var $version         = '0.1';
        var $description     = 'TBD';
        var $settings_exist  = 'n';
        var $docs_url        = '';

        // -------------------------------
        // Constructor 
        // -------------------------------             

        function __construct($settings = '')
        {
            $this->EE =& get_instance();
            $this->settings = $settings;
        }
    
    
        // --------------------------------
        //  Activate Extension
        // --------------------------------

        function activate_extension()
        {
            
            $data = array(
            'class' => __CLASS__,
            'method' => 'select_group',
            'hook' => 'member_register_validate_members',
            'settings' => '',
            'priority' => 10,
            'version' => $this->version,
            'enabled' => 'y'
            );
            
            $this->EE->db->insert('extensions', $data);
        }
        

        // --------------------------------
        //  Update Extension
        // --------------------------------  

        function update_extension ($current='')
        {

            if ($current == '' OR $current == $this->version) 
            {
            return FALSE;
            }

            if ($current < '1.0')
            {
            $this->EE->db->where('class', __CLASS__);
            $this->EE-db->update('extensions', array('version' => $this->version) );
            }
        }


        // --------------------------------
        //  Disable Extension
        // --------------------------------

        function disable_extension()
        {
            $this->EE->db->where('class', __CLASS__);
            $this->EE->db->delete('extensions');
        }


        //---------------------------------------
        //  Assign group ID to authorized member
        //---------------------------------------
        
        function select_group()
        {
        
        }
}

/* End of file ext.ff_member_assign.php */
/* Location: ./system/expressionengine/third_party/ext.member_assign.php */
       
Parse19's avatar
Parse19
44 posts
15 years ago
Parse19's avatar Parse19

This line here:

$this->EE-db->update('extensions', array('version' => $this->version) );

should be:

$this->EE->db->update('extensions', array('version' => $this->version) );

You are just missing the > there so it was throwing a syntax error and causing the blank screen. That should get it going!

       
ffurger's avatar
ffurger
220 posts
15 years ago
ffurger's avatar ffurger

Oh man!

You really have a very good eye - many thanks!

-Franco

       
ffurger's avatar
ffurger
220 posts
15 years ago
ffurger's avatar ffurger

Mmh - not quite there yet…

At least now I get an error message. PHP doesn’t like this line:

$this->EE->db->insert('extensions', $data);

in the activation function.

Here are the error messages:

Message: Undefined property: Assign_group_ext::$EE Message: Trying to get property of non-object

       
Parse19's avatar
Parse19
44 posts
15 years ago
Parse19's avatar Parse19

Where’s that error coming up? When you try to enable extensions?

       
ffurger's avatar
ffurger
220 posts
15 years ago
ffurger's avatar ffurger

Yep, exaclty there.

       
Parse19's avatar
Parse19
44 posts
15 years ago
Parse19's avatar Parse19

Try declaring private $EE; as a class variable.

       
ffurger's avatar
ffurger
220 posts
15 years ago
ffurger's avatar ffurger

I am not exactly an expert in using CodeIgniter :-( How would I do that, exactly?

       
Parse19's avatar
Parse19
44 posts
15 years ago
Parse19's avatar Parse19

It’s not really a CodeIgniter thing so much as a php thing, it’s just declaring it as a class variable like var $name = ‘Assign group’; Instead of putting “var” though, you can declare it as private. So right above the var $name = ‘Assign group’; line, you’d have:

private $EE;
       
ffurger's avatar
ffurger
220 posts
15 years ago
ffurger's avatar ffurger

Hi there:

I found the error. Wasn’t really an error. Turns out that PHP verions 5.2.6 doesn’t seem to like __construct() for the constructor. If I use the actual class name instead, everything works fine …

Now, the EE2 documentatation says the minimum requirements are PHP 5.1.6 and mySQL 4.1. I am running PHP 5.2.6 and SQL 4.1.22. The official PHP 5 documentation for __construct() merely refers to PHP 5.

So … where exactly is the problem here: by the minimum requirements, the EE2 documentation, or somewhere else?

       
Focus Lab Dev Team's avatar
Focus Lab Dev Team
1,129 posts
15 years ago
Focus Lab Dev Team's avatar Focus Lab Dev Team

Interesting. I know that plugins have a bug in EE where you must use the class name instead of __construct() but I’ve never seen this with extensions. I actually have extensions in 2.x that use __construct() without any issue.

       
ffurger's avatar
ffurger
220 posts
15 years ago
ffurger's avatar ffurger

Well, should I report this as a possible bug?

       
Greg Aker's avatar
Greg Aker
6,022 posts
15 years ago
Greg Aker's avatar Greg Aker

can you post, or zip and upload your plugin as it stands now so I can test? The plugin constructor bug was in the template parser, and with the way extensions are instantiated, this shouldn’t be an issue. I wrote the example extension with __construct() and had no issues as you describe.

-greg

       
ffurger's avatar
ffurger
220 posts
15 years ago
ffurger's avatar ffurger

I think I found out what was going on - a simple typo on my part: instead of “__construct” I had “__constructor”. So obviously the older notation worked, but not the new one …

It’s really embarassing. Sorry for all the fuss and thank you for your help and your patience guys, you really are terrific.

       
Greg Aker's avatar
Greg Aker
6,022 posts
15 years ago
Greg Aker's avatar Greg Aker

Woot! Glad you got it sorted. :D

-greg

       

Reply

Sign In To Reply

ExpressionEngine Home Features Pro Contact Version Support
Learn Docs University Forums
Resources Support Add-Ons Partners Blog
Privacy Terms Trademark Use License

Packet Tide owns and develops ExpressionEngine. © Packet Tide, All Rights Reserved.