Arturo Hernández Arturo Hernández - 1 month ago 10
PHP Question

codeigniter- Call to undefined function getNombre()

can someone help me with this?. It gives me following Fatal Error:


Fatal error: Call to undefined function getNombre() in C:\xampp\htdocs\CodeIgniter\application\views\vista.php on line 6


this is my controller(
c1.php
)

<?php

class c1 extends CI_Controller{

function _construct() {
parent::__construct();
$this->load->helper('mihelper');
}

function index(){
$this->load->view('headers');
$this->load->view('vista');
}

}

?>


this is in my helper(
mihelper_helper.php
)

<?php

function getNombre(){
return "<h1>Arturo</h1>";
}
?>


this is my view(
vista.php
)

<body>

<h1>Llamado desde controlador</h1>

<?php getNombre() ?>

</body>
</html>

Answer

You missed a underscore in the controller's construct function. So the helper is not able to load and the function is undefined. Updated code as below,

<?php

class c1 extends CI_Controller{

    function __construct() {
        parent::__construct();
        $this->load->helper('mihelper');
    }

    function index(){
        $this->load->view('headers');
        $this->load->view('vista');
    }

}

?>