[Solved] Codeigniter, error passing variable to template


public function index($dados=""){ $dados is not an array, it is a string, you cannot add values to it as if it were an array like $dados['titulo'] where [] denotes an array (hence the illegal string offset).

In your view you have <?= $body ?> which is never passed to your view in the index() function, hence your notice (it is also never echoed, fyi).

I’m not sure what $dados="" is supposed to be used for, but assuming its just a variable you want to pass to your controller you can do the following:

public function index($dados = "") {

    $data['body'] = 'Some body text';
    $data['somevarname'] = $dados;
    $data['titulo'] = 'Autenticação';
    //or
    /*
    $data = array(
        'body' => 'Some body text',
        'somevarname' => $dados,
        'titulo' => 'Autenticação'
    );
     * 
     */
    $this->template->load('login_template', 'area_restrita/acesso_login.php', $data);
}

0

solved Codeigniter, error passing variable to template