Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Symfony 2 Call a function in a Controller Method

Tags:

symfony

I have a method in a controller say like this. In fact, I'm in need to declare a function checkLogin so that I can use in several Controller method like below:

class DefaultController extends Controller
{
 /**
     * @Route("/test")
     * @Template()
     */
    public function testAction()
    {

        if (checkLogin()){}
            else {}
        exit;
    }

    public static function checkLogin()
    {
        return 1;
    }
}

In the above case, when I'm doing it like this, I'm getting the following error:

Fatal error: Call to undefined function NouPei\WebSiteBundle\Controller\checkLogin() in /home/noor/noupei/website/WebSiteBundle/Controller/DefaultController.php on line 142

like image 574
Noor Avatar asked Jan 24 '12 11:01

Noor


1 Answers

It's a method, not a function:

if (self::checkLogin()){}
like image 179
meze Avatar answered Sep 28 '22 19:09

meze