Delphi For PHP Forums       


Go Back   Delphi-PHP Forums > Delphi For PHP > General Information
Forum Jump Register FAQ Members List Downloads Search Today's Posts Mark Forums Read

General Information Heard some interesting news about Delphi for PHP? Post it here.

Reply
 
LinkBack Thread Tools Display Modes
  #1 (permalink)  
Old 6th February 2009, 00:30
fredrm's Avatar
D4PHP User
 
Join Date: Jun 2008
Posts: 45
fredrm is on a distinguished road
Default Help with smarty template + function

Hi Folks! I need some help with functions and smarty template.

I have a function like this:

function Test(){
$a = "This is a test.";
}

and I have a Item Template to show this variable on the smarty template, that go like this:

function Unit1Template($sender, $params){
$this->Test();

$template = $params['template'];
$template->_smarty->assign("test", $a);
}

And my Smarty Template is ok, but nothing shows...

Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
Sponsored Links
  #2 (permalink)  
Old 6th February 2009, 03:08
405hp's Avatar
Firebug Fanatic
 
Join Date: Dec 2007
Location: State of Confusion
Posts: 3,272
405hp has a reputation beyond repute405hp has a reputation beyond repute405hp has a reputation beyond repute405hp has a reputation beyond repute405hp has a reputation beyond repute405hp has a reputation beyond repute405hp has a reputation beyond repute405hp has a reputation beyond repute405hp has a reputation beyond repute405hp has a reputation beyond repute405hp has a reputation beyond repute
Default

debug with die ($a);

Then learn about variable scope on php.net

PHP: Variable scope - Manual
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #3 (permalink)  
Old 6th February 2009, 11:35
fredrm's Avatar
D4PHP User
 
Join Date: Jun 2008
Posts: 45
fredrm is on a distinguished road
Exclamation

But the question is.

How do I get the $a valeu inside of the Unit1Template?

Because when I debug on die($a), the $a inside of the Unit1Template is equals to NULL.

Thx!
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #4 (permalink)  
Old 6th February 2009, 13:09
405hp's Avatar
Firebug Fanatic
 
Join Date: Dec 2007
Location: State of Confusion
Posts: 3,272
405hp has a reputation beyond repute405hp has a reputation beyond repute405hp has a reputation beyond repute405hp has a reputation beyond repute405hp has a reputation beyond repute405hp has a reputation beyond repute405hp has a reputation beyond repute405hp has a reputation beyond repute405hp has a reputation beyond repute405hp has a reputation beyond repute405hp has a reputation beyond repute
Default

That is why I pointed you to variable scope.

In a nutshell vars are private to their function so they aren't usable unless you do something to make them that way. Declare them global is one way. Another is to return them from the function
PHP Code:
function Test(){
$a "This is a test.";
return 
$a;
}

....

$template->_smarty->assign("test"$this->Test()); 
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
Reply


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


All times are GMT +1. The time now is 15:37.




Powered by vBulletin® Version 3.7.3
Copyright ©2000 - 2010, Jelsoft Enterprises Ltd.
Search Engine Friendly URLs by vBSEO 3.3.0 ©2009, Crawlability, Inc.
Copyright © 2004 - 2009, G&J Solutions Ltd. All Rights Reserved. terms of use