Exemplo n.º 1
0
 public function run($segments = [], $quiet = false)
 {
     $name = array_shift($segments);
     $options = CLI::getOptions();
     $this->options['table_name'] = array_shift($segments);
     if (empty($name)) {
         $name = CLI::prompt('Model name');
     }
     // Format to CI Standards
     if (substr($name, -6) !== '_model') {
         $name .= '_model';
     }
     $name = ucfirst($name);
     if ($quiet === false) {
         $this->collectOptions($name, $options);
     } else {
         $this->quietSetOptions($name, $options);
     }
     $data = ['model_name' => $name, 'today' => date('Y-m-d H:ia')];
     $data = array_merge($data, $this->options);
     $destination = $this->determineOutputPath('models') . $name . '.php';
     if (!$this->copyTemplate('model', $destination, $data, $this->overwrite)) {
         CLI::error('Error creating new files');
     }
     return TRUE;
 }
Exemplo n.º 2
0
 protected function collectOptions($name)
 {
     $options = CLI::getOptions();
     // Model?
     $this->options['model'] = empty($options['model']) ? CLI::prompt('Model Name? (empty is fine)') : $options['model'];
     // Format per CI
     if (!empty($this->options['model']) && substr($this->options['model'], -6) !== '_model') {
         $this->options['model'] .= '_model';
     }
     $this->options['model'] = !empty($this->options['model']) ? ucfirst($this->options['model']) : NULL;
     // If we're using a model, then force the use of a themed controller.
     if (!empty($this->options['model'])) {
         $options['themed'] = 'y';
     }
     // Themed Controller?
     $this->options['themed'] = empty($options['themed']) ? CLI::prompt('Is a Themed Controller?', ['y', 'n']) : $options['themed'];
     $this->options['themed'] = $this->options['themed'] == 'y' ? TRUE : FALSE;
     if ($this->options['themed']) {
         $this->options['base_class'] = 'ThemedController';
     }
 }
Exemplo n.º 3
0
 public function collectOptions($name, $quiet = false)
 {
     $options = CLI::getOptions();
     // Use existing db table?
     if (array_key_exists('fromdb', $options)) {
         $this->readTable($this->table);
     } else {
         $fields = !empty($options['fields']) ? $options['fields'] : null;
         if (empty($fields) && $quiet) {
             return;
         }
         $fields = empty($fields) ? CLI::prompt('Fields? (name:type)') : $options['fields'];
         $this->fields = $this->parseFields($fields);
     }
 }