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

Adding a new page that contains a php code?

 
Closed Thread
   X-Cart forums > X-Cart 5 > Dev Questions (X-Cart 5)
 
Thread Tools Search this Thread
  #1  
Old 07-17-2016, 01:24 AM
 
Ed B. Ed B. is offline
 

X-Adept
  
Join Date: Apr 2016
Posts: 460
 

Default Adding a new page that contains a php code?

The knowledge base has this page explaining how to add new page.

It works fine if I only put html contents in the page, but would there be
any way to put php code in the new page?

For example, if I put
Code:
<? echo "hello world"; ?>
in the body.tpl, then I get an internal error on the new page. Putting
the same code in the viewer, at the end of the file, gives what I expect. However, if I put
Code:
<? $a="hello world"; echo $a; ?>
instead, then the entire site gets messed up. Would anyone know how to achieve this? Thank you in advance.
__________________
X-cart 5.2.12, php 5.6
Ed from Grenoble, France
  #2  
Old 07-17-2016, 05:17 AM
  cflsystems's Avatar 
cflsystems cflsystems is offline
 

Veteran
  
Join Date: Apr 2007
Posts: 14,201
 

Default Re: Adding a new page that contains a php code?

All php code goes to classes files. You can't put any of it in the templates. If you need something on the page to show dynamically you have to make a call to the class file from the template which will return whatever you need to show.
There are other examples in the KB to show you how to do this
__________________
Steve Stoyanov
CFLSystems.com
Web Development
  #3  
Old 07-17-2016, 07:41 AM
 
Ed B. Ed B. is offline
 

X-Adept
  
Join Date: Apr 2016
Posts: 460
 

Default Re: Adding a new page that contains a php code with variables?

Thank you for pointing me to KB examples. I tried to follow http://kb.x-cart.com/display/XDD/Working+with+viewer+classes and it goes fine if I add
Code:
protected function myVariable() { return "Hello World!"; }
to the viewer class. However, instead, if I write
Code:
protected function myVariable() { $mynewvariable="Hello World!"; return $mynewvariable; }
then the entire site gets messed up. So, I reformulate my question: would there be a way to use variables in the codes for added pages?
__________________
X-cart 5.2.12, php 5.6
Ed from Grenoble, France
  #4  
Old 07-18-2016, 12:47 AM
  qualiteam's Avatar 
qualiteam qualiteam is offline
 

X-Guru
  
Join Date: Dec 2010
Posts: 6,373
 

Default Re: Adding a new page that contains a php code?

The above change should not cause any errors. Please check the syntax (you might miss a letter) and make sure that quotes are " and ' (sometimes when you copy the source code from a website quotes become wrong characters).

Do you see any error messages in log files that are located in the var/log/ directory?
__________________
Alex Solovev,
Qualiteam

---

User manual Video tutorials X-Cart FAQ

You are welcome to press "Thanks" button
if you find this post useful

Click here to learn how to apply patches

X-Cart Extensions

The following user thanks qualiteam for this useful post:
Ed B. (07-18-2016)
  #5  
Old 07-18-2016, 05:30 AM
 
Ed B. Ed B. is offline
 

X-Adept
  
Join Date: Apr 2016
Posts: 460
 

Default Re: Adding a new page that contains a php code?

Oh, thank you very much. According to php_errors.log, I must have put
'' '' (twice single quotes) instead of " " (once double quotes)

Next time, I will check log files before posting here asking for answer, promised.
__________________
X-cart 5.2.12, php 5.6
Ed from Grenoble, France

The following user thanks Ed B. for this useful post:
qualiteam (07-18-2016)
Closed Thread
   X-Cart forums > X-Cart 5 > Dev Questions (X-Cart 5)



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may 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 09:39 AM.

   

 
X-Cart forums © 2001-2020