Generate Dummy Data in CodeIgniter with Faker Library

Faker is a popular PHP library which can be used in any PHP frameworks like CodeIgniter to generate dummy data for development or testing purpose. Faker can be used to bootstrap database and XML documents, fill-in your persistence to stress test it.

Faker allows dummy data generation for Lorem Ipsum Text, Person, Address, Phone Number, Company, Real Text, Date and Time, Internet, User Agent, Payment, Color, File, Image, Uuid, Barcode, Miscellaneous, Biased, and Html Lorem. It supports both PSR-0 as PSR-4 autoloaders.

Note: Faker’s repository has been archived by the owner. It won’t affect developers who want to use this library. The owner’s decision to archived the project is to avoid users abusing the database and add records which are critical to real-life business.

Steps to add Faker to CodeIgniter using PSR-0:

  • Download the library from
  • Copy it to application\third_party\, something like application\third_party\faker of your CodeIgniter project folder.
  • The library then can be added to any controllers that requires it with include APPPATH . 'third_party/faker/autoload.php';

Create an object of Faker class with $faker = Faker\Factory::create(); then use it to generate data with respective methods.

// use the factory to create a Faker\Generator instance
$faker = Faker\Factory::create();
//some examples
echo $faker->name;
echo $faker->address;
echo $faker->text;
echo $faker->numberBetween(10, 1000);
echo $faker->email;
echo $faker->hexcolor();

Leave a Comment

Your email address will not be published. Required fields are marked *

By continuing to use the site, you agree to the use of cookies. more information

The cookie settings on this website are set to "allow cookies" to give you the best browsing experience possible. If you continue to use this website without changing your cookie settings or you click "Accept" below then you are consenting to this.