| ||||||||||
Shopping cart software Solutions for online shops and malls | ||||||||||
|
X-Cart Home | FAQ | Forum rules | Calendar | User manuals | Login |
Proper way for query functionality | ||||
|
|
Thread Tools | Search this Thread |
#1
|
|||||||
|
|||||||
Proper way for query functionality
Hello,
What is the proper way to perform a db query -> saving the query as a smarty variable -> accessing the variable in the frontend tpl files? Is there documentation available for such tasks? I've searched around and cannot find any information on this. -S
__________________
Thanks. |
|||||||
#2
|
|||||||||
|
|||||||||
Re: Proper way for query functionality
PHP Code:
|
|||||||||
|
#3
|
|||||||
|
|||||||
Re: Proper way for query functionality
Thank You Cherie.
Does the PHP file need to live in a specific directory? or just somewhere in the root of the app? Also, by assigning the smarty var, does it automatically make it available through out the app or do I need to do anything in the TPL file to make it available in that file? Thank you so much for the insight. Sergio
__________________
Thanks. |
|||||||
#4
|
|||||||||
|
|||||||||
Re: Proper way for query functionality
This will depend on what you need and how you intend to use it.
You can look at root/product.php for example how the php file is structured and the query called to collect initial product info. The smarty assign is in there too. The tpl file is skins/common_files/customer/main/product.tpl - you can see there how the smarty $product variable is used.
__________________
Steve Stoyanov CFLSystems.com Web Development |
|||||||||
|
#5
|
|||||||
|
|||||||
Re: Proper way for query functionality
Thank you cflsystems,
I have tried a simple string example, and cannot get to display it on the product.tpl. Here's what I have so far (I followed from Smarty's documentation).... PHP FILE: PHP Code:
TPL FILE: PHP Code:
The php file is a new php file in the root dir, and the tpl file is the product.tpl under skin/common_files/customer/main/ Thank you for your help. -S
__________________
Thanks. |
|||||||
#6
|
|||||||||
|
|||||||||
Re: Proper way for query functionality
The cart does all of this for you if you follow the example from product.php. At the top it calls the important stuff that include setting up the new Smarty object. At the bottom it handles display itself. Also make sure you are looking at the right skin directory as set in Appearance options.
|
|||||||||
#7
|
|||||||
|
|||||||
Re: Proper way for query functionality
I've tried a barrage of different combinations of including bits and pieces from the product.php file to my new file, but nothing as yielded any positive results in the product.tpl file. Here's the current code in my new php file taken straight from the product.php, just added my simple smarty element - maybe I'm missing some additional things....
PHP Code:
I'm assuming anything above the new smarty declaration is the necessary things for Smarty, and the last line for display purposes. BTW: I am on version 4.6.1 Thanks Guys! -S
__________________
Thanks. |
|||||||
#8
|
|||||||||
|
|||||||||
Re: Proper way for query functionality
You don't need to start new smarty object. This is done by XC when calling auth.php. When you do this you overwrite the already created smarty object.
Also product.tpl and any other main template will show based on what the $main variable value is. So what you have will not show your variable in product.tpl Check this out - https://help.x-cart.com/index.php?title=X-Cart:Generating_module_distribution_packs_for_X-Cart_4 You don't need the portion "installation" but it will show you an empty module and its way of connecting/working with the system
__________________
Steve Stoyanov CFLSystems.com Web Development |
|||||||||
#9
|
|||||||
|
|||||||
Re: Proper way for query functionality
Thank you for that link...it totally helped me.
I have it kind of working, but not sure about one thing... I guess the only thing I was missing was the inclusion of the Smarty var in the home_main.tpl file. My question (or unsure about) is, If you run an elseif on the smarty variable but the value is a php variable storying the real value (like I have above), how do you insert the php variable in the elseif statement? Here's what I have and it is working, but I would like to check if it is available before continuing. PHP Code:
I tried something like this, but i get a "Page not Found"... PHP Code:
Would a .... ne ' ' suffice in this case? Thank you all for your help, you've been a huge help in understanding how everything is wired up. -S
__________________
Thanks. |
|||||||
#10
|
|||||||||
|
|||||||||
Re: Proper way for query functionality
{elseif $testing eq $testMssg}
implies both variable have same value in order to load product.tpl. So most likely your $testMssg is empty. You cannot call php variable directly in smarty templates. Not this way at least. If you need to make this check assign the $testMssg variable to smarty from the php file
__________________
Steve Stoyanov CFLSystems.com Web Development |
|||||||||
|
|||
X-Cart forums © 2001-2020
|