This article mainly introduces ThinkPHP's method of using the template engine in Cli mode. The example analyzes ThinkPHP's technique of operating the template based on Cli mode, which has some reference value, for more information about how ThinkPHP uses the template engine in Cli mode, see the following example. Share it with you for your reference. The details are as follows:
The manual in section 2.1 describes the Cli mode and template engine as follows:
By default, no template engine is used in Cli mode (you can call it in the operation method );
But how to call it is not mentioned in the manual. As a result, you need to improve yourself.
Before introducing how to call the function, let's briefly talk about what situations may require the module engine:
1. Use dompdf to automatically generate PDF or HTML reports in scheduled tasks
2. send HTML-type emails to scheduled tasks
3. automatically generate static pages in the background
4. Other background operations on the template
<? Php // This document is automatically generated. It is only for testing and running class IndexAction extends Action {private $ view; public function index () {// import View import ('Think. template. tagLib '); import ('Think. template. thinktemplate'); import ('Think. core. view '); // this document is automatically generated and is only for testing and running C ('cache _ path', CACHE_PATH); $ this-> view = Think :: instance ('view'); $ this-> View-> assign ('rows ', array ('title' => 'test ',))); $ this-> view-> assign ('title', 'This is a title'); $ Content = $ this-> view-> fetch ('index/index.html '); var_dump ($ content) ;}}?>