Ejemplo n.º 1
0
 /**
  * undocumented function
  *
  * @param string $field 
  * @param string $errorMessage 
  * @return void
  */
 public function add($field, $errorMessage = null)
 {
     if ($errorMessage === null) {
         $errorMessage = Inflector::humanize($field) . ' is invalid';
     }
     $this->_errors[$field] = $errorMessage;
 }
Ejemplo n.º 2
0
 public function generate($name, $colDefs = array())
 {
     if (empty($colDefs)) {
         $tableName = Inflector::tableize($name);
         $datasource = ConnectionManager::getDataSource();
         $attributes = $datasource->generateAttributeMapFromTable($tableName);
     } else {
         $columns = Migration::parseColumnDefinitions($colDefs);
         $names = array_map(function ($col) {
             return $col['name'];
         }, $columns);
         $types = array_map(function ($col) {
             return $col['type'];
         }, $columns);
         $attributes = array_combine($names, $types);
     }
     $templates = array('add', 'edit', 'index', 'view');
     $vars = array('attributes' => $attributes, 'friendlyModelName' => Inflector::humanize(Inflector::classify($name)), 'modelVarName' => Inflector::lowerCamelize(Inflector::classify(Inflector::singularize($name))), 'pluralModelVarName' => Inflector::lowerCamelize(Inflector::pluralize($name)), 'controller' => Inflector::tableize($name));
     foreach ($templates as $template) {
         $data = $this->_renderTemplate("views/{$template}", $vars, true);
         $folder = Inflector::tableize($name);
         $this->_writeFile("/views/{$folder}/{$template}.html.tpl", $data);
     }
 }
Ejemplo n.º 3
0
 public function generate($name)
 {
     $vars = array('controller_name' => Inflector::tableize($name), 'controller_class' => Inflector::camelize(Inflector::tableize($name) . '_controller'), 'model_name' => Inflector::underscore(Inflector::singularize($name)), 'model_class' => Inflector::classify($name), 'model_var_name' => Inflector::lowerCamelize(Inflector::classify($name)), 'model_var_plural_name' => Inflector::lowerCamelize(Inflector::tableize($name)), 'friendly_model_name' => Inflector::humanize(Inflector::singularize($name)), 'friendly_controller_name' => Inflector::humanize(Inflector::tableize($name)), 'package_name' => 'App', 'year' => date('Y'));
     $data = $this->_renderTemplate('controller', $vars);
     $this->_writeFile('/controllers/' . $vars['controller_class'] . '.php', $data);
 }
Ejemplo n.º 4
0
	protected function _generateViews($name) {
		$tableName = Inflector::tableize($name);
		$datasource = ConnectionManager::getDataSource();
		$attributes = $datasource->generateAttributeMapFromTable($tableName);

		$templates = array('add', 'edit', 'index', 'view');

		$vars = array(
			'attributes' => $attributes,
			'friendlyModelName' => Inflector::humanize(Inflector::classify($name)),
			'modelVarName' => Inflector::lowerCamelize(Inflector::classify(Inflector::singularize($name))),
			'pluralModelVarName' => Inflector::lowerCamelize(Inflector::pluralize($name)),
			'controller' => Inflector::tableize($name)
		);

		foreach ($templates as $template) {	
			$data = $this->_renderTemplate("views/{$template}", $vars, true);	
			$folder = Inflector::tableize($name);
			$this->_writeFile("/views/{$folder}/{$template}.html.tpl", $data);
		}
	}
Ejemplo n.º 5
0
 public function generate($name)
 {
     $vars = array('class_name' => Inflector::classify($name), 'friendly_model_name' => Inflector::humanize(Inflector::classify($name)), 'package_name' => 'App', 'year' => date('Y'));
     $data = $this->_renderTemplate('model', $vars);
     $this->_writeFile('/models/' . Inflector::classify($name) . '.php', $data);
 }