Welcome Guest, Not a member yet? Register   Sign In
Undefined variable: request;
#1

I recently migrated from CI 3 to 4 and I'm having a problem displaying $_POST values in my view. I have a filter in my view "listar.php" and when the form is sent the same view is loaded with new information based on the filter, but I cannot print the filter value when the page is loaded.
From what I noticed in CI 4 it is necessary to use
"echo $request->getGet('search');" to print the value sent by the form, but the problem happens because I'm not loading "Config\Services::request()", if I put " $request = \Config\Services::request(); " at the beginning of my view the error "Undefined variable: request" disappears, but it is very exhausting to always have to put this line in all views, I would like to know if anyone has a suggestion on how to always leave Request() loaded in all views by default, I would appreciate it.

Note: I haven't created the logic behind the filter yet, for now I just want to display what was sent in the filter itself
My controller: 


PHP Code:
namespace App\Controllers;
use 
App\Models\Modulo;

class 
Modulos extends My_Controller
{
    public function Getlistar()
    {
        $obj = new Modulo();
        $data['objetos'] = $obj->find();

        return view('estrutura/menu')
            view($this->controllerName.'/listar'$data)
            view('estrutura/rodape');
    }


Input I want to print the value: 
PHP Code:
<input type="text" name="busca" id="busca" value="<?php echo $request->getGet('busca'); ?>" class="form-control"
Reply


Messages In This Thread
Undefined variable: request; - by lucasdemarco - 04-11-2024, 07:25 AM
RE: Undefined variable: request; - by kenjis - 04-11-2024, 05:35 PM
RE: Undefined variable: request; - by kenjis - 04-12-2024, 05:34 PM
RE: Undefined variable: request; - by kenjis - 04-12-2024, 05:46 PM



Theme © iAndrew 2016 - Forum software by © MyBB