How do I call the controller method inside the view?

Asked

Viewed 322 times

0

have that method :

public function Menu()
{

    $tabelas = $this->menu->All();

    $menus ="<ul><li>";

    foreach ($tabelas as $tabela )
    {
        if ($tabela->active == !false)
        { 
          //  $return = $this->categoria->All();

            foreach ($tabela as $key => $value )
            {

                if($key->active == !false)
                {
                    $menus .="<li>{$key} <a href= ></a></li> ";
                }
            }   
        }

        $menus.= "</li></ul>";
    }
    return $menus ;
}

wanted to know how to call him in the view , to see how he’s returning and putting things together ...

public function create()
{
    $this->setPageTitle('Menu');
    echo  $this->categoria->Menu(); die;
    $this->renderView('rotas/RouteMenus', 'layoutForm');
}

ta giving error :Uncaught Error: Call to a Member Function Menu() on null

  • 1

    you shouldn’t do that. What’s the problem that happens?

  • I want to set up my menu dynamically giving a select in the table of the bank , I already tested my select which is that call for the method all() there is bringing good , and now I just wanted to give a call in this menu method in the view to see how it is mounting the <ul> and tals

  • Save the return of Menu() in a variable give an echo for testing or pass it straight to view, then give an echo.

  • I played an echo inside the method that renders to view more error :Uncaught Error: Call to a Member Function Menu() on null

  • By the code of to suppose some things. By calling $this->categoria->Menu(), in that order it would be necessary that the property categoria returns an instance of the class where the function was created Menu(). By the description of the error presented to realize that $this->categoria returns the value null. It would be interesting to indicate in which classes are the functions shown.

No answers

Browser other questions tagged

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