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 https://github.com/fzaninotto/Faker 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. 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.

Close