Answers for "symfony call function in controller"

PHP
2

symfony call another controller

// OtherController::fancy($name, $color) will be executed
public function myAction($name)
{
    $response = $this->forward(
    	'App\Controller\OtherController::fancy',
    	array(
      		'name'  => $name,
        	'color' => 'green',
    	)
    );
    // ... further modify the response or return it directly
    return $response;
}
Posted by: Guest on March-24-2021
0

symfony call service in controller

$this->container->get('service_name');

// This work on for Symfony\Bundle\FrameworkBundle\Controller\Controller
// if you are using use Symfony\Bundle\FrameworkBundle\Controller\AbstractController , it would prefer to inject dependency
 public function method(User $user)
    {
        $user->callSomeMethod();
    }
Posted by: Guest on November-29-2021

Code answers related to "symfony call function in controller"

Browse Popular Code Answers by Language