I'm working with CodeIgniter3 in the MVC model and I'm having problems for a long time, slowly I'm solving some problems here and there and almost reaching the point.
I'm doing a query in random order in the DB by the model:
public function get_rand(){
$frase = $this->db->query("SELECT frase FROM frases ORDER BY RAND() LIMIT 1");
if($frase->num_rows() > 0):
return $frase->result();
else:
return NULL;
endif;
}
and pulling inside the Controller:
public function index(){
if($frase = $this->randfrase->get_rand(1)):
foreach ($frase as $linha) :
echo $linha->frase;
endforeach;
else:
return NULL;
endif;
}
I mounted it so I could see by URL whether the Random selection was working. The part of the Model is 100%, now I wanted to know how I can instead of printa, send the info to a view aside of my system. Someone could help. In case this information should appear in an aside that is standard for the whole site. I tried to put this controller code right in the view but it always gives the error:
A PHP Error was encountered
Severity: Notice
Message: Undefined property: CI_Loader :: $ randfrase
Filename: views / aside.php
Line Number: 3
Backtrace:
File: C: \ xampp \ htdocs \ codeigniter \ site \ application \ views \ aside.php Line: 3 Function: _error_handler
File: C: \ xampp \ htdocs \ codeigniter \ site \ application \ views \ home.php Line: 27 Function: view
File: C: \ xampp \ htdocs \ codeigniter \ site \ application \ controllers \ page.php Line: 14 Function: view
File: C: \ xampp \ htdocs \ codeigniter \ site \ index.php Line: 315 Function: require_once
Fatal error: Call to a member function get_rand () on a non-object in C: \ xampp \ htdocs \ codeigniter \ site \ application \ views \ aside.php on line 3 A PHP Error was encountered
Severity: Error
Message: Call to a member function get_rand () on a non-object
Filename: views / aside.php
Line Number: 3
Backtrace: