Skip to content

Instantly share code, notes, and snippets.

@s4l1h
Last active November 9, 2017 14:08
Show Gist options
  • Select an option

  • Save s4l1h/3e6ac443e2c65d16e52f3fbc99ac52fa to your computer and use it in GitHub Desktop.

Select an option

Save s4l1h/3e6ac443e2c65d16e52f3fbc99ac52fa to your computer and use it in GitHub Desktop.
Smarty call_user_func
<?php
// file : /smartyplugins/function.run.php
function smarty_function_run($params, $template)
{
//var_dump($params);
if ($params['method'] == '') {
trigger_error("url: run Komutunda method parametresi boş olamaz.");
return;
}
call_user_func($params['method'],array());
//print_r($template);
}
<?php
require '../smarty/libs/Smarty.class.php';
//require '../smartyold/Smarty-3.0.9/libs/Smarty.class.php';
$smarty = new Smarty;
define('DS', DIRECTORY_SEPARATOR);
define('root_dir', DIRNAME(__FILE__) . DS);
$smarty->force_compile = true;
$smarty->debugging = true;
$smarty->caching = false;
$smarty->addPluginsDir(root_dir.'smartyplugins');
function addVariable()
{
global $smarty;
$smarty->assign("variable", "from run");
# code...
}
$smarty->display('index.tpl');
variable is : {var_dump($variable)}
after call run
{*call_user_func("addVariable",array())*}
{run method="addVariable"}
variable is : {var_dump($variable)}
templates/index.tpl
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment