Return results to the view MVC

Having this function in model. How Can i return the results to the view?
Thanks

Function

function increment(){
		$counter = 0;
		$counter = $counter + 1;
		return $counter;
}

Controller

$counter = $this->Starmodel->increment();

$person = $this->load->view('starview', array('iscorrect' => $res,
        	            'question' => $person['question'],
			    'name' => $guess,
			    'results' => $counter));

View

<?php echo $results ?>

Your function increment is always going to return the value 1, since you start by setting it to zero and then add one to it.

At the moment yes. It should look more like this:

function increment($counter){
		$counter = $counter + 1;
		return $counter;
}

Counter would come from the controller:

$c = $this->input->get('score',false);
$result= $this->Starmodel->increment($c);

My problem is in the view. I need to store the score somewhere so the controller could get it and call the function to add 1 if correct, and then update back.
Don’t know what to write in the view, and how to pass the results back to the view after calling the function.

I have to be honest, I don’t have a very good understanding how to pass data from the controller to the view and from the view to the controller. Naming of fields get’s me confused.

What framework are yo using @Andrei_Birsan

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