Welcome Guest, Not a member yet? Register   Sign In
Following the Tutorial and something is going wrong - aaaargh!!!!
#1

[eluser]Unknown[/eluser]
Hi,

I'm new to codeigniter and am following the video tutorial's, whilst trying to connect to my own mysql db and view my own tables.

I have created this class

class Dmp extends Controller {

function index()
{
$data['title'] = "Orders";
$data['heading'] = "Order Details";
$data['query'] = $this->db->get('orders_BDS');

$this->load->view('dmp_view', $data);
}
}

order_BDS is the name of a table on my db, but when viewing the index.php page online i get the following error;

Fatal error: Call to a member function on a non-object in *****/system/application/controllers/dmp.php on line 9

Line 9 relates to the db get function, if i comment it out the pages loads.

What have i done wrong.
Thanks in advance.
Mike
#2

[eluser]jedd[/eluser]
Hi miken16 and welcome to the CI forums.

[quote author="miken16" date="1259034893"]
What have i done wrong.
[/quote]

You appear to have forgotten your constructor.

Specifically if you are using PHP5, you need this function in your controller:
Code:
function  __construct ()  {
    parent::Controller();
    }

If you are using PHP4 your constructor name should be the same as your class name (in this case, Dmp).

Read the Class Constructors section of [url="/user_guide/general/controllers.html"]the Controllers[/url] page in the user guide.

EDIT: Oh, heck, sorry - may have gone off at an angle there - are you loading the database class? You can do this either with a $this->load->database(); as per the user guide, or put it in the library array in your config/autoload.php file (the latter is generally easier - as once you start using a database, you tend to use it on pretty much every page load.




Theme © iAndrew 2016 - Forum software by © MyBB