|
Smarty
WARNING: All discussion is moving to https://reddit.com/r/smarty, please go there! This forum will be closing soon. |
|
View previous topic :: View next topic |
Author |
Message |
MrVon Smarty Rookie
Joined: 08 Jul 2011 Posts: 15
|
Posted: Thu Mar 22, 2012 6:55 am Post subject: How to assign $smarty object to to php function? |
|
|
index.php
Code: |
require_once('smarty/Smarty.class.php');
$Smarty = new Smarty();
function do_something() {
global $Smarty;
echo "where is smarty?"
var_dump($Smarty);
$ObjSmarty->assign("teams_list", $teams_list);
}
get_active_teams(); |
Nothing dumps and error assigning...
Code: |
require_once('smarty/Smarty.class.php');
$Smarty = new Smarty();
function do_something() {
global $Smarty;
echo "where is smarty?"
var_dump($GLOBALS);
var_dump($GLOBALS["Smarty"]);
}
get_active_teams(); |
dump of globals shows Smarty and when i dump $globals["smarty"] nothing. Whats going on.
I don't have class is that the problem?
How can i assign to loaded smarty object inside php function without using declaring class? |
|
Back to top |
|
douglassdavis Smarty Junkie
Joined: 21 Jan 2008 Posts: 541
|
Posted: Thu Mar 22, 2012 12:18 pm Post subject: Re: How to assign $smarty object to to php function? |
|
|
I'm not sure what get_active_teams() function is supposed to be, perhaps that's supposed to be calling do_something()? Also, $ObjSmarty isn't initialized aynwhere.
But, try changing this:
$Smarty = new Smarty();
to this:
$GLOBALS['Smarty'] = new Smarty();
and see what happens. Maybe that code isn't in the global scope. |
|
Back to top |
|
U.Tews Administrator
Joined: 22 Nov 2006 Posts: 5068 Location: Hamburg / Germany
|
Posted: Thu Mar 22, 2012 4:00 pm Post subject: |
|
|
You must decalre $Smarty global alos in the root scope.
Code: | require_once('smarty/Smarty.class.php');
global $Smarty;
$Smarty = new Smarty();
...
|
|
|
Back to top |
|
skycyclone Smarty Rookie
Joined: 18 Dec 2009 Posts: 5
|
Posted: Sat Mar 24, 2012 11:14 am Post subject: I have this situation too |
|
|
updata smarty 3.1.8 have this situation
Code: |
require 'Smarty.class.php';
$smarty = new Smarty;
function get_news_list($str) {
global $smarty;
$list_news = "something";
$smarty -> assign('list_news', $list_news);
}
|
nothing display
Code: |
require 'Smarty.class.php';
$smarty = new Smarty;
function get_news_list($str) {
global $smarty;
$list_news = "something";
echo "echo test";
$smarty -> assign('list_news', $list_news);
}
|
display "echo test";
Code: |
require 'Smarty.class.php';
$smarty = new Smarty;
function get_news_list($str) {
global $smarty;
$list_news = "something";
$smarty -> assign('list_news','test');
}
|
nothing display
Code: |
require 'Smarty.class.php';
$smarty = new Smarty;
function get_news_list($str) {
global $smarty;
$list_news = "something";
print_r($smarty);
$smarty -> assign('list_news', $list_news);
}
|
display some array;
Code: |
require 'Smarty.class.php';
$smarty = new Smarty;
function get_news_list($str) {
global $smarty;
$list_news = "something";
$smarty -> assign('list_news', $smarty);
}
|
display nothing;
Code: |
require 'Smarty.class.php';
$smarty = new Smarty;
function get_news_list($str) {
//global $smarty;
$list_news = "something";
print_r($smarty);
$smarty -> assign('list_news', $list_news);
}
|
display Fatal error: Call to a member function assign() on a non-object;
Code: |
require 'Smarty.class.php';
$smarty = new Smarty;
function get_news_list($str) {
//global $smarty;
$list_news = "something";
print_r($smarty);
//$smarty -> assign('list_news', $list_news);
}
|
display Notice: Undefined variable: smarty
I think this is a bug from 3.1.8;
3.0.6 normal operation |
|
Back to top |
|
U.Tews Administrator
Joined: 22 Nov 2006 Posts: 5068 Location: Hamburg / Germany
|
Posted: Sat Mar 24, 2012 11:25 am Post subject: |
|
|
The last posted examples show all expected results.
Without calling a template with $smarty->display('sometemplate'); Smarty does not output any thing.
The errors you get are errors of your PHP code.
There are no bugs of Smarty. |
|
Back to top |
|
|
|
You cannot post new topics in this forum You cannot reply to topics in this forum You cannot edit your posts in this forum You cannot delete your posts in this forum You cannot vote in polls in this forum
|
Powered by phpBB © 2001, 2005 phpBB Group
|