本文整理匯總了PHP中Inflector::underscore方法的典型用法代碼示例。如果您正苦於以下問題:PHP Inflector::underscore方法的具體用法?PHP Inflector::underscore怎麽用?PHP Inflector::underscore使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類Inflector
的用法示例。
在下文中一共展示了Inflector::underscore方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的PHP代碼示例。
示例1: getExternalConditions
public static function getExternalConditions($select, $parentModel, $childName, $attributes)
{
$parentModelName = get_class($parentModel);
$parentTableName = $parentModel->getTableName();
// exhibitions
$childName = array_key_exists('source', $attributes) ? $attributes['source'] : $childName;
$childModelName = Inflector::classify($childName);
$childTableName = Bbx_Model::load($childModelName)->getTableName();
// images
if (!array_key_exists($childTableName, $select->getPart('from'))) {
$select->from($childTableName, array());
// images
}
if (array_key_exists('as', $attributes)) {
$refColumn = $attributes['as'] . '_id';
$polyType = $attributes['as'] . '_type';
} else {
$refColumn = Inflector::singularize($parentTableName) . '_id';
}
try {
$parentModel->getRowData();
$select->where("`" . $childTableName . "`.`" . $refColumn . "` = " . $parentModel->id);
} catch (Exception $e) {
$select->where("`" . $childTableName . "`.`" . $refColumn . "` = `" . $parentTableName . "`.`id`");
}
if (isset($polyType)) {
$select->where("`" . $childTableName . "`.`" . $polyType . "` = '" . Inflector::underscore($parentModelName) . "'");
}
return $select;
}
示例2: initialize
/**
* Configuration method.
*
* In addition to configuring the settings (see $__defaults above for settings explanation),
* this function also loops through the installed plugins and 'registers' those that have a
* PluginNameCallback class.
*
* @param object $controller Controller object
* @param array $settings Component settings
* @access public
* @return void
*/
public function initialize(&$controller, $settings = array())
{
$this->__controller =& $controller;
$this->settings = array_merge($this->__defaults, $settings);
if (empty($this->settings['priority'])) {
$this->settings['priority'] = Configure::listobjects('plugin');
} else {
foreach (Configure::listobjects('plugin') as $plugin) {
if (!in_array($plugin, $this->settings['priority'])) {
array_push($this->settings['priority'], $plugin);
}
}
}
foreach ($this->settings['priority'] as $plugin) {
$file = Inflector::underscore($plugin) . '_callback';
$className = $plugin . 'Callback';
if (App::import('File', $className, true, array(APP . 'plugins' . DS . Inflector::underscore($plugin)), $file . '.php')) {
if (class_exists($className)) {
$class = new $className();
ClassRegistry::addObject($className, $class);
$this->__registered[] = $className;
}
}
}
/**
* Called before the controller's beforeFilter method.
*/
$this->executeCallbacks('initialize');
}
示例3: initialize
/**
* initialize method
*
* Merge settings and set Config.language to a valid locale
*
* @return void
* @access public
*/
function initialize(&$Controller, $config = array())
{
App::import('Vendor', 'Mi.MiCache');
$lang = MiCache::setting('Site.lang');
if (!$lang) {
if (!defined('DEFAULT_LANGUAGE')) {
return;
}
$lang = DEFAULT_LANGUAGE;
} elseif (!defined('DEFAULT_LANGUAGE')) {
define('DEFAULT_LANGUAGE', $lang);
}
Configure::write('Config.language', $lang);
App::import('Core', 'I18n');
$I18n =& I18n::getInstance();
$I18n->domain = 'default_' . $lang;
$I18n->__lang = $lang;
$I18n->l10n->get($lang);
if (!empty($Controller->plugin)) {
$config['plugins'][] = Inflector::underscore($Controller->plugin);
}
if (!empty($config['plugins'])) {
$plugins = array_intersect(MiCache::mi('plugins'), $config['plugins']);
$Inst = App::getInstance();
foreach ($plugins as $path => $name) {
$Inst->locales[] = $path . DS . 'locale' . DS;
}
}
}
示例4: index
/**
* Take care of any minifying requests.
* The import is not defined outside the class to avoid errors if the class is read from the console.
*
* @return void
*/
public function index($type)
{
$files = array_unique(explode(',', $_GET['f']));
$plugins = array();
$symLinks = array();
$newFiles = array();
if (!empty($this->request->base)) {
$symLinks['/' . $this->request->base] = WWW_ROOT;
}
foreach ($files as &$file) {
if (empty($file)) {
continue;
}
$plugin = false;
list($first, $second) = pluginSplit($file);
if (CakePlugin::loaded($first) === true) {
$file = $second;
$plugin = $first;
}
$pluginPath = !empty($plugin) ? '../Plugin/' . $plugin . '/' . WEBROOT_DIR . '/' : '';
$file = $pluginPath . $type . '/' . $file . '.' . $type;
$newFiles[] = $file;
if (!empty($plugin) && !isset($plugins[$plugin])) {
$plugins[$plugin] = true;
$symLinks['/' . $this->request->base . '/' . Inflector::underscore($plugin)] = APP . 'Plugin/' . $plugin . '/' . WEBROOT_DIR . '/';
}
}
$_GET['f'] = implode(',', $newFiles);
$_GET['symlinks'] = $symLinks;
App::import('Vendor', 'Minify.minify/index');
$this->response->statusCode('304');
exit;
}
示例5: __loadHooks
/**
* Load hooks as helpers
*
* @return void
*/
function __loadHooks()
{
if (Configure::read('Hook.helpers')) {
// Set hooks
$hooks = Configure::read('Hook.helpers');
$hooksE = explode(',', $hooks);
foreach ($hooksE as $hook) {
if (strstr($hook, '.')) {
$hookE = explode('.', $hook);
$plugin = $hookE['0'];
$hookHelper = $hookE['1'];
$filePath = APP . 'plugins' . DS . Inflector::underscore($plugin) . DS . 'views' . DS . 'helpers' . DS . Inflector::underscore($hookHelper) . '.php';
} else {
$plugin = null;
$filePath = APP . 'views' . DS . 'helpers' . DS . Inflector::underscore($hook) . '.php';
}
if (file_exists($filePath)) {
$this->hooks[] = $hook;
}
}
// Set hooks as helpers
foreach ($this->hooks as $hook) {
$this->helpers[] = $hook;
}
}
}
示例6: find
/**
* The vast majority of the custom find types actually follow the same format
* so there was little point explicitly writing them all out. Instead, if the
* method corresponding to the custom find type doesn't exist, the options are
* applied to the model's request property here and then we just call
* parent::find('all') to actually trigger the request and return the response
* from the API.
*
* In addition, if you try to fetch a timeline that supports paging, but you
* don't specify paging params, you really want all tweets in that timeline
* since time imemoriam. But twitter will only return a maximum of 200 per
* request. So, we make multiple calls to the API for 200 tweets at a go, for
* subsequent pages, then merge the results together before returning them.
*
* Twitter's API uses a count parameter where in CakePHP we'd normally use
* limit, so we also copy the limit value to count so we can use our familiar
* params.
*
* @param string $type
* @param array $options
* @return mixed
*/
public function find($type, $options = array())
{
if (!empty($options['limit']) && empty($options['count'])) {
$options['count'] = $options['limit'];
}
if ((empty($options['page']) || empty($options['count'])) && array_key_exists($type, $this->allowedFindOptions) && in_array('page', $this->allowedFindOptions[$type]) && in_array('count', $this->allowedFindOptions[$type])) {
$options['page'] = 1;
$options['count'] = 200;
$results = array();
while (($page = $this->find($type, $options)) != false) {
$results = array_merge($results, $page);
$options['page']++;
}
return $results;
}
if (method_exists($this, '_find' . Inflector::camelize($type))) {
return parent::find($type, $options);
}
$this->request['uri']['path'] = '1/statuses/' . Inflector::underscore($type);
if (array_key_exists($type, $this->allowedFindOptions)) {
$this->request['uri']['query'] = array_intersect_key($options, array_flip($this->allowedFindOptions[$type]));
}
if (in_array($type, $this->findMethodsRequiringAuth)) {
$this->request['auth'] = true;
}
return parent::find('all', $options);
}
示例7: call
/**
* MailchimpAppModel::call()
*
* @return mixed
*/
public function call($method, array $options = [])
{
$args = [];
foreach ($options as $key => $value) {
$args[Inflector::underscore($key)] = $value;
}
$this->response = $this->Mailchimp->call($method, $args);
if (!isset($this->response['status']) || $this->response['status'] !== 'error') {
return $this->response;
}
if ($this->settings['exceptions']) {
$errorMsg = "Unknown error";
$errorCode = null;
$errorName = null;
if (isset($this->response['error'])) {
$errorMsg = $this->response['error'];
}
if (isset($this->response['code'])) {
$errorCode = $this->response['code'];
}
if (isset($this->response['name'])) {
$errorName = $this->response['name'];
}
throw new MailchimpException($errorMsg, $errorCode, $errorName);
}
return false;
}
示例8: changeStatus
public function changeStatus(Model $Model, $status, $id = null, $force = false)
{
if ($id === null) {
$id = $Model->getID();
}
if ($id === false) {
return false;
}
$force = true;
$Model->id = $id;
if (!$Model->exists()) {
throw new NotFoundException();
}
if ($force !== true) {
$modelData = $Model->read();
if ($modelData[$Model->alias]['status'] === $status) {
CakeLog::write(LOG_WARNING, __d('webshop', 'The status of %1$s with id %2$d is already set to %3$s. Not making a change', strtolower(Inflector::humanize(Inflector::underscore($Model->name))), $id, $status), array('webshop'));
return false;
}
} else {
CakeLog::write(LOG_WARNING, __d('webshop', 'Status change of %1$s with id %2$d is being forced to %3$s', strtolower(Inflector::humanize(Inflector::underscore($Model->name))), $id, $status), array('webshop'));
}
$Model->saveField('status', $status);
CakeLog::write(LOG_INFO, __d('webshop', 'Changed status of %1$s with id %2$d to %3$s', strtolower(Inflector::humanize(Inflector::underscore($Model->name))), $id, $status), array('webshop'));
$eventData = array();
$eventData[Inflector::underscore($Model->name)]['id'] = $id;
$eventData[Inflector::underscore($Model->name)]['status'] = $status;
$overallEvent = new CakeEvent($Model->name . '.statusChanged', $this, $eventData);
$specificEvent = new CakeEvent($Model->name . '.statusChangedTo' . Inflector::camelize($status), $this, $eventData);
CakeEventManager::instance()->dispatch($overallEvent);
CakeEventManager::instance()->dispatch($specificEvent);
return true;
}
示例9: init
/**
* Initializes the pager. Must be called before using the component.
*
* Takes user configuration and creates pager object ($this->Pager)
*
* @access public
* @param array $config Configuration options for Pager::factory() method
* @see http://pear.php.net/manual/en/package.html.pager.factory.php
* @return void
*/
function init($config)
{
// Get the correct URL, even with admin routes
$here = array();
if (defined('CAKE_ADMIN') && !empty($this->Controller->params[CAKE_ADMIN])) {
$here[0] = $this->Controller->params[CAKE_ADMIN];
$here[2] = substr($this->Controller->params['action'], strlen($this->Controller->params[CAKE_ADMIN]) + 1);
} else {
$here[2] = $this->Controller->params['action'];
}
$here[1] = Inflector::underscore($this->Controller->params['controller']);
ksort($here);
$url = implode('/', $here);
// Set up the default configuration vars
$this->params = array('mode' => 'Sliding', 'perPage' => 10, 'delta' => 5, 'totalItems' => '', 'httpMethod' => 'GET', 'currentPage' => 1, 'linkClass' => 'pager', 'altFirst' => 'First page', 'altPrev ' => 'Previous page', 'altNext' => 'Next page', 'altLast' => 'Last page', 'separator' => '', 'spacesBeforeSeparator' => 1, 'spacesAfterSeparator' => 1, 'useSessions' => false, 'firstPagePre' => '', 'firstPagePost' => '', 'firstPageText' => '<img src="' . $this->Controller->base . '/img/first.gif" alt="">', 'lastPagePre' => '', 'lastPagePost' => '', 'lastPageText' => '<img src="' . $this->Controller->base . '/img/last.gif" alt="">', 'prevImg' => '<img src="' . $this->Controller->base . '/img/prev.gif" alt="">', 'nextImg' => '<img src="' . $this->Controller->base . '/img/next.gif" alt="">', 'altPage' => 'Page', 'clearIfVoid' => true, 'append' => false, 'path' => '', 'fileName' => $this->Controller->base . DS . $url . DS . '%d', 'urlVar' => '');
vendor('Pear/Pager/Pager');
// Merge with user config
$this->params = array_merge($this->params, $config);
// sanitize requested page number
if (!in_array($this->params['currentPage'], range(1, ceil($this->params['totalItems'] / $this->params['perPage'])))) {
$this->params['currentPage'] = 1;
}
$this->Pager =& Pager::factory($this->params);
// Set the template vars
$this->Controller->set('pageLinks', $this->Pager->getLinks());
$this->Controller->set('currentPage', $this->params['currentPage']);
$this->Controller->set('isFirstPage', $this->Pager->isFirstPage());
$this->Controller->set('isLastPage', $this->Pager->isLastPage());
}
示例10: beforeRender
/**
* beforeRender callback
*
* @return void
* @access public
*/
public function beforeRender()
{
parent::beforeRender();
$this->Jquery->uses('jquery', 'ui', 'potato.menu');
$this->_categoryModel = $this->params['menu']['model'];
$this->_categoryController = Inflector::underscore(Inflector::pluralize($this->_categoryModel));
}
示例11: input
/**
* This function inserts CK Editor for a form input
*
* @param string $input The name of the field, can be field_name or Model.field_name
* @param array $options Options include $options['label'] for a custom label - this can be expanded on if required
*/
public function input($input, $options = array())
{
echo $this->Html->script('//cdn.ckeditor.com/4.4.5.1/standard/ckeditor.js');
$input = explode('.', $input);
if (empty($input[1])) {
$field = $input[0];
$model = $this->Form->model();
} else {
$model = $input[0];
$field = $input[1];
}
if (!empty($options['label'])) {
echo '<label>' . $options['label'] . '</label>';
} else {
echo '<label>' . Inflector::humanize(Inflector::underscore($field)) . '</label>';
}
echo $this->Form->error($model . '.' . $field);
echo $this->Form->input($model . '.' . $field, array('type' => 'textarea', 'label' => false, 'error' => false, 'required' => false));
?>
<script type="text/javascript">
CKEDITOR.replace('<?php
echo Inflector::camelize($model . '_' . $field);
?>
', { customConfig: '<?php
echo $this->Html->url('/pages/ckeditor');
?>
' });
</script>
<p> </p>
<?php
}
示例12: translations
public function translations()
{
$models = array_diff(App::objects('model'), array('AppModel'));
$translations = array();
$out = "<?php ";
foreach ($models as $model) {
$Model = ClassRegistry::init($model);
$translations[Inflector::humanize(Inflector::underscore($Model->name))] = true;
$translations[$Model->brwConfig['names']['singular']] = true;
$translations[$Model->brwConfig['names']['plural']] = true;
$schema = (array) $Model->schema();
foreach ($schema as $key => $value) {
$translations[Inflector::humanize(str_replace('_id', '', $key))] = true;
}
foreach ($Model->brwConfig['custom_actions'] as $action => $config) {
$translations[$config['title']] = true;
if ($config['confirmMessage']) {
$translations[$config['confirmMessage']] = true;
}
}
}
$translations = array_keys($translations);
foreach ($translations as $translation) {
$out .= "__('" . $translation . "');\n";
}
$forTranslate = ROOT . DS . APP_DIR . DS . 'View' . DS . 'Elements' . DS . '4translate.php';
fwrite(fopen($forTranslate, 'w'), $out);
}
示例13: beforeFind
/**
* beforeFind can be used to cancel find operations, or modify the query that will be executed.
* By returning null/false you can abort a find. By returning an array you can modify/replace the query
* that is going to be run.
*
* @param Model $model Model using this behavior
* @param array $query Data used to execute this query, i.e. conditions, order, etc.
* @return bool|array False or null will abort the operation. You can return an array to replace the
* $query that will be eventually run.
*/
public function beforeFind(Model $model, $query)
{
$model->Like = ClassRegistry::init('Likes.Like');
$model->LikesUser = ClassRegistry::init('Likes.LikesUser');
$conditions = $query['conditions'];
if (is_array($query['conditions']) === false) {
return $query;
}
$columns = array();
if (!isset($query['fields'])) {
$columns = 'Like.*';
} else {
$columns = $query['fields'];
}
$columns = Hash::merge((array) $columns, array_keys($conditions));
// Like條件あったらJOIN
if (!preg_grep('/^Like\\./', $columns) && !preg_grep('/^LikesUser\\./', $columns)) {
return $query;
}
if (!isset($query['fields'])) {
$query['fields'] = '*';
}
$query['joins'][] = array('table' => $model->Like->table, 'alias' => $model->Like->alias, 'type' => 'LEFT', 'conditions' => array('Like.plugin_key' => Inflector::underscore($model->plugin), $this->__model . '.' . $this->__field . ' = ' . 'Like.content_key'));
$likesUserConditions = array('Like.id = LikesUser.like_id');
if (Current::read('User.id')) {
$likesUserConditions['LikesUser.user_id'] = Current::read('User.id');
} else {
$likesUserConditions['LikesUser.session_key'] = CakeSession::id();
}
$query['joins'][] = array('table' => $model->LikesUser->table, 'alias' => $model->LikesUser->alias, 'type' => 'LEFT', 'conditions' => $likesUserConditions);
return $query;
}
示例14: _assign
protected function _assign($model)
{
if ($this->getRequest()->isHead()) {
Zend_Controller_Action_HelperBroker::getExistingHelper('viewRenderer')->setNoRender(true);
return;
}
$request = $this->getRequest();
$this->_setEtag($model->etag($this->_context));
$modelName = $model instanceof Bbx_Model ? Inflector::underscore(get_class($model)) : Inflector::tableize($model->getModelName());
if ($request->getParam('list') === 'true') {
$model->renderAsList();
}
if ($this->_context === 'csv') {
$this->_helper->authenticate();
}
if ($request->getParam('download') == 'true') {
$this->_helper->authenticate();
$this->_helper->download($model);
}
if ($this->_context === 'json') {
$options = $this->_context === 'json' ? array('deep' => true) : null;
$this->view->assign($model->toArray($options));
} else {
$this->view->{$modelName} = $model;
}
}
示例15: render
/**
* Render the current view.
*
* @return void
**/
public function render()
{
$registry = Components\Registry::instance();
$plugins = $registry->plugins;
$vars = $registry->get_view_vars();
$vars['current_controller'] = $registry->controller;
$vars['current_action'] = $registry->action;
include_once 'application_helper.php';
$helper_classes = array();
$helper_names = array();
foreach (glob(VALET_ROOT . "/core/libs/helpers/*.php") as $file) {
$class = str_replace(".php", "", basename($file));
$class = \Inflector::camelize($class);
include_once $file;
$helper_names[] = $class;
}
$helper_names[] = "ApplicationHelper";
$controller_helper = $registry->helper();
if (@(include_once \Inflector::underscore($controller_helper))) {
$helper_names[] = $controller_helper;
}
foreach ($helper_names as $class) {
$helper = new $class();
foreach (get_class_methods($helper) as $method) {
if (substr($method, 0, 1) != '_') {
$helper_classes[$method] = $helper;
}
}
}
if (!$this->_find_view($registry->view)) {
throw new \Error("The view '" . $registry->view . "' could not be found.");
}
$file = new File($registry->view . ".phtml", $vars, $helper_classes);
print $file;
}