Welcome Guest, Not a member yet? Register   Sign In
Bug in this code or what is the problem?
#1

[eluser]Isuru[/eluser]
I am new to CodeIgniter and trying to figure out this for hours, but still no success.

Is there anything wrong in the following Model code.
Code:
function getMainFeature(){
$data = array();
$this->db->select(“id,name,shortdesc,image”);
$this->db->where(‘featured’,’true’);
$this->db->where(‘status’, ‘active’);
$this->db->orderby(“rand()”);
$this->db->limit(1);
$Q = $this->db->get(‘products’);
if ($Q->num_rows() > 0){
foreach ($Q->result_array() as $row){
$data = array(
“id” => $row[‘id’],
“name” => $row[‘name’],
“shortdesc” => $row[‘shortdesc’],
“image” => $row[‘image’]
);
}
}
$Q->free_result();
return $data;
}

Or is it in my controller?

Code:
function index(){
$data[‘title’] = “Welcome to Claudia’s Kids”;
$data[‘navlist’] = $this->MCats->getCategoriesNav();
$data[‘mainf’] = $this->MProducts->getMainFeature();
$skip = $data[‘mainf’][‘id’];
$data[‘sidef’] = $this->MProducts->getRandomProducts(3,$skip);
$data[‘main’] = ‘home’;
$this->load->vars($data);
$this->load->view(‘template’);
}


I am learning CodeIgniter... So please be king enough to help! Thanks!
#2

[eluser]InsiteFX[/eluser]
Did you rename all Controllers to CI_Controller and all Models to CI_Model ?

You also need to all of these in your model!
Code:
class Controller extends CI_Controller {}
class Model extends CI_Model {}
=========================================

old code     New code
======================
getwhere to  get_where
orwhere  to  or_where
orlike   to  or_like
groupby  to  group_by
orderby  to  order_by

Also in your application/config/autoload.php
You need to change validation to form_validation and also all your code to form_validation!

InsiteFX
#3

[eluser]Madoc[/eluser]
The characters look dodgy as well (if this is what is in your functions).
Code:
replace all ‘ by '
replace all “ by "
Is it a copy / paste from a website or something ?

Please explain what actually is your problem. any errors ?
#4

[eluser]Isuru[/eluser]
[quote author="InsiteFX" date="1303890872"]Did you rename all Controllers to CI_Controller and all Models to CI_Model ?

You also need to all of these in your model!
Code:
class Controller extends CI_Controller {}
class Model extends CI_Model {}
=========================================

old code     New code
======================
getwhere to  get_where
orwhere  to  or_where
orlike   to  or_like
groupby  to  group_by
orderby  to  order_by

Also in your application/config/autoload.php
You need to change validation to form_validation and also all your code to form_validation!

InsiteFX[/quote]


Thanks! It was a problem of old code. I used orderby, instead of order_by.




Theme © iAndrew 2016 - Forum software by © MyBB