Skip to content
stvvt edited this page Sep 9, 2011 · 1 revision

Fixtures are used to easily insert values into your database. The most common use for a fixture is to insert example record into your database

You fixtures the same way you run migrate:

  cake fixtures help

If you wanted to create a fixture for your users table, it would be in the file app/config/fixtures/users.php and it would look like this:

---
- 
  user: 
    id: 1
    name: My user!!
    description: foo bar
    created: 2008-11-13 21:03:40
    modified: 2008-11-13 21:03:40
- 
  contests: 
    id: 2
    name: Lorem
    description: Lorem ipsum dolor sit amet, consectetur
    created: 2008-11-13 21:21:39
    modified: 2008-11-13 21:21:39

If you have to reset your database or need to reinsert data for any reason, you can "dump" all your current data to fixtures like so:

  cake fixtures g fromdb -force

NOTE: The -force option overwrites any existing files in app/config/fixtures!

Then you can load them back into the database simply by calling:

  cake fixtures
Clone this wiki locally