簡體   English   中英

Phalcon設置視圖模板

[英]phalcon set view template

我在Phalcon中的模板有一些問題。 它沒有渲染。 這是執行操作方法的示例。 動作稱為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.
{{ } }}

{{ 代替

默認情況下,Phalcon選擇與您的控制器和操作組合匹配的視圖。 但是,您可以使用以下方法覆蓋它:

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

在您提供的示例中,您應該替換以下代碼行

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

有了這個

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

有關更多信息,請參考Phalcon文檔


另一方面,我注意到您完全錯過了Volt模板語言的要點。 您正在將PHP語法與Volt語法混合使用,請參考Yergo在注釋中為您提供的鏈接

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM