Page 1 of 1

PHP Variables

Posted: Thu Nov 27, 2008 3:04 am
by leetrade
Hello all,

I'm new to OpenCart and am working to learn its structure so I can best make design changes to suit my web store.  As there is currently no documentation available for cusomization, etc. I'm exploring these key components on my own and making notes as I go along (I'll be happy to share what I discover).

As a newbie and an old school programmer I'm first puzzled by where the variables used in the PHP and TPL files are loaded, modified, etc. 

Here's a simple example from the home.tpl file:

div class="heading">

So where does the $heading_title variable come from?  How can it be modified?  Can anyone shed any light on this?  Sorry if this is too basic a question, but I'm just cutting my teeth on this stuff.

Re: PHP Variables

Posted: Thu Nov 27, 2008 3:12 am
by hm2k
It's exported via the "view" library class.

It takes a bit of time to get to grips with, but you'll pick it up...

Re: PHP Variables

Posted: Thu Nov 27, 2008 3:54 am
by leetrade
By "exported" so you mean pulled from a table in the MySQL database? Or perhaps a file on the server?  Also, how does one make changes to these variables?  Thank you for your insights.

Re: PHP Variables

Posted: Thu Nov 27, 2008 4:10 am
by Qphoria
Pay no attention to all those big words..  ;)

The setup is based on 3 main components:

Controller files = code
Language files = language
Template files = display or view

Using your question as an example, in the catalog/controller/home.php file there is:
$view->set('$heading_title', $language->get('heading_title');

which shows that it is setting a variable in the view to the value of the language heading_title.

If you want to change the contents, then you'd change the catalog/language/english/controller/home.php file under the "heading_title" variable

means that the variable that the controller file knows as "mainaction", it is passing it to a view variable called simply $action. So in the controller you'd be changing the code for $mainaction and in the tpl file you'd be referencing just $action

Re: PHP Variables

Posted: Thu Nov 27, 2008 4:22 am
by leetrade
Many thanks Q!  . . . a hint of light now appears for me.  I appreciate your breakdown.  Now I'm off to explore these further.

Re: PHP Variables

Posted: Thu Nov 27, 2008 4:24 am
by hm2k
I actually meant extract which is the way the template system extracts the variables.