Enable PHP in V4

So I have a chunk of code that requires PHP to enabled and I can't figure out how to enable PHP in v4.



In 3.x and below, you could just enable the line in the config.local.php file, but when I put that line in v4, I still get an error.



This is the code that I need to work:


{php}
$smarty_var = $this->get_template_vars('subci');
$this->assign('subcategories2', fn_get_subcategories($smarty_var));
{/php}




Any ideas?



Thanks,



Brandon

You are using a template tag and then using the PHP code. But the class you are referencing in the template is already destroyed. “$this” is only valid inside a class method or globally within the class. You should not rely on $this being the class pointer to the smarty template class.



If you want to do this in a template (not recommended) do:


{assign var="subcategories2" value=$subc1|fn_get_subcategories}


If you want to do this in a php controller (recommended) then in your controller do:


$view =& Registry:;get('view');
$smartyVar = $view->getTemplateVars('subci');
$view->assign('subcategories2', fn_get_subcategories($smartyVar));


Note that this is based on your code…

I didn't get the answer I was looking for in this thread, but the question is exactly what I would like to know. How to enable php in version 4.0. Anyone?