php function calling return from another function

Asked

Viewed 1,165 times

0

Hi, I’m new to PHP OO and in the Doctrine. I would like to return the value of a function within another function. Is it possible? Both are within the same class.

Function that will receive the result:

public function salvar(Request $request, EM $em)
{
    $FinContaspagar = new FinContaspagar(
        $_SESSION["grupo"],
        $_SESSION["estabelecimento"],
        $request->get('terceiro'),
        /****************RESULTADO DA FUNÇÃO AQUI**********/,
        $request->get('dtemissao'),
        $request->get("dtvencimento")
    );

    $em->persist($FinContaspagar);
    $em->flush();

    return redirect('contas')->with('success_message', 'Cadastrado com sucesso');
}

Function that generates the value:

public function insereCodigo(em $em){

    $query = $em->createQuery('SELECT COALESCE(MAX(u.codigo+1),1) as Codigo
                                 FROM ModuloFinanceiro\Entities\FinContaspagar u 
                                WHERE u.grupo = :sessionGrupo
                                  AND u.estabelecimento = :sessionEstabelecimento');
    $query->setParameter('sessionGrupo',$_SESSION["grupo"])
        ->setParameter('sessionEstabelecimento',$_SESSION["estabelecimento"]);
    $codigo = $query->getResult();

    return $codigo[0]["Codigo"];
}

If it is not possible, or is not recommended to do so, how can I proceed?

1 answer

2


I think that for a better understanding it would be better to receive this value before the function call:

$retorno = $this->insereCodigo($em);

or so, but I don’t know if it works:

 $FinContaspagar = new FinContaspagar(
    $_SESSION["grupo"],
    $_SESSION["estabelecimento"],
    $request->get('terceiro'),
    $this->insereCodigo($em),
    $request->get('dtemissao'),
    $request->get("dtvencimento")
);
  • Thanks @Evandro! The first solution worked! I was doing exactly the same as the second way, really not right. Thanks!

Browser other questions tagged

You are not signed in. Login or sign up in order to post.