2016-06-09 59 views
0

我在phalcon模板有一些問題。它沒有像現在這樣渲染。這是一個行動方法的例子。稱爲UploadSave的操作。 並且在此操作之後,我想呈現圖像/上傳文件。phalcon設置視圖模板

 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(); 

但結果是白色屏幕。 圖像/ 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

請閱讀[文檔](https://docs.phalconphp.com/pl/latest/reference/volt.html)瞭解如何使用Volt模板語言。你的模板只是沿着模板編寫php,這就是我不會調試的。此外,您的帖子已損壞。 – yergo

回答

2

默認情況下選擇多爾康您的控制器和動作的組合相匹配的圖。但是,您可以通過使用覆蓋此:

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

在您提供的例子中,你應該與此

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

替換代碼

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

以下行參考Phalcon documentation瞭解更多信息。


在另一個說明中,我注意到你完全忽略了伏模板語言的要點。您將PHP語法與Volt語法混合使用,請參閱Yergo在評論中提供的the link