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

Data in constructor not used on second call of plugin?

Development and Programming

Erin Dalzell's avatar
Erin Dalzell
790 posts
17 years ago
Erin Dalzell's avatar Erin Dalzell

Here is my plugin pseudo-code:

class myPlugin
{
  var foo = '';

  myPlugin()
  {
    foo = 'bar';
  }

  function method1()
  {
     echo $foo;
  }

  function method2()
  {
     echo $foo;
  }
}

And my template code:

{exp:myPlugin:method1}
...
  {exp:myPlugin:method2}
  ...
  {/exp:myPlugin:method2}
...
{/exp:myPlugin:method1}

The method2 call will print out nothing, instead of ‘foo’. Is that intentional?

       
Mr. Wilson's avatar
Mr. Wilson
131 posts
17 years ago
Mr. Wilson's avatar Mr. Wilson

Is your sample actually supposed to be:

class myPlugin
{
  var foo = '';

  myPlugin()
  {
    $this->foo = 'bar';
  }

  function method1()
  {
     echo $this->foo;
  }

  function method2()
  {
     echo $this->foo;
  }
}
       
Erin Dalzell's avatar
Erin Dalzell
790 posts
17 years ago
Erin Dalzell's avatar Erin Dalzell

Yes, keep in mind it was just pseudo code. The issue still exists however.

       
Erin Dalzell's avatar
Erin Dalzell
790 posts
17 years ago
Erin Dalzell's avatar Erin Dalzell

Anyone?

       
Derek Jones's avatar
Derek Jones
7,561 posts
17 years ago
Derek Jones's avatar Derek Jones

Pseudo-code still needs to be accurate, particularly when you are discussing the possibility of something not working. So, what’s different between your actual code and what Mr. Wilson posted?

       
Erin Dalzell's avatar
Erin Dalzell
790 posts
17 years ago
Erin Dalzell's avatar Erin Dalzell

Mr. Wilson’s code is what I have.

       
Derek Jones's avatar
Derek Jones
7,561 posts
17 years ago
Derek Jones's avatar Derek Jones

And how are you using it? Are you getting any errors? To be sure, the full syntax-error-free version is:

class myPlugin
{
  var $foo = '';

  function myPlugin()
  {
    $this->foo = 'bar';
  }

  function method1()
  {
     echo $this->foo;
  }

  function method2()
  {
     echo $this->foo;
  }
}
       
Erin Dalzell's avatar
Erin Dalzell
790 posts
17 years ago
Erin Dalzell's avatar Erin Dalzell

This is the offending line:

<a href="http://{path=gallery/index}">Gallery Home</a> <b>›</b> {exp:gallery_categoree:parent_category}<a href="http://{path=gallery/cat}{parent_name}">{parent_name}</a> <b>›</b> {cat_name}{/exp:gallery_categoree:parent_category}

I will attach both the plugin and the template file.

       
Derek Jones's avatar
Derek Jones
7,561 posts
17 years ago
Derek Jones's avatar Derek Jones

Turn on the template parsing log, Erin. I don’t believe the problem has anything to do with the constructor or class values, but that your nested plugin simply isn’t being called. In your example code, you left out a crucial detail of parse=”inward”.

       
Erin Dalzell's avatar
Erin Dalzell
790 posts
17 years ago
Erin Dalzell's avatar Erin Dalzell

In the only plugin call surrounding my parent_categoree one, I do have this:

{exp:gallery_categoree:categories gallery="{gallery_name}" parse="inward"}

Do I need to put it in another place?

       
Derek Jones's avatar
Derek Jones
7,561 posts
17 years ago
Derek Jones's avatar Derek Jones

Was I right about the plugin not being called?

       
Erin Dalzell's avatar
Erin Dalzell
790 posts
17 years ago
Erin Dalzell's avatar Erin Dalzell
Was I right about the plugin not being called?

I don’t think you were right, but maybe I am reading the log incorrectly:

(0.506711) Calling Class/Method: Gallery_categoree/parent_category
(0.506865) -> Class Called: Gallery_categoree
(0.527692) -> Method Called: parent_category
(0.530037) -> Data Returned

Should I attached the entire log?

       
Derek Jones's avatar
Derek Jones
7,561 posts
17 years ago
Derek Jones's avatar Derek Jones

First, make a reduction template with the most basic example, akin to your original post in this thread. Just those two tags, and the only line of tagdata being the one you are calling the nested plugin. Then please post the template and the parsing log for that reduction test.

       
Erin Dalzell's avatar
Erin Dalzell
790 posts
17 years ago
Erin Dalzell's avatar Erin Dalzell

Template:

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">

<head>
    {embed="common/html-head"}
    <style type='text/css' media='screen'>@import "{stylesheet=gallery/gallery_css}";</style>
</head>

<body>

<div id="wrapper">
    {embed="common/header"}

    <div id="content-wrapper">
        {exp:gallery_categoree:categories gallery="{gallery_name}" parse="inward"}
                <div id="content">
                <h3 class="gallery-breadcrumb">
                    <a href="http://{path=gallery/index}">Gallery Home</a> <b>›</b> {exp:gallery_categoree:parent_category}<a href="http://{path=gallery/cat}{parent_name}">{parent_name}</a> <b>›</b> {cat_name}{/exp:gallery_categoree:parent_category}
                </h3>
            </div> <!-- content -->
            {/exp:gallery_categoree:categories}
    </div> <!-- content-wrapper -->
</div> <!-- wrapper -->
</body>
</html>

Debug log attached.

       
Derek Jones's avatar
Derek Jones
7,561 posts
17 years ago
Derek Jones's avatar Derek Jones

Let’s reduce this further, okay? Eliminate all noise - you don’t need markup, and you don’t need embeds. In this code below, identify which variables are parsed by which tag, and what the unexpected behavior is.

{exp:gallery_categoree:categories gallery="{gallery_name}" parse="inward"}
    {exp:gallery_categoree:parent_category}
        {parent_name}
        {cat_name}
    {/exp:gallery_categoree:parent_category}
{/exp:gallery_categoree:categories}
       
1 2

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.