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

Issue with Phalcon4 RC2 on MacPorts / undefined variable in views


I had a big problem, that suddenly all variables in views became "undefined variable" although they are set in controllers. I install Phalcon using macPorts so I do not know if this problem ir only in macPorts release or more global. After figuring this out and downgrading back to RC1 everything works as expected.

This is my first post here, hope it helps someone. macPorts downgrading: https://trac.macports.org/wiki/howto/InstallingOlderPort

Can you show parts of the code that gets error?


Every controller with something similar to

public function indexAction() {
  $this->view->foo = 'bar';

And using in view .phtml

<?php echo $foo; ?> 

Resulted in standart php warning "Undefined variable". Also Hierarchical Rendering was not working and variables were not defined in MainLayout also.

Try to set via $this->view->setVar('foo', 'bar')

Also, is view names are the same as controller actions?


I tried that and there was no difference.

As I mentioned, when I moved back to rc1 version everyting works fine, no php code changes needed. I guess this bug is in macports version only, becauce such a visible problem cloud not be out there in rc2 unspotted for so long. :) Mybe something specific for my configuration - I do not know.

Ah, I completly forgot about that issue... Current issue is related to registring view service. Change from set() to setShared()

Here is resolved issue - https://github.com/phalcon/cphalcon/issues/14491

Currently it will work only by building from source, in case if you want latest version.