Data in constructor not used on second call of plugin?
Posted: 06 February 2008 01:28 PM   [ Ignore ]  
Research Assistant
RankRankRank
Total Posts:  996
Joined  11-01-2002

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?

Profile
 
 
Posted: 06 February 2008 02:12 PM   [ Ignore ]   [ # 1 ]  
Research Assistant
Avatar
RankRankRank
Total Posts:  712
Joined  07-02-2007

Quick question:
Don’t you need to use return?

function method2()
  
{
     
return $foo;
  
}

 Signature 

Truly ExpressionEngine


Fielder Module ( Mass Custom Fields )
Super Cache (Cache heavy tag output)
reCAPTCHA Extension
Rewrite Module


See all my EE Addons (8)

Profile
 
 
Posted: 06 February 2008 03:41 PM   [ Ignore ]   [ # 2 ]  
Research Assistant
Avatar
RankRankRank
Total Posts:  749
Joined  08-16-2003

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;
  
}
}

 Signature 

Pst… have you taken a look at Weever yet?

Profile
 
 
Posted: 06 February 2008 04:49 PM   [ Ignore ]   [ # 3 ]  
Research Assistant
RankRankRank
Total Posts:  996
Joined  11-01-2002

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

Profile
 
 
Posted: 08 February 2008 12:20 PM   [ Ignore ]   [ # 4 ]  
Research Assistant
RankRankRank
Total Posts:  996
Joined  11-01-2002

Anyone?

Profile
 
 
Posted: 16 February 2008 11:11 AM   [ Ignore ]   [ # 5 ]  
Administrator
Avatar
RankRankRankRankRankRankRank
Total Posts:  15727
Joined  06-03-2002

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?

 Signature 
Profile
MSG
 
 
Posted: 16 February 2008 11:55 AM   [ Ignore ]   [ # 6 ]  
Research Assistant
RankRankRank
Total Posts:  996
Joined  11-01-2002

Mr. Wilson’s code is what I have.

Profile
 
 
Posted: 16 February 2008 11:57 AM   [ Ignore ]   [ # 7 ]  
Administrator
Avatar
RankRankRankRankRankRankRank
Total Posts:  15727
Joined  06-03-2002

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;
  
}
}

 Signature 
Profile
MSG
 
 
Posted: 17 February 2008 12:49 AM   [ Ignore ]   [ # 8 ]  
Research Assistant
RankRankRank
Total Posts:  996
Joined  11-01-2002

This is the offending line:

<a href="{path=gallery/index}">Gallery Home</a> <b>&#8250;</b> {exp:gallery_categoree:parent_category}<a href="{path=gallery/cat}{parent_name}">{parent_name}</a> <b>&#8250;</b> {cat_name}{/exp:gallery_categoree:parent_category}

I will attach both the plugin and the template file.

File Attachments
EE_files.zip  (File Size: 4KB - Downloads: 79)
Profile
 
 
Posted: 18 February 2008 09:41 AM   [ Ignore ]   [ # 9 ]  
Administrator
Avatar
RankRankRankRankRankRankRank
Total Posts:  15727
Joined  06-03-2002

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”.

 Signature 
Profile
MSG
 
 
Posted: 18 February 2008 09:44 AM   [ Ignore ]   [ # 10 ]  
Research Assistant
RankRankRank
Total Posts:  996
Joined  11-01-2002

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?

Profile
 
 
Posted: 18 February 2008 09:53 AM   [ Ignore ]   [ # 11 ]  
Administrator
Avatar
RankRankRankRankRankRankRank
Total Posts:  15727
Joined  06-03-2002

Was I right about the plugin not being called?

 Signature 
Profile
MSG
 
 
Posted: 18 February 2008 09:57 AM   [ Ignore ]   [ # 12 ]  
Research Assistant
RankRankRank
Total Posts:  996
Joined  11-01-2002
Derek Jones - 18 February 2008 09:53 AM

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?

Profile
 
 
Posted: 18 February 2008 10:05 AM   [ Ignore ]   [ # 13 ]  
Administrator
Avatar
RankRankRankRankRankRankRank
Total Posts:  15727
Joined  06-03-2002

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.

 Signature 
Profile
MSG
 
 
Posted: 18 February 2008 10:20 AM   [ Ignore ]   [ # 14 ]  
Research Assistant
RankRankRank
Total Posts:  996
Joined  11-01-2002

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="{path=gallery/index}">Gallery Home</a> <b>&#8250;</b> {exp:gallery_categoree:parent_category}<a href="{path=gallery/cat}{parent_name}">{parent_name}</a> <b>&#8250;</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.

File Attachments
debug.zip  (File Size: 2KB - Downloads: 87)
Profile
 
 
Posted: 18 February 2008 10:32 AM   [ Ignore ]   [ # 15 ]  
Administrator
Avatar
RankRankRankRankRankRankRank
Total Posts:  15727
Joined  06-03-2002

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}

 Signature 
Profile
MSG
 
 
Posted: 18 February 2008 11:21 AM   [ Ignore ]   [ # 16 ]  
Research Assistant
RankRankRank
Total Posts:  996
Joined  11-01-2002

Sigh…it turns out I had not one, but TWO bugs in my code; one in my template and one in my plugin.

Sorry to make you waste your time Derek… +1 to the number of beers I owe ya!

Profile
 
 
Posted: 18 February 2008 11:30 AM   [ Ignore ]   [ # 17 ]  
Administrator
Avatar
RankRankRankRankRankRankRank
Total Posts:  15727
Joined  06-03-2002

Glad I could help you track them down, Erin.

 Signature 
Profile
MSG
 
 
   
 
 
Post Marker Legend
New Topic New posts Hot Topic Hot Topic with new posts New Poll New Poll Moved Topic Moved Topic Sticky Topic Sticky topic
Old Topic No new posts Hot Old Topic Hot Topic with no new posts Old Poll Old Poll Closed Topic Closed Topic Announcement Announcements
Theme
Change Theme
Visitor Statistics
The most visitors ever was 1149, on July 16, 2007 09:33 AM
Total Registered Members: 64492 Total Logged-in Users: 66
Total Topics: 81035 Total Anonymous Users: 28
Total Replies: 436073 Total Guests: 294
Total Posts: 517108    
Members ( View Memberlist )