终于明白了.
我想生成bash脚本.
在正确的位置创建模板,例如
myBundle/Resources/views/MyController/mytemplate.sh.twig
Run Code Online (Sandbox Code Playgroud)在ScriptGenerator类中
// Load the template
$template = $this->twig->loadTemplate('myBundle:MyController:mytemplate.sh.twig');
// Render the whole template
$script = $template->render($parameters);
Run Code Online (Sandbox Code Playgroud)如果要使用它,请放置此代码.
namespace myproject\myBundle\Controller;
use Symfony\Bundle\FrameworkBundle\Controller\Controller;
use myproject\myBundle\Generator\ScriptGenerator;
class myController extends Controller
{
public function myAction()
{
$twig = $this->get('twig');
$generator = new ScriptGenerator($twig);
$parameters = array(
'a parameter' => "whatever"
);
$script = $generator->setScript($parameters);
file_put_contents('whereyouwant',$script);
...
}
}
Run Code Online (Sandbox Code Playgroud) 归档时间: |
|
查看次数: |
8085 次 |
最近记录: |