Welcome Guest, Not a member yet? Register   Sign In
Simple code not working
#1

[eluser]Kikloo[/eluser]
Hi,

I have this code:

Code:
<?php
class MCats extends Model
{
        function MCats()
        {
                parent::Model();
        }

        function getCategory($id)
        {
                $data = array();
                $options = array("id" => $id);
                $Q = $this->db->getwhere("categories", $options, 1);
                if ($Q->num_rows() > 0)
                {
                        $data = $Q->row_array();
                }
                $Q->free_result();
                return $data;
        }

        function getAllCategories()
        {
                $data = array();
                $Q = $this->db->get("categories");
                if ($Q->num_rows() > 0)
                {
                        foreach ($Q->result_array() as $row)
                        {
                                $data[] = $row;
                        }
                }
                $Q->free_result();
                return $data;
        }
}
?>

Which is giving the following error:

Code:
A PHP Error was encountered

Severity: Notice

Message: Undefined property: MCats::$db

Filename: models/mcats.php

Line Number: 25

Fatal error: Call to a member function get() on a non-object in C:\xampp\htdocs\claudia\system\application\models\mcats.php on line 25

Help ?!

Thanks.
#2

[eluser]Kikloo[/eluser]
Hi,

Okay my bad i did'nt load the database library.

Thanks.
#3

[eluser]NateL[/eluser]
Wrox - Professional CodeIgniter?

arrrggg I got sooooo many errors reading over that book. Your best bet is to check the errata and see if the solution is in there some where.

I cracked open the book, found that code on page 66 and your code is (as far as i can tell) identical.

Despite some of the errors, i've found some useful info in that book - but I've never been able to complete it because of the errors. :-S
#4

[eluser]Kikloo[/eluser]
Hi,

Yes i am using that book. I am copy pasting code from pdf to php files, upon pasting it add's weird chars. and spaces which makes the code buggy, so far its working absolutely fine.

I did'nt auto load libraries and helpers thats why I was getting that error and I am already on page 96, and now am creating header, navigation and footer templates, seems to be working fine.

I am using very old version of Acrobat reader ie 5 i think i need to upgrade. I will post more as I progress. If all goes well as it says in the book I will start loving CI :-)

Thanks.
#5

[eluser]Kikloo[/eluser]
Hi,

Okay the book is buggy, any solutions ? I am stuck on updateCart function...it won't just work and gives a lot of errors. I have even re-checked the code several times and it just won't work. So i guess there's some major issue with the book.

Anyways is there some other way by which I can learn how to build a shopping cart using CI ?

Thanks.
#6

[eluser]Michael Wales[/eluser]
Quote:Anyways is there some other way by which I can learn how to build a shopping cart using CI ?

Read the User Guide and plan out your logic yourself. You mentioned previously that you were just copy-pasting code from the PDF, which really means you're not learning anything - your just glueing code examples together and hoping they work...
#7

[eluser]Kikloo[/eluser]
Hi,

By copy / pasting means that I am reading the book throughly and just not typing the code anyways. Its just few lines per chapter and I am understanding it all.

I thought by reading the whole book and by creating the sample app. I would know what I need to do and how will it be done, but as I am getting errors in the code which is in book so I am stuck again.

Also I am new to CI so i don't understand it quite well from the Documentation provided, for eg. I did'nt knew that sessions in CI are stored in cookies. This has been taught by the book. So I am learning but i just got stuck on 5th chapter which sessions were being just started etc.

There's alot more which I need to learn before I can start making on my own. The blog tutorial is good but its very limited. Need something big like symfony has provided real life practical examples.

I don't know how to make logins etc. using CI so much detail which is required in order to make a simple app. now a days.

Thanks.
#8

[eluser]Kikloo[/eluser]
Hi,

Weird! I deleted the files which were giving error and then retyped the same and now its working fine!

Thanks.




Theme © iAndrew 2016 - Forum software by © MyBB