Skip to main content

Faker CodeIgniter: Generate Dummy Data

Any developer knows that when it comes to coding, dummy data is essential. Not only does it help to test your code, but it can also be used to populate a database or create fake user profiles. If you’re working on a CodeIgniter project that requires dummy data, there are several ways to go about generating it. One option is to use the Faker library, which can be used to generate fake data such as names, addresses, phone numbers, and more.

The Faker library is a great option for generating dummy data in CodeIgniter projects. It includes a wide range of data types and can be used to generate realistic data that can be used in testing or prototyping scenarios.

Steps to add Faker to CodeIgniter using PSR-0:

  • Visit and download its ZIP folder.
  • Extract and copy the extracted folder to application\third_party\.
  • Add the autoload include APPPATH . 'third_party/faker/autoload.php'; with this line of code to a controller.
$faker = Faker\Factory::create();
for ($i = 0; $i < 100; $i++) {
  echo $faker->name." lives at ".$faker->address."<br/>";
echo $faker->numberBetween(10, 1000);
echo $faker->email;
echo $faker->username;
echo $faker->hexcolor();
echo $faker->phoneNumber;
echo $faker->unixTime();

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