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

Code for making plugins work in both EE1 and EE2

Development and Programming

Adam Khan's avatar
Adam Khan
319 posts
15 years ago
Adam Khan's avatar Adam Khan

In order to make things cleaner and easier, my small handful of plugins run on both EE1 and EE2. This is handled with a standard bit of code at the beginning of each one:

// Are we running EE 1.x or 2.x?
global $TMPL, $DB, $REGX;
$version = "";
if ( $TMPL )
{
    $version = "1";
}
else
{
    $version = "2";
}
if ($version == "2")
{
    $this->EE =& get_instance();
    $TMPL = $this->EE->TMPL;
    $DB = $this->EE->db;
    $REGX = $this->EE->security;
}

Okay, so it’s not exactly the Solspace Bridge, but it does work. At least, for some plugins, in some circumstances. My problem is that in one plugin, Tied Entries, in some circumstances, it doesn’t work.

The problem showed up when using the plugin to help with some relatively complex relationship handling. It’s called in an embedded template (#1), and called again within a further embedded template (#2) within an channel:entries tag. The plugin works within template #1 but only works once within template #2; in subsequent loops through the channel:entries tag the plugin doesn’t work. Some elementary debugging suggests that it doesn’t seem to accept the

$this->EE =& get_instance();

declaration.

The plugin is using

require_once PATH_MOD.'channel/mod.channel'.EXT;

and I’m wondering if that could be the problem?

       

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.