本文整理汇总了PHP中inflector::singular方法的典型用法代码示例。如果您正苦于以下问题:PHP inflector::singular方法的具体用法?PHP inflector::singular怎么用?PHP inflector::singular使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类inflector
的用法示例。
在下文中一共展示了inflector::singular方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: index
public function index()
{
$dotfile = "digraph G {\n";
foreach ($this->_get_models() as $model) {
$dotfile .= $model->object_name . ' [shape="Mrecord", label=< <FONT POINT-SIZE="18.0">' . $model->object_name . '</FONT><BR ALIGN="CENTER"/>';
foreach ($model->table_columns as $column => $meta) {
if (substr($column, -3) == '_id' or $column == 'id') {
continue;
}
$dotfile .= '<FONT COLOR="darkgreen">' . $column . '</FONT> <FONT COLOR="grey">(' . $meta['type'] . ')' . '</FONT><BR ALIGN="LEFT"/>';
}
$dotfile .= '>];' . "\n";
foreach ($model->has_one as $related) {
$dotfile .= $model->object_name . ' -> ' . $related . ";\n";
//" [arrowhead=\"tee\"];\n";
}
foreach ($model->has_many as $related) {
$dotfile .= $model->object_name . ' -> ' . inflector::singular($related) . ";\n";
//" [arrowhead=\"crow\"];\n";
}
}
$dotfile .= '}';
return $this->_render($dotfile);
foreach ($this->_get_models() as $model) {
echo $model->object_name . '<br />';
foreach ($model->table_columns as $column => $meta) {
echo ' : ' . $column . '<br />';
}
echo '<br />';
}
}
示例2: initialize
/**
* Sets up foreign and through properly.
*
* @param string $model
* @param string $column
* @return void
*/
public function initialize($model, $column)
{
// Default to the name of the column
if (empty($this->foreign)) {
$foreign_model = inflector::singular($column);
$this->foreign = $foreign_model . '.' . $foreign_model . ':primary_key';
} elseif (is_string($this->foreign) and FALSE === strpos($this->foreign, '.')) {
$this->foreign = $this->foreign . '.' . $this->foreign . ':primary_key';
}
// Create an array from them for easier access
if (!is_array($this->foreign)) {
$this->foreign = array_combine(array('model', 'field'), explode('.', $this->foreign));
}
// Create the default through connection
if (empty($this->through) or is_string($this->through)) {
if (empty($this->through)) {
// Find the join table based on the two model names pluralized,
// sorted alphabetically and with an underscore separating them
$through = array(inflector::plural($this->foreign['model']), inflector::plural($model));
sort($through);
$this->through = implode('_', $through);
}
$this->through = array('model' => $this->through, 'fields' => array(inflector::singular($model) . ':foreign_key', inflector::singular($this->foreign['model']) . ':foreign_key'));
}
parent::initialize($model, $column);
}
示例3: __get
/**
* Overload ORM::__get to support "parent" and "children" properties.
*
* @param string column name
* @return mixed
*/
public function __get($column)
{
if ($column === 'parent') {
if (empty($this->related[$column])) {
// Load child model
$model = ORM::factory(inflector::singular($this->children));
if (array_key_exists($this->parent_key, $this->object)) {
// Find children of this parent
$model->where($model->primary_key, $this->object[$this->parent_key])->find();
}
$this->related[$column] = $model;
}
return $this->related[$column];
} elseif ($column === 'children') {
if (empty($this->related[$column])) {
$model = ORM::factory(inflector::singular($this->children));
if ($this->children === $this->table_name) {
// Load children within this table
$this->related[$column] = $model->where($this->parent_key, $this->object[$this->primary_key])->find_all();
} else {
// Find first selection of children
$this->related[$column] = $model->where($this->foreign_key(), $this->object[$this->primary_key])->where($this->parent_key, NULL)->find_all();
}
}
return $this->related[$column];
}
return parent::__get($column);
}
示例4: initialize
/**
* Overrides the initialize to automatically provide the column name
*
* @param string $model
* @param string $column
* @return void
*/
public function initialize($model, $column)
{
// Default to the name of the column
if (empty($this->foreign)) {
$foreign_model = inflector::singular($column);
$this->foreign = $foreign_model . '.' . $foreign_model . ':primary_key';
} elseif (FALSE === strpos($this->foreign, '.')) {
$this->foreign = $this->foreign . '.' . $this->foreign . ':primary_key';
}
// Split them apart
$foreign = explode('.', $this->foreign);
// Create an array from them
$this->foreign = array('model' => $foreign[0], 'column' => $foreign[1]);
// We can work with nothing passed or just a model
if (empty($this->through) or is_string($this->through)) {
if (empty($this->through)) {
// Find the join table based on the two model names pluralized,
// sorted alphabetically and with an underscore separating them
$through = array(inflector::plural($this->foreign['model']), inflector::plural($model));
// Sort
sort($through);
// Bring them back together
$this->through = implode('_', $through);
}
$this->through = array('model' => $this->through, 'columns' => array(inflector::singular($model) . ':foreign_key', inflector::singular($this->foreign['model']) . ':foreign_key'));
}
parent::initialize($model, $column);
}
示例5: _tables
protected function _tables()
{
// Prepare an array to hold tables
$tables = array();
// Create a new database table with name and database
$table = new Database_Table($this->_model->table(), $this->_db);
// Get the model's primary keys as an array
$model_pks = is_array($this->_model->pk()) ? $this->_model->pk() : array($this->_model->pk());
// Loop through each field within the model
foreach ($this->_model->fields() as $field) {
// Check if the field implaments the migratable field interface
if ($field instanceof Sprig_Field_Migratable) {
// Loop through each column in the field
foreach ($field->columns() as $column) {
// Add the column to the table
$table->add_column($column);
}
} elseif ($field->in_db) {
// If the field is unique
if ($field->unique) {
// Add a unique constraint to the table
$table->add_constraint(new Database_Constraint_Unique($field->column));
}
// Loop through every column in the model
foreach ($this->_columns($field, $table) as $column) {
// Add the column to the table
$table->add_column($column);
}
} elseif ($field instanceof Sprig_Field_ManyToMany) {
// ManyToMany fields also contain a pivot table
$pivot = new Database_Table($field->through, $this->_db);
// Get the columns associated with the first half
$columns = $this->_columns(new Sprig_Field_BelongsTo(array('model' => $field->model)), $pivot);
// Foreach column in the first half
foreach ($columns as $column) {
// Add it to the pivot table
$pivot->add_column($column);
}
// Get the columns associated with the second half
$columns = $this->_columns(new Sprig_Field_BelongsTo(array('model' => inflector::singular($this->_model->table()))), $pivot);
// Foreach column in the second half
foreach ($columns as $column) {
// Add it to the pivot table
$pivot->add_column($column);
}
// Add a primary key constraint on all fields within the pivot table
$pivot->add_constraint(new Database_Constraint_Primary(array_keys($pivot->columns()), $pivot->name));
// Add the pivot table to the list of tables
$tables[] = $pivot;
}
}
// Add the primary key constraints to the table
$table->add_constraint(new Database_Constraint_Primary($model_pks, $table->name));
// Add the table to the list
$tables[] = $table;
// And return all tables.
return $tables;
}
示例6: getSynonomy
/**
* Retrieve the list of synonyms using a meaning id.
* @param string $meaning_field Name of the meaning field, either taxon_meaning_id or meaning_id.
* @param int $meaning_id Id value of the meaning to search for
* @param boolean $within_list Search within the current list only (true=default) or
* across all lists (false).
* @return ORM_Iterator List of synonyms
*/
public function getSynonomy($meaning_field, $meaning_id, $within_list = true)
{
$filters = array('preferred' => 'f', 'deleted' => 'f', $meaning_field => $meaning_id);
if ($within_list) {
$list_id_field = $this->list_id_field;
$filters[$list_id_field] = $this->{$list_id_field};
}
return ORM::factory(inflector::singular($this->table_name))->where($filters)->find_all();
}
示例7: tool
public function tool()
{
if (empty($_GET['tool_id'])) {
die('invalid tool_id');
}
$tool_id = valid::id_key($_GET['tool_id']);
$tool = ORM::factory('tool', $tool_id);
if (!$tool->loaded) {
die('invalid tool');
}
$toolname = strtolower($tool->system_tool->name);
# load the tool parent
$parent = ORM::factory($toolname, $tool->parent_id);
if (!$parent->loaded) {
die('invalid parent table');
}
# build the object.
$export = new stdClass();
$export->name = $toolname;
# export the parent table.
$parent_table = new stdClass();
foreach ($parent->table_columns as $key => $value) {
$parent_table->{$key} = $parent->{$key};
}
$export->parent_table = $parent_table;
# export any child tables.
$child_tables = new stdClass();
# loop through data from available child tables.
foreach ($parent->has_many as $table_name) {
$table_name = inflector::singular($table_name);
$child_tables->{$table_name} = array();
# get the child table model so we can iterate through the fields.
$table = ORM::factory($table_name);
# get any rows beloning to the parent.
$rows = ORM::factory($table_name)->where(array('fk_site' => $this->site_id, "{$toolname}_id" => $parent->id))->find_all();
foreach ($rows as $row) {
$object = new stdClass();
foreach ($table->table_columns as $key => $value) {
$object->{$key} = $row->{$key};
}
array_push($child_tables->{$table_name}, $object);
}
}
$export->child_tables = $child_tables;
# get the css file.
$export->css = file_get_contents($this->assets->themes_dir("{$this->theme}/tools/{$toolname}/_created/{$parent->id}/{$parent->type}_{$parent->view}.css"));
$json = json_encode($export);
echo '<h2>Copy this exactly and place into the importer=)</h2>';
echo "<textarea style='width:99%;height:400px;'>{$json}</textarea>";
die;
echo kohana::debug($export);
die;
# just testing ...
echo self::import($json);
die;
}
示例8: ordered2xml
/**
* Convert an ordered array to XML
* Wraps each element in the singular form of the root element
*
* @param array ordered array
* @param string root element, plural
* @return string XML String
*/
public static function ordered2xml($ordered, $root_element = "elements")
{
if (!is_array($ordered) || count($ordered) == 0) {
return "<" . $root_element . " />\n";
}
foreach ($ordered as $element) {
$xml .= xml::assoc2xml($element, inflector::singular($root_element));
}
return "<" . $root_element . ">\n" . xml::pad($xml) . "</" . $root_element . ">\n";
}
示例9: initialize
/**
* Determines the actual foreign model and field that the
* relationship is tied to.
*
* @param string $model
* @param string $column
* @return void
*/
public function initialize($model, $column)
{
parent::initialize($model, $column);
// Empty? The model defaults to the the singularized name
// of this field, and the field defaults to this field's model's foreign key
if (empty($this->foreign)) {
$this->foreign = inflector::singular($this->name) . '.' . $model . ':foreign_key';
} elseif (FALSE === strpos($this->foreign, '.')) {
$this->foreign = $this->foreign . '.' . $model . ':foreign_key';
}
// Create an array fo easier access to the separate parts
$this->foreign = array_combine(array('model', 'field'), explode('.', $this->foreign));
}
示例10: initialize
/**
* Overrides the initialize to automatically provide the column name
*
* @param string $model
* @param string $column
* @return void
*/
public function initialize($model, $column)
{
// Default to the name of the column
if (empty($this->foreign)) {
$this->foreign = inflector::singular($column) . '.' . $model . ':foreign_key';
} elseif (FALSE === strpos($this->foreign, '.')) {
$this->foreign = $this->foreign . '.' . $model . ':foreign_key';
}
// Split them apart
$foreign = explode('.', $this->foreign);
// Create an array from them
$this->foreign = array('model' => $foreign[0], 'column' => $foreign[1]);
parent::initialize($model, $column);
}
示例11: __construct
public function __construct()
{
parent::__construct();
if (in_array(Router::$method, $this->excluded_actions)) {
Event::run('system.404');
}
if (!$this->model_name) {
$this->model_name = inflector::singular(Router::$controller);
}
$this->plural = inflector::plural($this->model_name);
$this->directory = $this->base_route . $this->plural;
// Do not render, by default, if the request is an ajax request
if (request::is_ajax()) {
$this->auto_render = false;
}
}
示例12: __construct
function __construct($config = array())
{
parent::__construct();
$name = Uri::instance()->segment(1, Kohana::config('controls.default_controller'));
$setup = Kohana::config('controls.' . $name);
if ($setup != false) {
$this->setup = $setup;
} else {
$this->setup = array();
$this->setup['name'] = $name;
$this->setup['model'] = inflector::singular($name);
$this->setup['table'] = $name;
$this->setup['view'] = 'standard';
}
$this->name = $this->setup['name'];
$this->set_listeners();
}
示例13: get_list
/**
* return list
*
* @param object $lc
* @return array
* @author Andy Bennett
*/
public function get_list()
{
$data = array('action' => 'list', 'name' => $this->name, 'role' => User::instance()->get_role());
Event::run('steamcore.aclcheck', $data);
$tdata = array();
$limit = 10;
$page_num = $this->input->get('page', 1);
$offset = ($page_num - 1) * $limit;
$model = ORM::factory($this->setup['model'], null);
$role = inflector::singular(URI::instance()->segment(1));
$data['query'] = $model->where('role', $role)->find_all($limit, $offset);
$data['controller'] = Kohana::instance()->uri->segment(1);
$data['pagination'] = Pagination::factory(array('style' => 'digg', 'items_per_page' => $limit, 'query_string' => 'page', 'total_items' => $model->count_last_query()));
// merge any passed data and the data returned from the model
$tdata = array_merge($tdata, $data);
// return the result
return $tdata;
}
示例14: find_related
public function find_related($key)
{
$model = ORM::factory(inflector::singular($key));
// Load the "end" model
if (in_array($key, $this->has_one)) {
// one<>many relationship
return $model->where($model->primary_key, $this->object[$this->foreign_key($model->object_name)]);
} else {
// many<>many relationship
$through = ORM::factory(inflector::singular($this->has_many[$key]));
// Load the "middle" model
// Join ON target model's primary key set to 'through' model's foreign key
// User-defined foreign keys must be defined in the 'through' model
$join_table = $through->table_name;
$join_col1 = $through->foreign_key($model->object_name, $join_table);
$join_col2 = $model->table_name . '.' . $model->primary_key;
return $model->join($join_table, $join_col1, $join_col2)->where($through->foreign_key($this->object_name, $join_table), $this->object[$this->primary_key]);
}
}
示例15: checkboxes_wrap
/**
* Creates checkboxes list
*
* @param string $name input name
* @param array $data array of checkboxes
* @param array $values checked values
* @param string $label
* @param string|array $error
* @param string|array $tip
* @return string
*/
public static function checkboxes_wrap($name, $data = array(), $values = array(), $label = '', $error = '', $class = '', $tip = '')
{
// Get checkboxes
$checkboxes = isset($data[$name]) ? $data[$name] : $data;
if (!empty($checkboxes)) {
// Create internal id
$singular = inflector::singular($name) . '_';
// Get values
$values = array_key_exists($name, $values) ? $values[$name] : $values;
$input = empty($class) ? "<ul>\n" : '<ul class="' . $class . "\">\n";
foreach ($checkboxes as $checkbox_id => $checkbox_name) {
$internal_id = $singular . $checkbox_id;
$input .= '<li>';
$input .= form::checkbox(array('id' => $internal_id, 'name' => $name . '[' . $checkbox_id . ']'), 1, isset($values[$checkbox_id]));
$input .= form::label($internal_id, $checkbox_name);
$input .= "</li>\n";
}
$input .= "</ul>\n";
return form::wrap($input, $name, $label, $error, $tip);
}
}