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

View rendering changed in 1.3.0?

Upgraded Phalcon from 1.2.6 to 1.3.0 and my whole site stopped rendering the action view.

It appears this is because DefaultController->homeAction used to look for views/default/home.volt but now is looking for views/Default/home.volt

Is this a bug? An intentional change? Am I missing something?

It seems a change like this, if intentional, should be configurable via a config option...



51.3k
edited Apr '14

Hi, not sure I can answer your question, but you can use the code below to debug view script loading:

            $di->set('view', function() {
                $eventsManager = new Events;
                // Use to debug view rendering.
                $eventsManager->attach('view', function(Event $event, View $view) {
                    if ($event->getType() == 'notFoundView') {
                        if ($event->getSource()->getCurrentRenderLevel() == \Phalcon\Mvc\View::LEVEL_ACTION_VIEW) {
                            // Only log missing views when view's own script could not be found.
                            $this->getDi()->get(LOGD_ERROR)->error('View not found: ' . $view->getActiveRenderPath());
                        }
                    }
                });
                $view = new View();
                $view->setViewsDir(MODULE_ROOT . '/views/phtml/')
                    ->setMainView('master')
                    ->setPartialsDir('partials/')
                    ->setEventsManager($eventsManager);

                return $view;
            });

Cheers!

Thanks temuri - but I can see what the problem is - it's in my original post.

I can fix it by capitalizing all my directory names or by lowercasing my class names - but I shouldn't have to!



51.3k

Good :-)

Out of curiosity - how do you solve the problem of passing PHP context to Javascript or CSS? Something you might need if you wanted to generate JS dynamically or use application-wide constants.

That's a bit of a threadjack.

Depends on the situation, frankly. But rarely is such a thing required, there are normally other solutions that are cleaner.

Back to the OP - this may be a bug or something you're missing. I can use 1.2.6 & 1.3.0 interchangably and the case of the view directory name is irrelevant.

It's irrelevant? Are you on linux!?

I am using the Annotations router...

$router->addResource( 'Default' );

And this used to look in views/default and now it wants views/Default

I'm seriously considering moving this entire project to a different framework, as clearly moving from 1.2.6 to 1.3.0 is broken.

I've now also found a problem with adding an extension to the Volt Compiler where the tag property is somehow getting overwritten with the extension class =(

Yes I'm on Linux.

Broken or not, I'm sure it's easier to just rename your directory than to port your project to another framework.

If you have another problem, feel free to start. another thread.

I've managed to code around both problems now.

But it's rather hacky.



8.1k
Accepted
answer
edited May '14

This is not a bug. This is a feature :) Just Phalcon adopted PSR-0

https://github.com/php-fig/fig-standards/blob/master/accepted/PSR-0.md

https://docs.phalcon.io/en/latest/reference/loader.html

Due to PSR-0 we can autoload all project classes shortly like

$loader = new \Phalcon\Loader();

$loader->registerNamespaces([
    Myprojectnamespace' => \dirname(__DIR__),
]);

And all work exellent. Without any hack. This feature fully consistent with the concept of PHP.

This is a positive move, but a move that does break things (as evidenced by this thread) - and as such should have been communicated better.

Thank you for the answer... but I am with quasipickle.

I don't think minor version changes should break things like this.

why? no result!