1
我正在编写一个Console Shell
,它将文件保存为webroot
文件夹内的html文件,以便浏览器可以通过URL(即/file.htm)访问该文件。cakephp 2.3从控制台获取ctp文件
我想能够将一个ctp文件加载到一个变量中,解析php inn过程,然后保存最终变量作为html文件的内容。有没有一种方法可以做到这一点?或者如果不是,我可以怎么做这个定制?
谢谢。
我正在编写一个Console Shell
,它将文件保存为webroot
文件夹内的html文件,以便浏览器可以通过URL(即/file.htm)访问该文件。cakephp 2.3从控制台获取ctp文件
我想能够将一个ctp文件加载到一个变量中,解析php inn过程,然后保存最终变量作为html文件的内容。有没有一种方法可以做到这一点?或者如果不是,我可以怎么做这个定制?
谢谢。
它可以手动使用View类的贝壳,这里的如何:
<?php
// Make the View class available.
App::uses('View', 'View');
class HtmlCreatorShell extends AppShell {
function create() {
// Initialize the View class.
$view = new View(null);
// Pass variables to the view like you would in a controller.
$view->set('article', array('Article' => ...));
// Render the view and store the HTML (string) output.
$html = $view->render('Articles/view');
// Output to the terminal for testing.
$this->out($html);
}
}
需要明确的是,Articles/view
相对于app/Views
目录并没有.ctp
扩展视图文件。
CakePHP API在View class上有更多信息。