6

I got constant in PHP

This constant is written in Mysql

With Smarty i am doing output to HTML

Is it possible to output Smarty results to php not to HTML

<? {$CONSTANTS_RESULT[LOOP]} ?>

?

Cameleon
  • 453
  • 1
  • 6
  • 16

2 Answers2

8

To access PHP constants in Smarty, you can use {$smarty.const.MY_CONSTANT} which is documented here.

rcapote
  • 1,034
  • 7
  • 19
  • You dont uderstand. I want results from mysql to be threat as constants. In simple word. I want smarty to throw results not to HTML but to PHP, so PHP could use results as Constants. – Cameleon May 30 '11 at 22:11
  • You would send a query to mysql to retrieve the information, then use define() to make it a constant. Smarty is really only for output to html, not for communicating with the database. Define documentation:http://www.php.net/manual/en/function.define.php – rcapote May 30 '11 at 22:21
  • So I can not send Smarty output to PHP ? – Cameleon May 30 '11 at 23:58
1

or:

$smarty->registerFilter('pre',array($this,'preFilterConstants'));

// '#' Const in Smarty...
public function preFilterConstants($strInput, $objSmarty) {
  return preg_replace('|(<!--\{[^\}]+)#([A-Za-z0-9_]+)(.+?\}-->)|si','$1\$smarty.const.$2$3',$strInput);
}

and do:

<? <!--{#MY_CONSTANT}--> ?>

if you want to use other delimiter just edit pattern...

Unknown
  • 11
  • 1