Hi,
How do I call a function from a component from a view? (ctp file)
Is that even a good practice to do that?
Thanks,
Tee
Hi,
How do I call a function from a component from a view? (ctp file)
Is that even a good practice to do that?
Thanks,
Tee
For most components you could use something like:
App::import('Component', 'YourComponent');
$theComponent = new YourComponent();
$theComponent->yourMethod();
However, components are meant to share functionality used by controllers, so usually you should avoid calling components from views.
i suggest wrapping the component methods in a helper, and then using the usual route to access the helper.
My opinion is it is not good practice to do that. Think of a view as something designers would work with. You want to keep your code in the models and controllers if at a possible. If it has to do with reusable view content, consider moving the controller to an element or a helper, as that is what they are intended for.
If you provide more details, we can be more specific to how to implement something if you already have a code base we can reference.