Quantcast

Zend Framework, PhpRenderer unable to render template adds controllers into the template name

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
6 messages Options
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Zend Framework, PhpRenderer unable to render template adds controllers into the template name

DimaD
This post has NOT been accepted by the mailing list yet.
I migrated from ZF2 to ZF3. Now I have a problem. My view script is in the right place, the configuration seems ok, but I get the following error:

    Zend\View\Renderer\PhpRenderer::render: Unable to render template "parties/controllers/write-party/add"; resolver could not resolve to a file

which is a fairly common error to solve, but the problem is that for some reason, I get controllers folder in the template path. The template path should be parties/write-party/add.

module.config.php

return [
    'controllers' => [
        'factories' => [
            WritePartyController::class => WritePartyControllerFactory::class,
        ],
    ],
    'router' => [
        'routes' => [
            'parties' => [
                'type'    => Literal::class,
                'options' => [
                    'route'    => '/parties',
                    'defaults' => [
                        '__NAMESPACE__' => 'Parties\Controllers',
                        'controller'    => 'Index',
                        'action'        => 'index',
                    ],
                ],
                'may_terminate' => true,
                'child_routes' => [
                    'add' => [
                        'type' => Segment::class,
                        'options' => [
                            'route' => '/add',
                            'defaults' => [
                                'controller' => WritePartyController::class,
                                'action' => 'add',
                            ],
                        ],
                    ],
    //...
    'view_manager' => [
        'template_path_stack' => [
            'parties' => __DIR__ . '/../view',
        ],
        'strategies' => [
            'ViewJsonStrategy',
        ],
    ],
],

How to get the correct path to my view script which is parties/write-party/add?
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: Zend Framework, PhpRenderer unable to render template adds controllers into the template name

Marco Pivetta
This post has NOT been accepted by the mailing list yet.
Seems caused by the `'__NAMESPACE__' => 'Parties\Controllers'` config. Not sure why that happens, but I suggest looking into the InjectTemplateListener and see what it is doing ( https://github.com/zendframework/zend-mvc/blob/c6d6392d84508091bc774751c157a8f36d006955/src/View/Http/InjectTemplateListener.php )


On Mon, Nov 14, 2016 at 1:58 PM, DimaD [via Zend Framework Community] <[hidden email]> wrote:
I migrated from ZF2 to ZF3. Now I have a problem. My view script is in the right place, the configuration seems ok, but I get the following error:

    Zend\View\Renderer\PhpRenderer::render: Unable to render template "parties/controllers/write-party/add"; resolver could not resolve to a file

which is a fairly common error to solve, but the problem is that for some reason, I get controllers folder in the template path. The template path should be parties/write-party/add.

module.config.php

return [
    'controllers' => [
        'factories' => [
            WritePartyController::class => WritePartyControllerFactory::class,
        ],
    ],
    'router' => [
        'routes' => [
            'parties' => [
                'type'    => Literal::class,
                'options' => [
                    'route'    => '/parties',
                    'defaults' => [
                        '__NAMESPACE__' => 'Parties\Controllers',
                        'controller'    => 'Index',
                        'action'        => 'index',
                    ],
                ],
                'may_terminate' => true,
                'child_routes' => [
                    'add' => [
                        'type' => Segment::class,
                        'options' => [
                            'route' => '/add',
                            'defaults' => [
                                'controller' => WritePartyController::class,
                                'action' => 'add',
                            ],
                        ],
                    ],
    //...
    'view_manager' => [
        'template_path_stack' => [
            'parties' => __DIR__ . '/../view',
        ],
        'strategies' => [
            'ViewJsonStrategy',
        ],
    ],
],

How to get the correct path to my view script which is parties/write-party/add?


To start a new topic under Zend Framework, email [hidden email]
To unsubscribe from Zend Framework Community, click here.
NAML

Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: Zend Framework, PhpRenderer unable to render template adds controllers into the template name

DimaD
This post has NOT been accepted by the mailing list yet.
Thanks very much, Marco. but __NAMESPACE__ has nothing to do with this because if i change it to just 'Parties', or remove it entirely it doesn't correct the thing.
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: Zend Framework, PhpRenderer unable to render template adds controllers into the template name

DimaD
This post has NOT been accepted by the mailing list yet.
In reply to this post by Marco Pivetta
Marco, once again, thanks very much for your help. You were right. If I go to InjectTemplateListener, there's a method mapController. This is where the chemistry lies. The line

$parts = array_diff($parts, ['Controller']);

assumes that the folder with the module's controllers is named 'Controller' whereas mine is 'ContollerS' (capitalized 's' to emphasize). As I mentioned, everything worked fine on ZF2, so I believe it's a bug.

Should I report it somehow?
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: Zend Framework, PhpRenderer unable to render template adds controllers into the template name

Marco Pivetta
This post has NOT been accepted by the mailing list yet.
If you can write a test case, and that test case succeeds on 2.x and fails on 3.x, then yes, report it.


On Mon, Nov 14, 2016 at 3:20 PM, DimaD [via Zend Framework Community] <[hidden email]> wrote:
Marco, once again, thanks very much for your help. You were right. If I go to InjectTemplateListener, there's a method mapController. This is where the chemistry lies. The line

$parts = array_diff($parts, ['Controller']);

assumes that the folder with the module's controllers is named 'Controller' whereas mine is 'ContollerS' (capitalized 's' to emphasize). As I mentioned, everything worked fine on ZF2, so I believe it's a bug.

Should I report it somehow?


To start a new topic under Zend Framework, email [hidden email]
To unsubscribe from Zend Framework Community, click here.
NAML

Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: Zend Framework, PhpRenderer unable to render template adds controllers into the template name

DimaD
This post has NOT been accepted by the mailing list yet.
And Marco, really words cannot describe how grateful i am to your for saving my a** for the 4th time. Thank you VERY much for your desire to help newbies like me.
Loading...