Solved thread

This post is marked as solved. If you think the information contained on this thread must be part of the official documentation, please contribute submitting a pull request to its repository.

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.



3.9k

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)



4.7k
Accepted
answer

@AucT

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