Question

This site is built using CakePHP 1.2*

I have an element that needs to be placed in multiple views under multiple controllers. This element is very dynamic, every time a page is loaded it needs to call a function (which is rather large) and then display what was returned.

There are a few options that I have thought of, none of which I am sure are the correct way of doing this.

  • Placing this function within app_controller and then somehow calling it from the element
  • create a helper and then including it in every controller that will display the element.
  • creating a component and then including it in every controller that will display the element.

Any help is appreciated in the correct way of doing this. Currently the element is being placed on multiple pages under multiple controllers and is calling the function using $this->requestAction() which from what I understand is certainly not the correct way.

Thanks in advance!

Was it helpful?

Solution

Well, it's a tricky question, maybe you should give a little more of information. But I'll try:

  • If your function is part of your app's logic, you should make it a component.
  • If this function is part of the view, you should make it a helper.
  • If this function must be executed in your view, you could also try $this->render();

It's a tricky question, I hope this could help you, but you should give a little extra info.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top