Skip to content

What fetch() does ​

Use fetch() to render a template without sending output—it returns an HTML string. That fits Ajax responses or when you need the markup as a value.

Example ​

php
class index {

    function docs() {
        $data = array(
          'status' => 1,
        );
        $list = m('essay')->where($data)->select();
        assign('docs_list', $list);
        $html = fetch('docs'); // home/view/index/docs.html
        ajax(0, $html);
    }
}

fetch() vs v() ​

  • fetch() — render and return HTML.
  • v() — render and output, then end the request (typical page response).

Argument forms ​

Assume the current request is /home/index/docs.

  1. fetch('') — default template for the action: /home/view/index/docs.html
  2. fetch('docsInfo') — docsInfo.html under the current controller view folder.
  3. fetch('index:docs') — explicit controller/view mapping (segment before :).
  4. fetch('admin@index:docs') — another module (@ before the module name).

PhpTide documentation