Search code examples
functionsymfonycontrollerprestashopsmarty

How can I call a specific function in my controller


I'm trying to create a module.

On my Dashboard I have a table with all my elements in my database, but, I don't know how I can set a function present in my controller in my smarty template.

Example of my function in my AdminController and who extends ModuleAdminController

public function deleteAction($id)
{
  //here my logic
}

In smarty how can I set my link to redirect to my function?

<a href="/* HERE WHAT CAN I SET ? */">Delete</a>

Solution

  • Try to set your method with public static scope and then call it from you tpl. Something like

    public static function deleteAction($id)
    {
        //do semething here
    }
    

    and then call it from tpl like

    <a href="{YourClassName::deleteAction('id_here')}">Delete</a>
    

    But be aware that it would work only from related tpl but not everywhere