EllisLab text mark
Advanced Search
     
CI Error message in the Model
Posted: 26 October 2012 05:35 PM   [ Ignore ]
Joined: 2012-04-10
33 posts

Hello,

i have a problem. i do through a tutorial of the book “professional codeigniter” and i get this errors:

A PHP Error was encountered

Severity: Notice

Message: Undefined property: Welcome::$db

Filename: core/Model.php

Line Number: 51

Fatal error: Call to a member function get() on a non-object in E:\xampp\htdocs\CI_2.1.3\application\models\mcats.php on line 39


Thats my Code:

application/models/mcats.php:


 function 
getAllCategories() {
  $data 
= array();
  
$Q $this->db->get('categories');    //line 39
  
  
if($Q->num_rows() > 0{
   
foreach($Q->result_array() as $row{
    $data[] 
$row;
   
}
  }
  
  $Q
->free_result();
  return 
$data
Model.php:


 function 
__get($key)
 
{
  $CI 
=& get_instance();
  return 
$CI->$key;       //Thats Line 51
 

I use the CodeIgniter Version 2.1.3.. Help please smile

 
Posted: 26 October 2012 11:05 PM   [ Ignore ]   [ # 1 ]   [ Rating: 0 ]
Avatar
Joined: 2009-02-19
3819 posts

Is the database loaded?

 Signature 
 
Posted: 27 October 2012 09:49 AM   [ Ignore ]   [ # 2 ]   [ Rating: 0 ]
Joined: 2012-04-10
33 posts

thanks i must declared the database in the autoload.php..

but now i have a different problem.

Here is the Warning:

Fatal error: Call to undefined method CI_DB_mysql_driver::orderby() in E:\xampp\htdocs\CI_2.1.3\application\models\mcats.php on line 41

function getCategoriesNav() {
  $data 
= array();
  
$this->db->where('parentid <'1);
  
$this->db->where('status''active');
  
$this->db->orderby('name''asc'); //line 41
  
  
$Q $this->db->get('categories');
  
  if(
$Q->num_rows() > 0{
   
foreach($Q->result_array() as $row{
    $data[$row[
'id']] $row['name'];
   
}
  }
  
  $Q
->free_result();
  return 
$data;
 

can you say me, what’s the new declaration of the sql command “ORDER BY” by CodeIgniter 2.1.3?

 
Posted: 27 October 2012 02:58 PM   [ Ignore ]   [ # 3 ]   [ Rating: 0 ]
Avatar
Joined: 2009-02-19
3819 posts

Sure, but it’s in the user guide so you should probably read that.
Active Record

 Signature