Phalcon 集视图模板

phalcon set view template

我在使用 phalcon 模板时遇到了一些问题。它不会像以前那样呈现。下面是一个 do 方法的例子。名为 UploadSave 的操作。 在此操作之后,我想渲染我的 image/upload 模板。

     try {
        $hash = $this->request->getPost('hash');
        $File = $this->_getUploadedFile();
        $Validator = new ImageQualityValidator();
        if($Validator->isValid($File)){
            $Image = $this->_saveImage($File);
            $EnvCfg = self::_getEnvCfgDir();
            $cfg_data = $EnvCfg->getObject(self::MYPAINT);
            $this->response->redirect($cfg_data->host.'image/crop?hash='.$hash);
        }else {
            $this->getViewData()->hash = $hash;
            $this->getViewData()->validation_error = 'Image is invalid!!';
        }
    } catch (AMyPaintExceptions $Exc) {
        $this->getViewData()->validation_error = $Exc->getMessage();
    }
    $this->view->setMainView('image/upload');
    return $this->getViewData();

但是结果是白屏。 image/upload.phtml 不为空:

{{
   if( false == $this->is_already_image_uploaded) {

       echo $Tag->form(
       [
        "image/uploadSave",
        "method" => "post",
        "enctype" => "multipart/form-data"
       ]
    ); 
}}

<p>  {{ echo $Tag->fileField('my_photo');   }}</p>
<p> {{ echo $Tag->hiddenField(["hash", "value" => $this->hash]); }}</p>
<p> {{ echo $Tag->submitButton('Submit'); }} </p>
   {{ if($this->validation_error){ }}
        <p>{{ print_r($this->error_information);}}</p>
    {{ } }}
{{ echo $Tag->endForm(); }}

{{
}
else { }}

    Image has been uploaded already.
{{ } }}

{{ 而不是

默认情况下,Phalcon 选择与您的控制器和操作组合相匹配的视图。但是,您可以使用以下方式覆盖它:

$this->view->pick('other-controller/other-action');

在您提供的示例中,您应该替换以下代码行

$this->view->setMainView('image/upload');

有了这个

$this->view->pick('image/upload');

有关详细信息,请参阅 Phalcon documentation


另一方面,我注意到您完全忽略了 Volt 模板语言的要点。您将 PHP 语法与 Volt 语法混合,请参阅 Yergo 在评论中为您提供的 the link