0

I've a model called City in datamapper for codeigniter. I've kept the name of the table as "cities" because datamapper expects the name of the table in pluralized form. Now when I create the object for the model in controller ( $c = new City(); ); I get following error : Call to a member function where() on a non-object in C:\wamp\www\project\application\controllers\userhome.php on line 61 .

This is the model I've used

                    <?php

        class City extends DataMapper {

            //var $table = "cities";
            function __construct()
            {
                parent::__construct();
            }
        }

        ?>

As you can see in the model that i've tried to assign the table name to the variable which for now I've commented. I got the error with that also.

These are the codes I am using in my controller.

                    $c = new City(); 

                    $details3 = $c -> where('city_id', $ct) -> get();
        foreach($details3 as $d3)
        {
            $data['city_native_from_city_table'] = $d3 -> city_name; 
        }
        echo $data['city_native_from_city_table']; echo "<br>";

Please help me out. Thanks in advance...

hakre
  • 178,314
  • 47
  • 389
  • 754
Shashi Roy
  • 303
  • 3
  • 7
  • 21

1 Answers1

0

you can remove comment in code see below:

    <?php

        class City extends DataMapper {

            var $table = "cities";
            function __construct()
            {
                parent::__construct();
            }
        }

        ?>

and try again..!

Chintan
  • 1,004
  • 1
  • 7
  • 22