H
H
hatman2018-09-11 08:26:23
symfony
hatman, 2018-09-11 08:26:23

Why is it written that you cannot call a function inside a controller?

Hello

public function isCorrectChat($resultData)
    {
        if(array_key_exists ('event_name', $resultData )){
            $eventName = $resultData['event_name'];
            if ($eventName === 'chat_finished'){
                return true;
            } else {
                return false;
            }
        } else {
            return false;
        }
    }

    /**
     * @Route("/decode", name="decode")
     */
    public function decode()
    {
        $loader = $this->getDoctrine()
            ->getRepository(PlainJson::class)
            ->find(1);

        $json = $loader->getJson();
        $resultData = json_decode($json, true);

        if(isCorrectChat($resultData)){  ----- вот тут
            $cargo = array();
        ....

I made an auxiliary function in the controller file, which I call from the controller function. I get the error
"undefined function isCorrectChat less... (Ctrl+F1)
Inspection info: Declaration of referenced function is not found in built-in library and project files."
Is it necessary to carry out this function as a service in symphony, or is it impossible to work with functions like this in php?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
D
Dmitry, 2018-09-11
@hatman

Good morning.
Perhaps it should be called through $this?
if($this->isCorrectChat($resultData)){

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question