[thelist] PHP / smarty
Bob Meetin
bobm at dottedi.biz
Sun Oct 9 13:31:04 CDT 2011
I'm after a simple solution, not something complex. Before emailing the question to the list I did some googling and found something like:
$prod = $this->get_template_vars('product');
Not being very good with arrays I wasn't sure whether this was the right path or if it was, how to extract the ID part. So this gave me a clue and then I guessed.
//$prod = $this->getTemplateVars('product'); // This was erring out maybe due to the way it is installed
$prod = $this->get_template_vars('product');
$product_id = ($prod[0]);
echo "Product ID: $product_id<br>";
This now works perfectly. But silly me, I was also overlooking the obvious, the page URL was outputting an ID in the string ( &id=4 ). So 2 solutions for the price of one, let's market that concept.
Thx, Bob
On 10/09/2011 11:05 AM, David Miller wrote:
>
> The question. How can you convert the smarty ID to a PHP variable that can be used in the PHP/MySQL query?
>
> Something like:
>
> {php}
> $prod = $this->getTemplateVars('product');
> $prod_id = $prod->id
> do_some_database_query($prod_id);
> {/php}
>
> ?
>
> Don't do this :)
> Instead rip out the pointless and redundant Php Template Engine.
>
> If you can't do that, then unless it's deeply insane, the smarty object is getting instantiated and passed existing PHP variables.
>
> Do your database logic there & pass in whatever objects you get back.
>
> --
> Love regards etc
>
> David Miller
> http://www.deadpansincerity.com
> 07854 880 883
>
--
Bob Meetin
dotted i - http://www.dottedi.biz
LinkedIn: http://www.linkedin.com/in/bobmeetin
303-926-0167 (home/business)
More information about the thelist
mailing list