Follow us on Twitter X-Cart on Facebook Wiki
Shopping cart software Solutions for online shops and malls
 

Creating pages with PHP instead of just HTML

 
Reply
   X-Cart forums > X-Cart 4 > Dev Questions > Changing design
 
Thread Tools Search this Thread
  #1  
Old 08-13-2010, 09:54 AM
 
mikeysweet mikeysweet is offline
 

Newbie
  
Join Date: Sep 2009
Posts: 7
 

Default Creating pages with PHP instead of just HTML

I've written a PHP application that searches a MySQL database based on the input from the user. Basic stuff, nothing too complicated. It's basically 3 pages, the Search, the Results List and the Details page.

The table I search against can be added to the existing database, that way the system only needs to connect to just one database.

I want to integrate this into the X-Cart site I'm building. I want the 3 pages to have all the cart info, navigation, links and other items that are on all the pages. Basically, I just need to use the "content" area. When I added my code to a new page through the "Static Pages" section of X-Cart, none of my PHP code doesn't get executed.

I searched these forums but can't find a way to create PHP pages that will fit right into the site like the Static Pages do.

Any suggestions?
Thanks
__________________
-Mike
X-Cart Gold Version 4.2.2
Reply With Quote
  #2  
Old 08-13-2010, 11:29 AM
 
Shamun Shamun is offline
 

X-Adept
  
Join Date: Jun 2009
Location: North Carolina
Posts: 841
 

Default Re: Creating pages with PHP instead of just HTML

Hello, you need to do several things for this to work.

In the x-cart root you need to add your php files that contain the logic. No display code should be in there.
In the php file, you should also have some lines of code similar to this:

Code:
<?php # # $Id: fileName.php,v 2.0 2010/04/04 07:34:02 pdma Exp $ # #Make sure the server knows its legit require "./auth.php"; #### PUT YOUR CODE BETWEEN THIS LINE ####### #### AND THIS LINE ##### #Make the $main smarty variable to #customThing #This is needed for home_main.tpl $smarty->assign("main","customThing"); #Output all variables possible to home.tpl func_display("customer/home.tpl",$smarty); ?>


Then in skin1/customer/home_main.tpl you will need to add something like this (A good spot is after the {elseif $main eq "subscriptions"} code)
Code:
{elseif $main eq "customThing"} {include file="customer/yourDisplayFile.tpl"}

Then you need to make that file and put your design in it. Remember, the design is using smarty and smarty variables. If you need to use {php} tags in the tpl, then you did something wrong.

The design will be where the rest of the actual content is. If you need to not show stuff on that page that is, for example, shown on the welcome page then you need to do a little more modification.
You may also change the func_display("customer/home.tpl",$smarty); to a different .tpl file with an entirely new design.
__________________
- Shane Munroe
Reply With Quote

The following user thanks Shamun for this useful post:
am2003 (08-16-2010)
  #3  
Old 08-13-2010, 12:15 PM
  gb2world's Avatar 
gb2world gb2world is offline
 

X-Wizard
  
Join Date: May 2006
Location: Austin, TX
Posts: 1,970
 

Default Re: Creating pages with PHP instead of just HTML

An example is here.
__________________
X-CART (4.1.9,12/4.2.2-3/4.3.1-2/4.4.1-5)-Gold
(CDSEO, Altered-Cart On Sale, BCSE Preorder Backorder, QuickOrder, X-Payments, BCSE DPM Module)
Reply With Quote
  #4  
Old 09-05-2010, 07:30 PM
 
crcool75 crcool75 is offline
 

Advanced Member
  
Join Date: Jan 2006
Posts: 87
 

Default Re: Creating pages with PHP instead of just HTML

Tal,

What do you mean by "No display code should be in there"?
__________________
X-Cart Gold 4.4.0
Reply With Quote
  #5  
Old 09-05-2010, 07:50 PM
 
Shamun Shamun is offline
 

X-Adept
  
Join Date: Jun 2009
Location: North Carolina
Posts: 841
 

Default Re: Creating pages with PHP instead of just HTML

Quote:
Originally Posted by crcool75
Tal,

What do you mean by "No display code should be in there"?

PHP files are for logic. PHP works with logic faster than smarty.
TPL files are for display. Smarty works with templates and caching and such faster than with logic. Performance will drop with php stuff inside TPL files.

All the info needed to be displayed should be passed as variables to the TPLs which then format it as needed.
So something like below wouldn't be advised in a php file:
Code:
<? $var = 123456; echo $var; ?>

Instead it should be:
Code:
$var = 123456; $smarty->assign("var",$var);


The reverse is true for TPLs.
Bad:
Code:
{php} $var1 = 1; $var2 = 1; $var3 = $var1 + $var 2; {/php} {$var3}

Good:
PHP File:
Code:
$var1 = 1; $var2 = 1; $var3 = $var1 + $var2; $smarty->assign("varName",$var3);
TPL file:
Code:
{$var3}
__________________
- Shane Munroe
Reply With Quote
  #6  
Old 09-05-2010, 10:48 PM
 
crcool75 crcool75 is offline
 

Advanced Member
  
Join Date: Jan 2006
Posts: 87
 

Default Re: Creating pages with PHP instead of just HTML

Thanks, Tal... I understand.

I've read over your reply on this thread and interested in trying to write a small custom mod. I have limited PHP/Smarty skills, but think I have enough to do this.

I'm trying to create a shipping request form. It's just like the Contact Us form, but with different fields. The fields will be different sizes, etc. I want to do more than just add additional fields to the contact form. I've experimented with the additional fields and have a basic understanding. The problem is v4.4.0 has a bug with the Contact Us additional fields. They don't get sent with the email that goes out. I've reported this to the Qualiteam bug list.

Anyway, I'm trying to create a simple PHP mailer form to send shipping requests to the support department. However, I want it integrated with X-Cart, not a seperate form. I've created advanced mailer forms using PHP code scripts, but I can't get them in X-Cart as their too complicated. The code I use echo's the HTML out and may use more than one PHP file. I've having trouble integrating this into X-Cart using Smarty. Any help from you would be greatly appreciated.
__________________
X-Cart Gold 4.4.0
Reply With Quote
  #7  
Old 09-06-2010, 12:34 AM
 
Shamun Shamun is offline
 

X-Adept
  
Join Date: Jun 2009
Location: North Carolina
Posts: 841
 

Default Re: Creating pages with PHP instead of just HTML

I would suggest three files.
1) quote.php [Contains any php code that may be required to display, such as pulling variables from the DB. Sets $main and other stuff]
2) quoterequest.php [Contains the mailer. Put in xcart root]
3) quote.tpl [skin1/customer/ and includes the form]


quote.php has logic for displaying the page. Sets the $main var. Pushes rest into $smarty
quote.tpl shows on quote.php after modification to home_main.tpl. This file also contains the html form which has the action set as quoterequest.php
quoterequest.php accepts the vars and sends the mail
__________________
- Shane Munroe
Reply With Quote
  #8  
Old 09-06-2010, 01:54 PM
 
crcool75 crcool75 is offline
 

Advanced Member
  
Join Date: Jan 2006
Posts: 87
 

Default Re: Creating pages with PHP instead of just HTML

Ok, I see your logic. However, I don't quite understand how you would access this new page. Would I be creating a static page? How would the web server know to display the new page? Would it be a link something like /home.php?mode=quote ?
__________________
X-Cart Gold 4.4.0
Reply With Quote
  #9  
Old 09-06-2010, 02:31 PM
 
Shamun Shamun is offline
 

X-Adept
  
Join Date: Jun 2009
Location: North Carolina
Posts: 841
 

Default Re: Creating pages with PHP instead of just HTML

Quote:
Originally Posted by crcool75
Ok, I see your logic. However, I don't quite understand how you would access this new page. Would I be creating a static page? How would the web server know to display the new page? Would it be a link something like /home.php?mode=quote ?

quote.php is what is accessed by the user. It will be accessed via http://www.exaple.com/quote.php . In the quote.php file you will need to set the $main var like this:
Code:
$smarty->assign("main","quotereq");

Then in home_main.php you can set an elseif like this:

Code:
{elseif $main eq 'quotereq'} {include file="customer/main/quote.tpl"}

So now you got the display working.



Also, you may actually want to move the quoterequest.php which sends the email to a different directory such as /include/ so people cant access it directly.
__________________
- Shane Munroe
Reply With Quote
  #10  
Old 09-06-2010, 03:16 PM
 
crcool75 crcool75 is offline
 

Advanced Member
  
Join Date: Jan 2006
Posts: 87
 

Default Re: Creating pages with PHP instead of just HTML

Understood... I'm creating a form for the user to enter the data we need. What would the form action be and would the form be in the .tpl file?
__________________
X-Cart Gold 4.4.0
Reply With Quote
Reply
   X-Cart forums > X-Cart 4 > Dev Questions > Changing design



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

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Forum Jump


All times are GMT -8. The time now is 04:31 AM.

   

 
X-Cart forums © 2001-2020