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 */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!
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
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?
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.
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
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.
Packet Tide owns and develops ExpressionEngine. © Packet Tide, All Rights Reserved.