當前位置: 首頁>>代碼示例>>PHP>>正文


PHP Inflector::singular方法代碼示例

本文整理匯總了PHP中Inflector::singular方法的典型用法代碼示例。如果您正苦於以下問題:PHP Inflector::singular方法的具體用法?PHP Inflector::singular怎麽用?PHP Inflector::singular使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在Inflector的用法示例。


在下文中一共展示了Inflector::singular方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的PHP代碼示例。

示例1: initialize

 /**
  * Assign default forein_model to singular association name
  * @param  Jam_Meta $meta
  * @param  string   $name
  */
 public function initialize(Jam_Meta $meta, $name)
 {
     if (!$this->foreign_model) {
         $this->foreign_model = Inflector::singular($name);
     }
     parent::initialize($meta, $name);
 }
開發者ID:Konro1,項目名稱:pms,代碼行數:12,代碼來源:Collection.php

示例2: before

 public function before()
 {
     parent::before();
     // Save the old action so it can be brought back on after
     $this->_action = $this->request->action;
     // Set the current action
     $current_action = $this->request->action;
     $id = $this->request->param('id', NULL);
     // Let's guess the action based on the params
     if (!in_array($this->request->action, array('edit', 'add', 'delete')) and (!is_null($id) or !empty($id))) {
         $current_action = 'read';
     }
     if (!method_exists($this, 'action_' . $this->request->action)) {
         $model = Jelly::select(Inflector::singular($this->request->controller));
         foreach ($model->get_state() as $key => $value) {
             $param = $this->request->param($key, NULL);
             if (!is_null($param)) {
                 $model->set_state($key, $param);
             }
         }
         $this->request->response = Kostache::factory($this->request->controller . '/' . $current_action)->set_model($model);
         // Since the magic has been executed, just execute an empty action
         $this->request->action = 'default';
     }
 }
開發者ID:raeldc,項目名稱:kojo-plugin,代碼行數:25,代碼來源:controller.php

示例3: xml

 /**
  * Convert an array to XML string
  *
  * @static
  * @param   array   $array
  * @param   string  $root
  * @param   SimpleXMLElement  $xml
  * @return  string
  */
 public static function xml(array $array, $root = 'data', SimpleXMLElement &$xml = null)
 {
     // Initialize
     if (is_null($xml)) {
         $xml = simplexml_load_string('<?xml version="1.0" encoding="' . Kohana::$charset . '"?><' . $root . ' />');
     }
     foreach ($array as $key => $value) {
         // No numeric keys in our xml please!
         $numeric = false;
         if (is_numeric($key)) {
             $numeric = true;
             $key = Inflector::singular($root);
         }
         // Valid XML name
         $key = preg_replace('/[^a-z0-9\\-\\_\\.\\:]/i', '', $key);
         // Recursive call required for array values
         if (is_array($value)) {
             $node = true || Arr::is_assoc($value) || $numeric ? $xml->addChild($key) : $xml;
             self::xml($value, $key, $node);
         } else {
             $xml->addChild($key, htmlspecialchars($value));
         }
     }
     return $xml->asXML();
 }
開發者ID:netbiel,項目名稱:core,代碼行數:34,代碼來源:arr.php

示例4: get_error

 /**
  * Get field validation messages
  * 
  * @return string
  */
 public function get_error()
 {
     $errors = $this->_get_view_var('errors');
     if ($errors) {
         if ($this->_field instanceof Jelly_Field_ManyToMany) {
             if (array_key_exists(Inflector::singular($this->_field->name), $errors)) {
                 return $errors[Inflector::singular($this->_field->name)];
                 //extra validation from controller
             } elseif (isset($errors['_external'])) {
                 if (array_key_exists(Inflector::singular($this->_field->name), $errors['_external'])) {
                     return $errors['_external'][Inflector::singular($this->_field->name)];
                 }
             }
         } else {
             if (array_key_exists($this->_field->name, $errors)) {
                 return $errors[$this->_field->name];
                 //extra validation from controller
             } elseif (isset($errors['_external'])) {
                 if (array_key_exists($this->_field->name, $errors['_external'])) {
                     return $errors['_external'][$this->_field->name];
                 }
             }
         }
     }
 }
開發者ID:piotrtheis,項目名稱:jelly-form,代碼行數:30,代碼來源:field.php

示例5: __construct

 /**
  * Constructs a new CDM model
  *
  * @param  key  record key to load
  */
 public function __construct($key = NULL)
 {
     if (!CDM::$_connected) {
         foreach (Kohana::config('cdm')->connection['hosts'] as $host) {
             // Connect to cassandra nodes
             CassandraConn::add_node($host['hostname'], $host['port']);
         }
         CDM::$_connected = TRUE;
     }
     if (!isset($this->_keyspace)) {
         // Find the application keyspace if not already set
         $this->_keyspace = Kohana::config('cdm')->keyspace;
     }
     if (!isset($this->_column_family)) {
         // Use singular version of model name for the column family
         $this->_column_family = Inflector::singular(strtolower(substr(get_class($this), 10)));
     }
     if (!isset(CDM::$_managers[$this->_keyspace][$this->_column_family])) {
         // Create column manager
         CDM::$_managers[$this->_keyspace][$this->_column_family] = new CassandraCF($this->_keyspace, $this->_column_family, $this->_is_super);
     }
     $this->_manager = CDM::$_managers[$this->_keyspace][$this->_column_family];
     if ($key !== NULL) {
         // Load initial record
         $this->find($key);
     }
 }
開發者ID:jylinman,項目名稱:kohana-cdm,代碼行數:32,代碼來源:cdm.php

示例6: initialize

 /**
  * Initialize object (for relations)
  * @param orm $object 
  */
 public function initialize(&$object)
 {
     $models[0] = Inflector::plural(strtolower(str_replace('Model_', '', get_class($object))));
     $models[1] = $this->item['name'];
     sort($models);
     $object->create_relation('hasMany', $this->item['name'], array('model' => Inflector::singular($this->item['name']), 'through' => $models[0] . '_' . $models[1]));
 }
開發者ID:raku,項目名稱:MorCMS,代碼行數:11,代碼來源:manytomany.php

示例7: config

 public function config($group, $type, $model_name = NULL)
 {
     $model_name = $model_name ? $model_name : $this->model_name;
     $config = self::$_config === NULL ? self::$_config = Kohana::$config->load('huia/api') : self::$_config;
     $custom = $config->get('custom_' . $group);
     $regexp = Arr::path($custom, strtolower(Inflector::singular($model_name)) . '.' . $type);
     return $regexp !== NULL ? $regexp : Arr::get($config->get($group), $type);
 }
開發者ID:huiancg,項目名稱:kohana-huia-api,代碼行數:8,代碼來源:App.php

示例8: title

 public function title()
 {
     $name = str_replace('Controller_Tart_', '', get_class($this));
     $name = ucwords(Inflector::humanize($name));
     if ($this->request->param('id')) {
         return ucwords(Inflector::singular($name)) . ' - ' . Inflector::humanize($this->request->action());
     } else {
         return $name . ' - ' . Inflector::humanize($this->request->action());
     }
 }
開發者ID:openbuildings,項目名稱:jam-tart,代碼行數:10,代碼來源:Layout.php

示例9: before

 /**
  * Prepare controller and model for crud actions
  */
 public function before()
 {
     parent::before();
     $this->controller_name = $this->request->controller();
     if ($this->model == null) {
         $this->model = $this->request->controller();
     }
     if (is_string($this->model)) {
         $this->model = ORM::factory(Inflector::singular($this->model));
     }
 }
開發者ID:raku,項目名稱:MorCMS,代碼行數:14,代碼來源:crud.php

示例10: add_validator

 /**
  * Add a validator item
  *
  * @access public
  * @param mixed $type
  * @param mixed $rule
  * @return object
  */
 public function add_validator($type, $rule)
 {
     $type = Inflector::plural($rule->type);
     if (in_array($type, array('filters', 'display_filters'))) {
         return $this->add_filter(Inflector::singular($type), $rule);
     }
     $next = count($this->_validators[$type]);
     // Resolve the context
     $this->make_context($rule);
     $this->_validators[$type][$next] = $rule;
     return $this;
 }
開發者ID:justus,項目名稱:kohana-formo,代碼行數:20,代碼來源:core.php

示例11: __construct

 /**
  * Try to load Flatfile Model, based on url segment
  * Throw 404 error page if markdown file cant found
  **/
 public function __construct()
 {
     try {
         $model_name = Inflector::singular(strtolower(Request::current()->controller()));
         $model = 'Model_' . ucfirst($model_name);
         /**
          * Assign model to a variable named as the controller name
          **/
         $this->{$model_name} = new $model(Request::initial()->param('slug'));
     } catch (Kohana_Exception $e) {
         if ($slug = Request::initial()->param('slug')) {
             throw HTTP_Exception::factory(404, __("Unable to find page :slug"), array(':slug' => $slug));
         }
         throw HTTP_Exception::factory(404, __("Unable to find URI :uri"), array(':uri' => Request::initial()->uri()));
     }
 }
開發者ID:ziopod,項目名稱:kitsune,代碼行數:20,代碼來源:Master.php

示例12: input_edit

 /**
  * Input for edit item
  * @return string Form::input
  */
 public function input_edit($value)
 {
     if (is_object($value)) {
         $id = $value->id;
     } else {
         $id = $value;
         $value = ORM::factory(Inflector::singular($this->item['name']), $id);
     }
     $field = isset($this->item['field']) ? $this->item['field'] : 'name';
     $values_model = $value->clear()->find_all()->as_array($field);
     $values = array();
     foreach ($values_model as $value) {
         $values[$value->id] = $value->{$field};
     }
     if (!$this->item['notnull']) {
         Arr::unshift($values, 0, '');
     }
     return Form::select($this->item['name'], $values, $id);
 }
開發者ID:raku,項目名稱:MorCMS,代碼行數:23,代碼來源:belongsto.php

示例13: age

 /**
  * Returns age in human readable format with only the largest span
  *
  * @param		int|string	$time1
  * @param		int|string	$time2
  * @param		string			$output
  * @return	string
  */
 public static function age($time1, $time2 = null)
 {
     if (!is_numeric($time1)) {
         $time1 = strtotime($time1);
     }
     if (!is_null($time2) && !is_int($time2)) {
         $time2 = strtotime($time2);
     }
     if ($difference = Date::span($time1, $time2) and is_array($difference)) {
         foreach ($difference as $span => $amount) {
             if ($amount > 0) {
                 return $amount . ' ' . __(Inflector::singular($span, $amount));
             }
         }
     }
     if (empty($difference)) {
         return '0 ' . __('seconds');
     }
     return __('some time');
 }
開發者ID:anqh,項目名稱:core,代碼行數:28,代碼來源:date.php

示例14: count_all

 /**
  * Count the number of records in the table.
  * @param bool $reset Pass FALSE to avoid resetting on the next call
  * @return int
  */
 public function count_all($reset = true)
 {
     $is_distinct = false;
     $selects = [];
     foreach ($this->_db_pending as $key => $method) {
         if ($method['name'] == 'distinct') {
             $is_distinct = true;
             // Ignore any selected columns for now
             $selects[] = $method;
             unset($this->_db_pending[$key]);
         }
         if ($method['name'] == 'select') {
             // Ignore any selected columns for now
             $selects[] = $method;
             unset($this->_db_pending[$key]);
         }
     }
     if (!empty($this->_load_with)) {
         foreach ($this->_load_with as $alias) {
             // Bind relationship
             $this->with($alias);
         }
     }
     $this->_build(Database::SELECT);
     $records = $this->_db_builder->from([$this->_table_name, $this->_object_name]);
     if ($is_distinct) {
         $records->select([DB::expr('COUNT(DISTINCT(`' . Inflector::singular($this->_table_name) . '`.`' . $this->_primary_key . '`))'), 'records_found']);
     } else {
         $records->select([DB::expr('COUNT(*)'), 'records_found']);
     }
     $records = $records->execute($this->_db)->get('records_found');
     // Add back in selected columns
     $this->_db_pending += $selects;
     $this->reset($reset);
     // Return the total number of records in a table
     return $records;
 }
開發者ID:eok8177,項目名稱:shopCMS,代碼行數:42,代碼來源:ORM.php

示例15: __construct

 /**
  * Initialize the fields and add validation rules based on field properties.
  *
  * @return  void
  */
 protected function __construct()
 {
     if ($this->_init) {
         if ($this->state() === 'loading') {
             // Object loading via mysql_fetch_object or similar has finished
             $this->state('loaded');
         }
         // Can only be called once
         return;
     }
     // Initialization has been started
     $this->_init = TRUE;
     // Set up the fields
     $this->_init();
     if (!$this->_model) {
         // Set the model name based on the class name
         $this->_model = strtolower(substr(get_class($this), 6));
     }
     if (!$this->_table) {
         // Set the table name to the plural model name
         $this->_table = inflector::plural($this->_model);
     }
     foreach ($this->_fields as $name => $field) {
         if ($field->primary === TRUE) {
             if (!$this->_primary_key) {
                 // This is the primary key
                 $this->_primary_key = $name;
             } else {
                 if (is_string($this->_primary_key)) {
                     // More than one primary key found, create a list of keys
                     $this->_primary_key = array($this->_primary_key);
                 }
                 // Add this key to the list
                 $this->_primary_key[] = $name;
             }
         }
     }
     foreach ($this->_fields as $name => $field) {
         if ($field instanceof Sprig_Field_ForeignKey and !$field->model) {
             if ($field instanceof Sprig_Field_HasMany) {
                 $field->model = Inflector::singular($name);
             } else {
                 $field->model = $name;
             }
         }
         if ($field instanceof Sprig_Field_ManyToMany) {
             if (!$field->through) {
                 // Get the model names for the relation pair
                 $pair = array(strtolower($this->_model), strtolower($field->model));
                 // Sort the model names alphabetically
                 sort($pair);
                 // Join the model names to get the relation name
                 $pair = implode('_', $pair);
                 if (!isset(Sprig::$_relations[$pair])) {
                     // Must set the pair key before loading the related model
                     // or we will fall into an infinite recursion loop
                     Sprig::$_relations[$pair] = TRUE;
                     $tables = array($this->table(), Sprig::factory($field->model)->table());
                     // Sort the table names alphabetically
                     sort($tables);
                     // Join the table names to get the table name
                     Sprig::$_relations[$pair] = implode('_', $tables);
                 }
                 // Assign by reference so that changes to the pivot table
                 // will carry over to all models
                 $field->through =& Sprig::$_relations[$pair];
             }
         }
         if (!$field->column) {
             // Create the key based on the field name
             if ($field instanceof Sprig_Field_BelongsTo) {
                 if (isset($field->foreign_key) and $field->foreign_key) {
                     $fk = $field->foreign_key;
                 } else {
                     $fk = Sprig::factory($field->model)->fk();
                 }
                 $field->column = $fk;
             } elseif ($field instanceof Sprig_Field_HasOne) {
                 $field->column = $this->fk();
             } elseif ($field instanceof Sprig_Field_ForeignKey) {
                 // This field is probably a Many and does not need a column
             } else {
                 $field->column = $name;
             }
         }
         if (!$field->label) {
             $field->label = Inflector::humanize($name);
         }
         if ($field->null) {
             // Fields that allow NULL values must accept empty values
             $field->empty = TRUE;
         }
         if ($field->editable) {
             if (!$field->empty and !isset($field->rules['not_empty'])) {
                 // This field must not be empty
//.........這裏部分代碼省略.........
開發者ID:hawkip,項目名稱:sprig,代碼行數:101,代碼來源:core.php


注:本文中的Inflector::singular方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。