【问题标题】:phalcon set view templatephalcon 集视图模板
【发布时间】:2016-06-09 07:44:06
【问题描述】:

我在 phalcon 中的模板有一些问题。它不会像以前那样渲染。这是一个 do 操作方法的示例。名为 UploadSave 的操作。 在此操作之后,我想渲染我的图像/上传模板。

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

{{ 而不是

【问题讨论】:

  • 请阅读documentation,了解如何使用 Volt 模板语言。您的模板只不过是沿着模板编写 php,这就是我不会调试的。您的帖子也已损坏。

标签: php view phalcon


【解决方案1】:

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

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

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

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

有了这个

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

有关更多信息,请参阅Phalcon documentation


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

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2016-01-29
    • 2015-12-13
    • 2017-01-14
    • 1970-01-01
    • 1970-01-01
    • 2023-04-01
    • 2014-05-14
    • 2019-01-21
    相关资源
    最近更新 更多