Andrzej Moroz
Andrzej Moroz

Reputation: 548

phalcon set view template

I have some problems with templates in phalcon. It doesn't render as it have. Here is an example of do method of action. Action called UploadSave. And after this action I want to render my image/upload 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();

But result is white screen. image/upload.phtml is not empty:

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

{{ instead of

Upvotes: 2

Views: 3132

Answers (1)

Timothy
Timothy

Reputation: 2003

By default Phalcon selects the view that matches your controller and action combination. You can however overwrite this by using:

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

In your provided example you should replace the following line of code

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

with this

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

Refer to the Phalcon documentation for more information.


On another note, I notice that you are completely missing the point of the Volt templating language. You are mixing PHP syntax with the Volt syntax, refer to the link that Yergo provided you in the comments.

Upvotes: 5

Related Questions