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 https://github.com/fzaninotto/Faker.
- Copy it toÂ
application\third_party\
, something likeapplication\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();