Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8490969
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 10, 20262026-06-10T22:16:48+00:00 2026-06-10T22:16:48+00:00

I am working with lemonade-php. My code is at https://github.com/sofadesign/limonade . The issue I

  • 0

I am working with lemonade-php. My code is at https://github.com/sofadesign/limonade.

The issue I am having is when I try to run

class syscore {

    public function hello(){
        set('post_url',  params(0));
        include("./templates/{$this->temp}/fullwidth.tpl"); 
        return render('fullwidth');

    }

}

which then loads the fullwidth.tpl and runs function fullwidth

fullwidth.tpl

<?php

global $post;
function fullwidth($vars){ 
    extract($vars);
    $post = h($post_url);

}

    print_r($this->post($post));    

?>

it seems to pass the $post_url but I can not pass it again to the print_r($this->post($post));

However when I try to run print_r($this->post($post)) inside the fullwidth function it says it can not find the post() function

I have tried a number of things like below

function fullwidth($vars){ 
        extract($vars);
        $post = h($post_url);
    print_r(post($post));
}

I tried re connecting to the syscore by

$redi = new syscore();
$redi->connection() <-- this works
$redi->post($post) <-- this does not

Here is my full class syscore

class syscore {

    // connect
    public function connect($siteDBUserName,$siteDBPass,$siteDBURL,$siteDBPort, $siteDB,$siteTemp){
        for ($i=0; $i<1000; $i++) {
         $m = new Mongo("mongodb://{$siteDBUserName}:{$siteDBPass}@{$siteDBURL}:{$siteDBPort}", array("persist" => "x", "db"=>$siteDB));
        }

        // select a database
       $this->db = $m->$siteDB;
       $this->temp = $siteTemp;
    }

    public function hello(){
        set('post_url',  params(0));
        include("./templates/{$this->temp}/fullwidth.tpl"); 
        return render('fullwidth');

    }

    public function menu($data)
    {

        $this->data = $data;
        $collection = $this->db->redi_link;
        // find everything in the collection
        //print $PASSWORD;
        $cursor = $collection->find(array("link_active"=> "1"));

        if ($cursor->count() > 0)
        {
            $fetchmenu = array();
            // iterate through the results
            while( $cursor->hasNext() ) {   
                $fetchmenu[] = ($cursor->getNext());
            }
            return $fetchmenu;
        }
        else
        {
            var_dump($this->db->lastError());
        }
    }

    public function post($data)
    {

        $this->data = $data;
        $collection = $this->db->redi_posts;
        // find everything in the collection
        //print $PASSWORD;
        $cursor = $collection->find(array("post_link"=> $data));

        if ($cursor->count() > 0)
        {
            $posts = array();
            // iterate through the results
            while( $cursor->hasNext() ) {   
                $posts[] = ($cursor->getNext());
            }
            return $posts;
        }
        else
        {
            var_dump($this->db->lastError());
        }
    }

}
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-10T22:16:50+00:00Added an answer on June 10, 2026 at 10:16 pm

    It looks like you are having some issues understanding the execution path that PHP is taking when trying to render your template. Let’s take a more in-depth look, shall we?

    // We're going to call "syscore::hello" which will include a template and try to render it
    public function hello(){
        set('post_url',  params(0));  // set locals for template
        include("./templates/{$this->temp}/fullwidth.tpl");  // include the template
        return render('fullwidth'); // Call fullwidth(array('post_url' => 'http://example.com/path'))
    }
    

    The trick to solving this one is to understand how PHP include works. When you call include("./templates/{$this->temp}/fullwidth.tpl") some of your code is executing in the scope of the syscore object, namely:

    global $post;
    

    and

    print_r($this->post($post));
    

    fullwidth is created in the global scope at this point, but has not yet been called. When render calls fullwidth you’re no longer in the syscore scope, which is why you cannot put $this->post($post) inside without triggering an error.

    Ok, so how do we solve it? Glad you asked.

    1. We could probably refactor syscore::post to be a static method, but that would then require syscore::db to be static, and always return the SAME mongodb instance (singleton pattern). You definitely do not want to be creating 1000 Mongo instances for each syscore instance.

    2. We could just abuse the framework. A much poorer solution, but it will get the job done.

    fullwidth.tpl

    <?php
    
    function fullwidth($vars){ 
        $post_url = ''; // put the variables you expect into the symbol table
        extract($vars, EXTR_IF_EXISTS); // set EXTR_IF_EXISTS so you control what is added.
        $syscore_inst = new syscore; 
        $post = h($post_url);
        print_r($syscore->post($post)); // I think a puppy just died.    
    }
    

    Look the second way is a complete hack, and writing code like that will probably mean you won’t get promoted. But it should work.

    But let’s say you wanted to get promoted, you would make good, shiny code.

    // Note: Capitalized class name
    class Syscore {
    protected static $_db;
    
    public static function db () {
        if (! static::$_db) {
            static::$_db = new Mongo(...);
        }
        return static::$_db;
    }
    
    // @FIXME rename to something more useful like "find_posts_with_link"
    public static post($url) {
        $collection = static::db()->redi_posts;
        // find everything in the collection
        $cursor = $collection->find(array("post_link"=> $url));
    
        // Changed to a try-catch, since we shouldn't presume an empty find is
        // an error.
        try {
            $posts = array();
            // iterate through the results
            while( $cursor->hasNext() ) {   
                $posts[] = ($cursor->getNext());
            }
            return $posts;
        } catch (Exception $e) {
            var_dump($this->db->lastError());
        }
    }
    
    }
    

    Then in your fullwidth function, we don’t have to do any of that stupid nonsense of treating an instance method like it were a static method.

    function fullwidth($vars){ 
        $post_url = ''; // put the variables you expect into the symbol table
        extract($vars, EXTR_IF_EXISTS); // set EXTR_IF_EXISTS so you control what is added.
        $post = h($post_url);
        print_r(Syscore::post($post)); // static method. \O/ Rainbows and unicorns.   
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Here's the XML code i'm working with: <inventory> <drink> <lemonade supplier=mother id=1> <title>Super Lemonade</title>
Working with COM interop, I can call a managed function from within unmanaged code.
Here's the XML code I'm working with: <inventory> <drink> <lemonade supplier=mother id=1> <price>$2.50</price> <amount>20</amount>
Working with Reporting Services 2008 r2. So here's my issue: We have 5 reports
Working with H2 I get this error when I try to write a row
Working on the problems on Project Euler to try to learn Clojure. I'm on
Working on a website http://www.ArenaText.com written in asp.net with Microsoft AJAX control toolkit. iPad
Working through the five minute Xtext tutorial (http://www.eclipse.org/Xtext/documentation/2_1_0/010-xtext-in-5-minutes.php) I get to Generating The Language
Working with the Box2djs plugin here: http://www.crackin.com/dev/mms/physics/ ... and all I'm trying to do
Working with Json, how can I NSlog only the title in this code: NSDictionary

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.