Code Igniter simple MVC help

Hi

I have this simple code that where I am trying to display the name ana from the model in the view. Here is the simple code for the controller, model and the view.I get the error code: Message: Undefined variable: celebrity Filename: views/Stardisplay.php

Thanks

<?php
class Starcontroller extends CI_Controller {
function __construct()
{
	parent::__construct();
}

function guess()
{
	$this->load->model('Starmodel');
	$newstarr = $this->Starmodel->lookup();
	$this->load->view('Stardisplay',$celebrity);
}

}	
?>


<?php
class Starmodel extends CI_Model{
function __construct()
{
	parent::__construct();
}
public function lookup(){

$celebrity = "Anna";
return $celebrity;
}
}
?>


<html>
<head></head>
<body>
    <?php
	echo $celebrity;
    ?>
 </body>	
 </html>

Change

$this->load->view('Stardisplay',$celebrity);

To

$this->load->view('Stardisplay',$newstarr);

I have made the changes, but still it won’t display the name “Anna”.
I thought that in the code I need to pass to the view Stardisplay the value of the variable $celebrity

Maybe I am not doing something right:
In the codeigniter controllers folder I have a controller welcome.php with the function:

public function index()
{
	$this->load->view('Stardisplay.php');
}

Also in config-> router.php there is this code:

$route['default_controller'] = "welcome";
$route['404_override'] = '';

Try this:

function guess()
{
$data=array();

$this->load->model('Starmodel');

$data['celebrity'] = $this->Starmodel->lookup();

$this->load->view('Stardisplay', $data);

}

Thank you. Yes this worked for me.

1 Like

This topic was automatically closed 91 days after the last reply. New replies are no longer allowed.