Welcome Guest, Not a member yet? Register   Sign In
CI Error message in the Model
#1

[eluser]yuro[/eluser]
Hello,

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


Quote:A PHP Error was encountered

Severity: Notice

Message: Undefined property: Welcome::$db

Filename: core/Model.php

Line Number: 51


Quote: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:
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;

Code:
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
#2

[eluser]CroNiX[/eluser]
Is the database loaded?
#3

[eluser]yuro[/eluser]
thanks i must declared the database in the autoload.php..

but now i have a different problem.

Here is the Warning:

Quote: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

Code:
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?
#4

[eluser]CroNiX[/eluser]
Sure, but it's in the user guide so you should probably read that.
Active Record




Theme © iAndrew 2016 - Forum software by © MyBB