Author Topic: Smarty > PHP  (Read 1164 times)

Offline snw

  • Level 5
  • *
  • Posts: 15
  • Reputation: +0/-0
    • View Profile
Smarty > PHP
« on: May 29, 2010, 11:57:13 AM »
hello i have problem
im decoding from smarty into PHP
and i cant do this

Code: [Select]
{foreach from=$weapons key=id item=i}
To: PHP
can someone help me please ?

EDIT :
+ this
Code: [Select]
<strong>{$i.name}</strong> - <em>{$i.price} gold coins</em>
« Last Edit: May 29, 2010, 12:05:21 PM by snw »

Offline jannesiera

  • Level 35
  • **
  • Posts: 1,026
  • Reputation: +6/-1
    • View Profile
    • BBGameDesign
Re: Smarty > PHP
« Reply #1 on: May 29, 2010, 12:55:59 PM »
Quote

foreach($weapons as $weapon)
{
    echo "<strong>" . $weapon['name'] . "</strong> - <em>" . $weapon['price'] . "gold coins</em>"; // If it's an array
    echo "<strong>" . $weapon->name . "</strong> - <em>" . $weapon->price . "gold coins</em>"; // If it's an object
}


You mean something like that? If you're having troubles with the basics you should refresh it sometimes (this is good place to do just that: http://www.w3schools.com/). That shouldn't stop you from asking off course!
« Last Edit: May 29, 2010, 01:01:11 PM by jannesiera »

Offline snw

  • Level 5
  • *
  • Posts: 15
  • Reputation: +0/-0
    • View Profile
Re: Smarty > PHP
« Reply #2 on: May 29, 2010, 02:11:23 PM »
thank you ! you solved my problem :)

Offline Nox

  • Level 35
  • **
  • Posts: 738
  • Reputation: +12/-2
    • View Profile
Re: Smarty > PHP
« Reply #3 on: May 29, 2010, 02:13:54 PM »
Quote from: Smarty
Smarty compiles templates into PHP code behind the scenes, eliminating run-time parsing of templates.
So maybe you should have it somewhere already done, skim through the folders (on server)
Meet us at an IRC irc.freenode.net #bbg as well
Enjoy http://spiritbeacon.noxart.cz/ !

Offline snw

  • Level 5
  • *
  • Posts: 15
  • Reputation: +0/-0
    • View Profile
Re: Smarty > PHP
« Reply #4 on: May 29, 2010, 02:30:49 PM »
thank for your tip :) ill search for it
hopefully it will work :D

Offline snw

  • Level 5
  • *
  • Posts: 15
  • Reputation: +0/-0
    • View Profile
Re: Smarty > PHP + New Problem
« Reply #5 on: May 29, 2010, 03:07:57 PM »
i've got another problem (sorry im newbie and i cant fix some problems )
still trying to decode from smarty to PHP
Code: [Select]
{foreach from=$combat key=id item=i}
<li><strong>{$i.attacker}</strong> attacks {$i.defender} for {$i.damage} damage!</li>
{/foreach}
i made this
Code: [Select]
foreach ($combat as $cb) {
$cb_attacker = $cb['attacker'];
$cb_defender = $cb['defender'];
$cb_damage = $cb['damage'];
echo "<li><strong>" .$cb_attacker. "</strong> attacks " .$cb_deffender. " for " .$cb_damage. " damage!</li>";
}
and it writes me this
Code: [Select]
Warning: Invalid argument supplied for foreach() in /home/free/ic.cz/s/snw/root/www/explore.php  on line 289Explore .php in attachment

Offline raestlyn

  • Level 29
  • **
  • Posts: 463
  • Reputation: +9/-5
    • View Profile
Re: Smarty > PHP + New Problem
« Reply #6 on: May 29, 2010, 03:15:41 PM »
echo "<li><strong>" .$cb_attacker. "</strong> attacks " .$cb_deffender. " for " .$cb_damage. " damage!</li>";



$cb_deffender? Fix that and see what happens.


I can send you pics of my cocks if you want reference.


Offline Nox

  • Level 35
  • **
  • Posts: 738
  • Reputation: +12/-2
    • View Profile
Re: Smarty > PHP
« Reply #7 on: May 29, 2010, 03:17:28 PM »
No, the error is about foreach's first argument, $combat is not an array at the point
Meet us at an IRC irc.freenode.net #bbg as well
Enjoy http://spiritbeacon.noxart.cz/ !

Offline snw

  • Level 5
  • *
  • Posts: 15
  • Reputation: +0/-0
    • View Profile
Re: Smarty > PHP
« Reply #8 on: May 29, 2010, 03:19:42 PM »
but could that work in smarty lang ?  ???

Offline Nox

  • Level 35
  • **
  • Posts: 738
  • Reputation: +12/-2
    • View Profile
Re: Smarty > PHP
« Reply #9 on: May 29, 2010, 03:26:26 PM »
I must say the code is pretty messy, it's difficult to somehow help you with it (for me at least)
Learn to define and use your own functions (more), more logically divided (newlines etc.), more comments...

but it's probably:
r.275 if ($combat = '') not = but == !
if you had array inside it before, by this you overwrote it with empty string

<p><p><p> &nbsp; &nbsp; &nbsp;
ale fuj ... CSS margin or padding
Meet us at an IRC irc.freenode.net #bbg as well
Enjoy http://spiritbeacon.noxart.cz/ !

Offline snw

  • Level 5
  • *
  • Posts: 15
  • Reputation: +0/-0
    • View Profile
Re: Smarty > PHP
« Reply #10 on: May 29, 2010, 03:29:59 PM »
omg THX it works !  :o
its a pity i cant +rep

// BTW : answer my PM pls :)

// it doesnt :( when i try to attack it writes : "You killed Array!" what's funny but it isnt what i wanted  ;D
« Last Edit: May 29, 2010, 03:32:45 PM by snw »

 


SimplePortal 2.3.3 © 2008-2010, SimplePortal