phalcon设置视图模板

时间:2016-06-09 07:44:07

标签: php view phalcon

我在phalcon中遇到了一些模板问题。它没有渲染。这是一个做行动方法的例子。动作叫做UploadSave。 在这个动作之后,我想渲染我的图像/上传temlate。

     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.
{{ } }}

{{代替

1 个答案:

答案 0 :(得分:4)

默认情况下,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