Last active
April 21, 2020 12:00
-
-
Save ytake/1a6f1d5312b552bc83ff to your computer and use it in GitHub Desktop.
laravel-smarty registerFilter in Controller
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
namespace App\Controllers; | |
class HomeController extends BaseController | |
{ | |
public function showWelcome() | |
{ | |
\View::registerFilter('post', [$this, 'add_header_comment']); | |
// または | |
//$smarty = \View::getSmarty(); | |
//$smarty->registerFilter('post', [$this, 'add_header_comment']); | |
return \View::make('hello'); | |
} | |
/** | |
* @param $tpl_source | |
* @param $smarty | |
* @return string | |
*/ | |
public function add_header_comment($tpl_source, $smarty) | |
{ | |
return "<?php echo \"<!-- Created by Smarty! -->\n\"; ?>\n".$tpl_source; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Its an error - Method Illuminate\View\Factory::getSmarty does not exist.