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

Call function from view

Hi! I need in a view (plain php) to call custom function.

  1. Where should I declare custom function?
  2. How to call it from the view (plain php)?

open the php tag anywhere in your volt file and call custom function. But this is not the best of way you should call your function in your controller and then pass the value to volt.



11.2k

I'm not using volt. I just want to call my function from the views (.phtml). I can't give it straight to the view from controller as I'm looping through array of entities and in the loop getting related entity. So I know arguments only in the loop while fetching related entities.

offtop: I wish phalcon had more real-world examples. It's very hard to do smth beyond fetching cars or robots :(

edited Dec '15

Why you use plain php ? Volt is much better to be honest nad it still compiled to plain php without any classes(not like twig where you have tones of classes)



14.7k
Accepted
answer

@AucT

Get the whole array of your records from the controller and then loop that array in your .phtml file.