Solved thread

This post is marked as solved. If you think the information contained on this thread must be part of the official documentation, please contribute submitting a pull request to its repository.

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 http://mysite the IndexController\IndexAction should load /views/index.volt and accessing http://mysite/issues the IssuesController\indexAction should load the /views/issues/index.volt and then http://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



30.7k
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



864

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



30.7k
edited Feb '15

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

A usefull doc regarding view component: http://docs.phalconphp.com/en/latest/reference/views.html



864

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.