Welcome Guest, Not a member yet? Register   Sign In
[SOLVED]DataMapper 1.8.2 get() gives an error
#1

[eluser]Cgull[/eluser]
Hello,

I have just staretd using Datamapper and trying to learn what to do with it.
I dowloaded the latest version and I am using CI 2.1.2

I followed all the installation steps.

I Need some help.

I have these 3 tables:
books:
id
name

provinces:
id
name

books_provinces:
id
book_id (foriegn_key - books)
province_id (foriegn_key - provinces)

I created a application/models/book.php file:
Code:
class Book extends DataMapper
{
var $has_one = array();
var $has_many = array("provinces");
  
public $validation = array(
    'name' => array(
        'label' => 'name',
        'rules' => array('required', 'trim', 'unique', 'max_length' => 100)
     )
  );
// Optionally, don't include a constructor if you don't need one.
  function __construct($id = NULL)
  {
   parent::__construct($id);
  }
}

And a application/controllers/admin/book.php file:
Code:
class Book extends CI_Controller
{
public function __construct ()
{
         parent::__construct();
}

public function index ()
{
  // Fetch all books
  $book = new Book();
  $this->data['books'] = $book->get();
  
  // Load view
  $this->data['subview'] = 'admin/books/index';
  $this->load->view('admin/_layout_main', $this->data);
}
}

Browsing: localhost/mysite/admin/book gives me this error:

SCREAM: Error suppression ignored for
( ! ) Fatal error: Call to undefined method Book::get() in C:\wamp\www\thinklocal\application\controllers\admin\book.php on line 14
Call Stack
# Time Memory Function Location
1 0.0008 276336 {main}( ) ..\index.php:0
2 0.0033 345752 require_once( 'C:\wamp\www\thinklocal\system\core\CodeIgniter.php' ) ..\index.php:218
3 0.0869 3663536 call_user_func_array ( ) ..\CodeIgniter.php:359
4 0.0869 3663616 Book->index( ) ..\CodeIgniter.php:359

Why do I get this error please?

Sorry, sorry, sorry, just saw there is a troubleshooting section in the user guide which solved my problem.

Call the controller books and not book.

*blush*




Theme © iAndrew 2016 - Forum software by © MyBB