/** * Create four routes for the given controller. * * index, edit, create, delete * * @param string $name * @param string $controller * @return void * @author Justin Palmer */ function resources($name, $controller) { $path = '/' . $name; $this->add($name, $path, $controller, 'index'); $this->add(Inflections::singularize($name), $path . '/{id}', $controller, 'view'); $this->add('edit-' . Inflections::singularize($name), $path . '/{id}/edit', $controller, 'edit'); $this->add('update-' . Inflections::singularize($name), $path . '/{id}/update', $controller, 'update'); $this->add('new-' . Inflections::singularize($name), $path . '/new', $controller, 'init'); $this->add('create-' . Inflections::singularize($name), $path . '/create', $controller, 'create'); $this->add('delete-' . Inflections::singularize($name), $path . '/{id}/delete', $controller, 'delete'); }
/** * Add the relationship * * @return Schema * @author Justin Palmer **/ private function addRelationship($name, $type) { $options = new stdClass(); $options->name = $name; $options->type = $type; $options->alias = Inflections::underscore(str_replace('-', '_', $name)); $options->table = Inflections::tableize($options->alias); $options->foreign_key = Inflections::foreignKey(Inflections::singularize($this->model->table_name())); $this->relationships->set($name, $options); $options->on = $this->autoGenerateOn($name); $this->relationships->set($name, $options); return $this; }
/** * @see Inflections::$singularize() **/ function singularize($string) { return Inflections::singularize($string); }
/** * Change a table name into a class name * * @return string * @author Justin Palmer **/ public static function classify($string) { $string = Inflections::singularize($string); $string = str_replace('_', ' ', $string); return str_replace(' ', '', ucwords($string)); }
/** * Constructor * * @param array $array * @return Model * @author Justin Palmer **/ public function __construct($array = array()) { $Adapter = Adapter::getDriverClass(); //Generate the table name if it is not set. if ($this->table_name === null) { $this->table_name = Inflections::tableize(get_class($this)); } // $this->schema = new Schema($this); $this->alias = Inflections::singularize($this->table_name); $this->errors = new Hash(); //Store the db adapter. self::$db = new $Adapter($this); //Set the default database name; $config = $this->db()->getConfig(); $this->database_name = $config->database; $this->props = new Hash(); //Hold the columns from the db to make sure properties, rules and relationships set actually exist. $this->columns = $this->prepareShowColumns($this->showColumns()); $this->setProperties($array); $this->init(); }