本文整理匯總了PHP中Inflector::variable方法的典型用法代碼示例。如果您正苦於以下問題:PHP Inflector::variable方法的具體用法?PHP Inflector::variable怎麽用?PHP Inflector::variable使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類Inflector
的用法示例。
在下文中一共展示了Inflector::variable方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的PHP代碼示例。
示例1: tokenize
/**
* Tokenize
*
* @param string $action reset|confirm
* @param string $field password|email
* @param array $data CakeRequest::data
*
* @return array $user User::find
*/
public function tokenize(Model $Model, $action, $field, $data = array())
{
if (empty($field) || empty($action) || !in_array($field, array('password', 'email')) || !in_array($action, array('reset', 'confirm'))) {
throw new InvalidArgumentException('Invalid agruments');
}
return $this->dispatchMethod('_' . Inflector::variable(sprintf('tokenize_%s_%s', $action, $field)), array($Model, $data));
}
示例2: init
/**
* Cette fonction permet l'initialisation de la variable de session
*
* @access static
* @author koéZionCMS
* @version 0.1 - 20/04/2012
* @version 0.2 - 31/07/2012 - Suppression de la récupération des données de la variable de session par un fichier
* @version 0.3 - 09/11/2012 - Rajout du test pour savoir si les classes Inflector et Set sont chargées
*/
static function init()
{
if (!class_exists('Inflector')) {
require_once CAKEPHP . DS . 'inflector.php';
}
if (!class_exists('Set')) {
require_once CAKEPHP . DS . 'set.php';
}
$sessionName = Inflector::variable(Inflector::slug('koeZion ' . $_SERVER['HTTP_HOST']));
//Récupération du nom de la variable de session
//Récupération des configuration du coeur de l'application pour détermine le mode de stockage des variables de sessions
//Soit on utilise le comportement natif de PHP
//Soit on stocke les sessions en local dans le dossier TMP
require_once LIBS . DS . 'config_magik.php';
$cfg = new ConfigMagik(CONFIGS . DS . 'files' . DS . 'core.ini', true, false);
$coreConfs = $cfg->keys_values();
if (isset($coreConfs['local_storage_session']) && $coreConfs['local_storage_session']) {
ini_set('session.save_path', TMP . DS . 'sessions');
}
ini_set('session.use_trans_sid', 0);
//Evite de passe l'id de la session dans l'url
session_name($sessionName);
//On affecte le nom
session_start();
//On démarre la session
}
示例3: load
function load($admin, $useDbAssociations = false)
{
// Load an instance of the admin model object
$plugin = Inflector::camelize($admin->plugin);
$modelObj = ClassRegistry::init(array('class' => "{$plugin}.{$admin->modelName}Admin", 'table' => $admin->useTable, 'ds' => $admin->useDbConfig));
$adminModelObj = ClassRegistry::init(array('class' => "{$plugin}.{$admin->modelName}Admin", 'table' => $admin->useTable, 'ds' => $admin->useDbConfig));
$modelClass = $admin->modelName . 'Admin';
$primaryKey = $adminModelObj->primaryKey;
$displayField = $adminModelObj->displayField;
$schema = $adminModelObj->schema(true);
$fields = array_keys($schema);
$controllerName = $this->_controllerName($admin->modelName);
$controllerRoute = $this->_pluralName($admin->modelName);
$pluginControllerName = $this->_controllerName($admin->modelName . 'Admin');
$singularVar = Inflector::variable($modelClass);
$singularName = $this->_singularName($modelClass);
$singularHumanName = $this->_singularHumanName($this->_controllerName($admin->modelName));
$pluralVar = Inflector::variable($pluginControllerName);
$pluralName = $this->_pluralName($modelClass);
$pluralHumanName = Inflector::humanize($this->_pluralName($controllerName));
if ($useDbAssociations) {
$associations = $this->loadAssociations($modelObj, $admin);
} else {
$associations = $this->__associations($adminModelObj);
}
return compact('admin', 'modelObj', 'adminModelObj', 'modelClass', 'primaryKey', 'displayField', 'schema', 'fields', 'controllerName', 'controllerRoute', 'pluginControllerName', 'singularVar', 'singularName', 'singularHumanName', 'pluralVar', 'pluralName', 'pluralHumanName', 'associations');
}
示例4: checkboxBlockRolePermission
/**
* Outputs room roles radio
*
* @param string $fieldName Name attribute of the RADIO
* @param array $attributes The HTML attributes of the select element.
* @return string Formatted RADIO element
* @link http://book.cakephp.org/2.0/en/core-libraries/helpers/form.html#options-for-select-checkbox-and-radio-inputs
*/
public function checkboxBlockRolePermission($fieldName, $attributes = array('inline' => true))
{
list($model, $permission) = explode('.', $fieldName);
$html = '';
if (!isset($this->_View->request->data[$model][$permission])) {
return $html;
}
$html .= '<div class="form-inline">';
foreach ($this->_View->request->data[$model][$permission] as $roleKey => $role) {
if (!$role['value'] && $role['fixed']) {
continue;
}
$html .= '<span class="checkbox-separator"></span>';
$html .= '<div class="form-group">';
if (!$role['fixed']) {
$html .= $this->Form->hidden($fieldName . '.' . $roleKey . '.id');
$html .= $this->Form->hidden($fieldName . '.' . $roleKey . '.roles_room_id');
$html .= $this->Form->hidden($fieldName . '.' . $roleKey . '.block_key');
$html .= $this->Form->hidden($fieldName . '.' . $roleKey . '.permission');
}
$options = Hash::merge(array('div' => false, 'disabled' => (bool) $role['fixed']), $attributes);
if (!$options['disabled']) {
$options['ng-click'] = 'clickRole($event, \'' . $permission . '\', \'' . Inflector::variable($roleKey) . '\')';
}
$html .= $this->Form->checkbox($fieldName . '.' . $roleKey . '.value', $options);
$html .= $this->Form->label($fieldName . '.' . $roleKey . '.value', h($this->_View->viewVars['roles'][$roleKey]['name']));
$html .= '</div>';
}
$html .= '</div>';
return $html;
}
示例5: defID
function defID()
{
if (!empty($this->params['id'])) {
return $options['id'] = $this->params['id'];
} else {
if (!empty($this->params['named']['id'])) {
return $options['id'] = $this->params['named']['id'];
} else {
if (!empty($this->params['pass'][0]) && is_numeric($this->params['pass'][0])) {
return $options['id'] = $this->params['pass'][0];
}
}
}
$model = $this->defModel();
if ($model) {
if (!empty($this->data[$model]['id'])) {
return $this->data[$model]['id'];
}
$view =& ClassRegistry::getObject('view');
if (!empty($view->viewVars[Inflector::variable($model)][$model]['id'])) {
return $view->viewVars[Inflector::variable($model)][$model]['id'];
}
}
return null;
}
示例6: implementedEvents
/**
* implementedEvents
*
* @return array
*/
public function implementedEvents()
{
$events = array();
if ($this->events) {
foreach ($this->events as $key => $registerEvent) {
$options = array();
if (is_array($registerEvent)) {
$options = $registerEvent;
$registerEvent = $key;
}
$eventName = $this->layer . '.' . $registerEvent;
if (strpos($registerEvent, '.') !== false) {
$aryRegisterEvent = explode('.', $registerEvent);
$registerEvent = Inflector::variable(implode('_', $aryRegisterEvent));
}
if ($options) {
$options = array_merge(array('callable' => $registerEvent), $options);
} else {
$options = array('callable' => $registerEvent);
}
$events[$eventName] = $options;
}
}
return $events;
}
示例7: viewVar
/**
* Change the name of the view variable name
* of the data when its sent to the view
*
* @param mixed $name
* @return mixed
*/
public function viewVar($name = null)
{
if (empty($name)) {
return $this->config('viewVar') ?: Inflector::variable($this->_model()->name);
}
return $this->config('viewVar', $name);
}
示例8: convert
public function convert($from, $to, $data, $options = array())
{
$function1 = Inflector::variable("{$from}_to_array");
$function2 = Inflector::variable("array_to_{$to}");
if (method_exists($this, $function1) && method_exists($this, $function2)) {
return $this->{$function2}($this->{$function1}($data, $options), $options);
}
}
示例9: setup
/**
* @param AppModel $model
* @param array $config Defaults:
* 'collection' => 'global',
* 'name' => "Mirrored.variableStyleModelName",
* 'findType' => 'all' or 'threaded',
* 'findOptions' => array('recursive' => -1),
*/
public function setup($model, $config = array())
{
$config = (array) $config;
$config += array('collection' => 'global', 'name' => "Mirror." . Inflector::variable($model->alias), 'findType' => $model->Behaviors->enabled('Tree') ? 'threaded' : 'all', 'findOptions' => array(), 'collectionField' => null, 'groupField' => null, 'indexField' => null, 'valueField' => null, 'valueFields' => array(), 'autoRefresh' => true);
$config['findOptions'] += array('recursive' => -1);
$config += array('noModelName' => $config['findOptions']['recursive'] == -1);
$this->_pending[$model->alias] = $config['autoRefresh'] ? 0 : 100000;
$this->settings[$model->alias] = $config;
}
示例10: getPrototypes
public function getPrototypes()
{
$searchdirs['App'] = APP . 'View';
$searchdirs['Basic'] = CakePlugin::path('Muffin');
foreach (CakePlugin::loaded() as $plugin) {
if ($plugin != 'Muffin') {
$searchdirs[$plugin] = CakePlugin::path($plugin) . 'View';
}
}
$configs = array();
foreach ($searchdirs as $plugin => $searchdir) {
$dir = new Folder($searchdir, false);
if ($files = $dir->findRecursive('config.xml')) {
$configs = Hash::merge($configs, array($plugin => $files));
}
}
$prototypes = array();
foreach ($configs as $plugin => $configFiles) {
$i = 0;
foreach ($configFiles as $configFile) {
$xml = Xml::build($configFile);
$items = $xml->xpath('menu/item');
if (!is_array($items) || empty($items)) {
continue;
}
foreach ($items as $item) {
$item = Xml::toArray($item);
if (empty($item['item']['@label'])) {
continue;
}
if (!isset($item['item']['@id']) || empty($item['item']['@id'])) {
$id = ucfirst(Inflector::variable($item['item']['@label']));
} else {
$id = $item['item']['@id'];
}
$fields = array();
foreach ($item['item']['field'] as $key => $field) {
foreach ($field as $name => $value) {
$name = str_replace('@', '', $name);
$fields[$key][$name] = $value;
}
}
$prototypes[$plugin][$i]['Link']['id'] = $id;
$prototypes[$plugin][$i]['Link']['priority'] = !empty($item['item']['@priority']) ? $item['item']['@priority'] : '10';
$prototypes[$plugin][$i]['Link']['model'] = !empty($item['item']['@model']) ? $item['item']['@model'] : '';
$prototypes[$plugin][$i]['Link']['label'] = $item['item']['@label'];
$prototypes[$plugin][$i]['Field'] = $fields;
$i++;
}
}
}
foreach ($prototypes as $plugin => $section) {
$prototypes[$plugin] = Hash::sort($section, '{n}.Link.priority', 'asc');
}
return $prototypes;
}
示例11: addShortcodes
/**
* @param array $shortcodes
* @return void
*/
private function addShortcodes($shortcodes)
{
foreach ($shortcodes as $shortcode) {
$method = '__initShortcode_' . Inflector::variable(Inflector::slug($shortcode['id'], '_'));
add_shortcode($shortcode['id'], array(&$this, $method));
if (isset($shortcode['shortcodes'])) {
$this->addShortcodes($shortcode['shortcodes']);
}
}
}
示例12: beforeSave
public function beforeSave($options = array())
{
$parent = parent::beforeSave($options);
if (empty($this->data[$this->alias]['name'])) {
return $parent;
}
$name = $this->data[$this->alias]['name'];
$name_slug = strtolower(Inflector::slug($name));
$name_variable = Inflector::variable($name_slug);
$this->data[$this->alias] += compact('name_variable', 'name_slug');
return $parent;
}
示例13: input
/**
* Drop in replacement for FormHelper::input which adds additional logic for
* determining whether to display certain fields, what type to use, and
* setting additional CSS class names
*
* @param string $fieldName
* @param array $options
* @return string
*/
function input($fieldName, $options = array())
{
// Do not display TreeBehavior lft and rght fields
if (in_array($fieldName, array('lft', 'rght'))) {
return;
}
// Do not display counter cache fields
$isCount = substr($fieldName, -6) === '_count';
if ($isCount) {
return;
}
// Determine if this field is a key
$isKey = substr($fieldName, -3) === '_id';
// Determine if this field is a HABTM
$this->Form->setEntity($fieldName);
$isHabtm = $this->Form->model() === $this->Form->field();
// If field is a key or habtm and options are not specified in options array
if (($isKey || $isHabtm) && !isset($options['options'])) {
// Try and get the options from the view vars
$view =& ClassRegistry::getObject('view');
$varName = Inflector::variable(Inflector::pluralize(preg_replace('/_id$/', '', $fieldName)));
$varOptions = $view->getVar($varName);
// If options is not an array, or empty, don't display the field
if (!is_array($varOptions) || empty($varOptions)) {
return;
}
}
// Set default options required by CSS
$defaults = array('label' => array('class' => 'label'));
// If HABTM, set multiple type and various classnames
if ($isHabtm) {
$defaults['multiple'] = $defaults['class'] = $defaults['label']['class'] = 'checkbox';
}
// Set classnames depending to field type required by CSS
$model =& ClassRegistry::getObject($this->model());
$type = $model->getColumnType($fieldName);
switch ($type) {
case 'string':
$defaults['class'] = 'text';
break;
case 'boolean':
$defaults['class'] = $defaults['label']['class'] = 'checkbox';
break;
}
// Add empty option
if ($isKey) {
$defaults['empty'] = __('Please select', true);
}
// Merge defaults with options
$options = Set::merge($defaults, $options);
// Return the form input markup
return $this->Form->input($fieldName, $options);
}
示例14: implementedEvents
/**
* implementedEvents
*
* @return array
*/
public function implementedEvents()
{
$events = array();
if ($this->events) {
foreach ($this->events as $registerEvent) {
$eventName = $this->layer . '.' . $registerEvent;
if (strpos($registerEvent, '.') !== false) {
$aryRegisterEvent = explode('.', $registerEvent);
$registerEvent = Inflector::variable(implode('_', $aryRegisterEvent));
}
$events[$eventName] = array('callable' => $registerEvent);
}
}
return $events;
}
示例15: loadHelpers
public function loadHelpers()
{
parent::loadHelpers();
$helpers = HelperCollection::normalizeObjectArray($this->helpers);
foreach ($helpers as $properties) {
list(, $class) = pluginSplit($properties['class']);
$helper = $this->{$class};
$class = Inflector::variable($class);
if (!isset($this->viewVars[$class])) {
$this->viewVars[$class] = $helper;
}
$this->Phptal->set($class, $helper);
$this->_createHelperModifier($class);
}
unset($class, $helpers, $helper);
}