Search code examples
codeignitercodeigniter-4

Codeigneiter return controller


How do I switch between controls in codeigneiter 4?

public function index()
    {
        $db = \Config\Database::connect();
        $query = $db->query('SELECT * FROM musste');
        $results = $query->getResultArray();
        $viewData = array("results" => $results);
        return view('index', $viewData);
    }

For example, what can I do to work this function again.I get an error when I use return view again.

public function login()
    {
      return view('index');
    }

is failing here


Solution

  • In login() function try to:

    return $this->index();

    instead of

    return view('index');