We have moved our forum to GitHub Discussions. For questions about Phalcon v3/v4/v5 you can visit here and for Phalcon v6 here.

Newbie question

Hi, I'm totally new to Phalcon and probably I am missing something in the docs, but I cannot understand how view work. I created 2 controllers:

IndexController with a IndexAction method

and

IssuesController with a IndexAction and ReadAction methods

I have problems loading views (which use the Volt templating engine). My views folder looks like this:

  • views
    • issues
        • index.volt
        • read.volt
    • index.volt

I was pretty sure that with this structure if I access https://mysite the IndexController\IndexAction should load /views/index.volt and accessing https://mysite/issues the IssuesController\indexAction should load the /views/issues/index.volt and then https://mysite/issues/read is "controlled by IssuesController\ViewAction and is supposed to render /views/issues/read.volt

What happens is that /views/index.volt is always rendered and I didn't find a way to make the correct template to be rendered. Any help?

Thank you in advance, SImone



43.9k
Accepted
answer

Hi,

views/index.volt is the main layout file and should contain something like:


<!DOCTYPE html>
<html>
    <head>
        <title>Phalcon PHP Framework</title>
    </head>
    <body>
        {{ content() }}
    </body>
</html>

you will have to create a views/index folder and have a views/index/index.volt file to be displayed whe calling indexController/indexAction



1.7k

Wow, thanks, so easy. You saved my day! Thanks! S.



43.9k
edited Feb '15

You're welcome. I hope you will enjoy phalcon framework.

A usefull doc regarding view component: https://docs.phalcon.io/en/latest/reference/views.html



1.7k

Thanks, I got it! Now I found another problem:

When in my controller I try to read data from a form

$issue = new \Multiple\Backend\Models\Issues();
$issue->name = $request->getPost("name", "alphanum");

I obtain this error:

A dependency injection object is required to access the 'filter' service

In my bootstrap file I think I have the filter as a dependency injection:

$di->set('filter', function() {
    return new \Phalcon\Filter();
});

So I can't understand what I didi wrong... The only way to read POSTed variables for me at the moment is to set the validation filters to null. Can anyone help?

Thanks again, S.