tags:

views:

80

answers:

2

Hello,

I am working on smarty template files.

core php of that template engine are encoded with ioncube.

So I am restricted to get certain values on certain pages only.

For Example,

I get value of {$clientemail} only on clientareadetails.php

on clientprofile.php value of {$clientemail} is null

So, Is it possible to fetch values using smarty, php, JQuery from another page ?

All my pages are residing on single domain only.

Any help will be appreciated.

Thank You!

A: 

You can use $.get function of jQuery to get data from any php script using ajax.

Vikash
Not a good way to get hold of a Smarty template variable defined in another PHP file.
Pekka
+1  A: 

You should assign all needed variables to Smarty from the PHP end. Don't use Ajax for this.

If $clientemail is a fixed value in your script, the best way would be to keep a central configuration array with all values in a PHP file, including that file in every script instance (include "conf.php"), and passing that array as a Smarty variable.

 $conf = array();
 $conf["clientemail"] = "[email protected]";

 ...........

 $Smarty = new Smarty();  // or whichever way you do it
 $Smarty->assign("conf", $conf);

 ............

 Then in the template:
 {$conf.clientemail}

If $clientemail is a user-entered value, you could store it in $_SESSION (if you have a session running) and fetch it:

 In the PHP script that processes the form:
 $_SESSION["clientemail"] = ..... wherever clientemail comes from

 ...........

 $Smarty = new Smarty();  // or whichever way you do it
 $Smarty->assign("clientemail", $_SESSION["clientemail"]);

 ............

 Then in the template:
 {$clientemail}

Note that this example will give you trouble if the user has two or more windows open and is filling out the same form at the same time: $_SESSION["clientemail"] would be overwritten by each form submission.

Pekka
Couldn't agree more. Doing that via ajax is super lame.
rochal