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

Accessing $this->view->partial variables on Phalcon 3.4.2 vs 3.2.4

I just noticed that in Phalcon 3.4.2 I can not access variables that are generated in the partial view. Which I can access in Phalcon 3.2.4. For example:

I have a view file called "a.php". In that file I call partial "b.php" which generates some variables which in return after partial was processed in a.php I want to access those variables.

----- a.php ----- <?php $this->view->partial("b.php");

echo $_my_variable; ?>

--- b.php ----- <?php $_my_variable = "Hello World!"; ?>

The weird thing is that works in version 3.2.4 where as once I upgraded Phalcon to 3.4.2 - it does not work anymore. I thouhgt "partial" was acting as "includes()".

Can anybody let me know if it is a bug or there is a way to set in Phalcon to be able to access set variables in the partials. Anybody had the same issue?



8.4k

i just did a quick test and worked as it should

phalcon: 3.4.5 php: 7.1.33 windows 10 64

did a undefined variable showup on php error log ?

Pardon me for saying so, but this seems like a poor design. I think just like MVC separates concerns (ie: The View shouldn't know how the Model works, etc.), an outer view shouldn't rely on an inner view.

If you're processing data in b.php, but need it in a.php, you should be doing the processing in a.php or in your controller.

edited Feb '20

I'm not sure but this was actually a bug i think in phalcon 3.2, it was fixed in 3.4. You should not have access to variables from partial a in partial b and vice-versa. Each partial has own local variables scope.



369

talal424,

So you can access variables in the partial from the view in 3.4.5?

i just did a quick test and worked as it should

phalcon: 3.4.5 php: 7.1.33 windows 10 64

did a undefined variable showup on php error log ?

I guess in phalcon 3.4.5 it got broken again???



369

According to talal424, it is working in 3.4.5.

I don't know whether it is a bug or not as it is working in 3.4.5. Granted, I can either upgrade the server to 3.4.5 or rewrite the code (which will take time). If Phalcon says that you can not access variables in the partial from the view - then it is no brainer - rewrite it is. I just want to confirm if it is officialy that you can not access it. I was looking in the Documentation - could not find anything.

I'm not sure but this was actually a bug i think in phalcon 3.2, it was fixed in 3.4. You should not have access to variables from partial a in partial b and vice-versa. Each partial has own local variables scope.



8.4k

yes i did

talal424,

So you can access variables in the partial from the view in 3.4.5?

i just did a quick test and worked as it should

phalcon: 3.4.5 php: 7.1.33 windows 10 64

did a undefined variable showup on php error log ?

i wouldn't jump and rewrite everything

just test it in 3.4.5 in a local enviroment and consider what @Dylan Anderson suggested which is setting it up in controllers