Last active
August 29, 2015 14:27
-
-
Save marcogrueter/abc40440a17f070d8028 to your computer and use it in GitHub Desktop.
seeding with faker in pyrocms
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php if (!defined('BASEPATH')) exit('No direct script access allowed'); | |
/* | |
* Use faker in pyrocms: | |
* 1. create composer.json in installation root | |
* content: | |
* { | |
* "require-dev": { | |
* "fzaninotto/Faker": "dev-master" | |
* } | |
* } | |
* 2. composer install | |
* 3. use the class below as a template for your own seeder in your module | |
* 4. be sure to protect or delete this controller in production mode | |
*/ | |
include_once "vendor/autoload.php"; | |
class Seeder extends Admin_Controller { | |
public function seed_customers() | |
{ | |
if( ! $this->ion_auth->is_admin() ) { | |
return; | |
} | |
$this->load->model('customers_m'); | |
$faker = Faker\Factory::create(); | |
for($i = 1; $i <= 10; $i++) | |
{ | |
$data = array( | |
'created' => date('Y-m-d H:i:s', time()), | |
'company' => $faker->company, | |
'address' => $faker->streetAddress, | |
'postal_code' => $faker->postcode, | |
'city' => $faker->city, | |
'contact' => $faker->title . ' ' . $faker->firstName . ' ' . $faker->lastName, | |
'email' => $faker->email, | |
'phone' => $faker->phoneNumber, | |
'login' => $faker->password | |
); | |
$this->customers_m->insert($data); | |
} | |
echo "seeding complete"; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
👍