本文整理匯總了PHP中Inflector類的典型用法代碼示例。如果您正苦於以下問題:PHP Inflector類的具體用法?PHP Inflector怎麽用?PHP Inflector使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。
在下文中一共展示了Inflector類的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的PHP代碼示例。
示例1: init
/**
* Initialize the Cache Engine
*
* Called automatically by the cache frontend
* To reinitialize the settings call Cache::engine('EngineName', [optional] settings = array());
*
* @param array $settings array of setting for the engine
* @return boolean True if the engine has been successfully initialized, false if not
*/
public function init($settings = array())
{
if (!class_exists('Memcache')) {
return false;
}
if (!isset($settings['prefix'])) {
$settings['prefix'] = Inflector::slug(APP_DIR) . '_';
}
$settings += array('engine' => 'Memcache', 'servers' => array('127.0.0.1'), 'compress' => false, 'persistent' => true);
parent::init($settings);
if ($this->settings['compress']) {
$this->settings['compress'] = MEMCACHE_COMPRESSED;
}
if (is_string($this->settings['servers'])) {
$this->settings['servers'] = array($this->settings['servers']);
}
if (!isset($this->_Memcache)) {
$return = false;
$this->_Memcache = new Memcache();
foreach ($this->settings['servers'] as $server) {
list($host, $port) = $this->_parseServerString($server);
if ($this->_Memcache->addServer($host, $port, $this->settings['persistent'])) {
$return = true;
}
}
return $return;
}
return true;
}
示例2: display
/**
* Displays a view
*
* @param mixed What page to display
* @return void
* @throws NotFoundException When the view file could not be found
* or MissingViewException in debug mode.
*/
public function display()
{
$path = func_get_args();
//debug($path);
$count = count($path);
//debug($count);
if (!$count) {
return $this->redirect('/');
}
$page = $subpage = $title_for_layout = null;
//debug(Inflector::humanize($path[$count - 1]));
if (!empty($path[0])) {
$page = $path[0];
}
if (!empty($path[1])) {
$subpage = $path[1];
}
if (!empty($path[$count - 1])) {
$title_for_layout = Inflector::humanize($path[$count - 1]);
}
$this->set(compact('page', 'subpage', 'title_for_layout'));
//debug($this->render(implode('/', $path)));
//debug($page);
//debug($subpage);
//debug($title_for_layout);
try {
$this->render(implode('/', $path));
} catch (MissingViewException $e) {
if (Configure::read('debug')) {
throw $e;
}
throw new NotFoundException();
}
}
示例3: smarty_function_header
function smarty_function_header($params, &$smarty)
{
$self = $smarty->getTemplateVars('self');
$theme = $smarty->getTemplateVars('theme');
$title = $smarty->getTemplateVars('page_title');
$inflector = new Inflector();
$item_name = prettify($inflector->singularize($smarty->getTemplateVars('controller')));
if (empty($title) || $title === 'Index') {
switch ($smarty->getTemplateVars('action')) {
case 'view':
$title = $item_name . ' Details';
break;
case 'edit':
$title = 'Editing ' . $item_name . ' Details';
break;
case 'new':
$title = 'Create new ' . $item_name;
break;
case 'index':
default:
$title = $item_name;
break;
}
}
return '<h1 class="page_title">' . $title . '</h1>';
}
示例4: ize
/**
* undocumented function
*
* @param string $string
* @param string $count
* @param string $showCount
* @return void
* @access public
*/
function ize($string, $count, $showCount = true)
{
if ($count != 1) {
$inflect = new Inflector();
return ($showCount ? $count . ' ' : '') . $inflect->pluralize($string);
}
return ($showCount ? $count . ' ' : '') . $string;
}
示例5: find
public static function find($value, $columnName = 'id')
{
$reflector = new \ReflectionClass(get_called_class());
$inflector = new Inflector();
$tableName = $inflector->tableize($reflector->getName());
$stmt = self::$_connection->prepare("SELECT * FROM " . $tableName . " WHERE `" . $columnName . "` = :Value");
$stmt->bindParam('Value', $value);
$stmt->execute();
$data = $stmt->fetch(\PDO::FETCH_ASSOC);
return $data;
}
示例6: season
function season($indoor)
{
// The configuration settings values have "0" for the year, to facilitate form input
$today = date('0-m-d');
$today_wrap = date('1-m-d');
// Build the list of applicable seasons
$seasons = Configure::read('options.season');
unset($seasons['None']);
if (empty($seasons)) {
return 'None';
}
foreach (array_keys($seasons) as $season) {
$season_indoor = Configure::read("season_is_indoor.{$season}");
if ($indoor != $season_indoor) {
unset($seasons[$season]);
}
}
// Create array of which season follows which
$seasons = array_values($seasons);
$seasons_shift = $seasons;
array_push($seasons_shift, array_shift($seasons_shift));
$next = array_combine($seasons, $seasons_shift);
// Look for the season that has started without the next one starting
foreach ($next as $a => $b) {
$start = Configure::read('organization.' . Inflector::slug(low($a)) . '_start');
$end = Configure::read('organization.' . Inflector::slug(low($b)) . '_start');
// Check for a season that wraps past the end of the year
if ($start > $end) {
$end[0] = '1';
}
if ($today >= $start && $today < $end || $today_wrap >= $start && $today_wrap < $end) {
return $a;
}
}
}
示例7: multiCall
/**
* Creates and issue multi call to magento api
*/
public function multiCall($calls)
{
$model = Inflector::underscore($this->name);
$request = array($this->_getSession(), $calls);
$results = $this->query('multiCall', $request);
return $results;
}
示例8: 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);
}
示例9: mapResources
public static function mapResources($controller = array(), $options = array())
{
$hasPrefix = isset($options['prefix']);
$options = array_merge(array('prefix' => '/', 'id' => self::ID . '|' . self::UUID), $options);
$prefix = $options['prefix'];
foreach ((array) $controller as $name) {
list($plugin, $name) = pluginSplit($name);
$urlName = Inflector::underscore($name);
$plugin = Inflector::underscore($plugin);
if ($plugin && !$hasPrefix) {
$prefix = '/' . $plugin . '/';
}
foreach (self::$_resourceMap as $params) {
if ($params['action'] === 'count') {
$url = $prefix . $urlName . '/count';
} else {
$url = $prefix . $urlName . ($params['id'] ? '/:id' : '');
}
if (!empty($options['controllerClass'])) {
$controller = $options['controllerClass'];
} else {
$controller = $urlName;
}
Router::connect($url, array('plugin' => $plugin, 'controller' => $controller, 'action' => $params['action'], '[method]' => $params['method']), array('id' => $options['id'], 'pass' => array('id')));
}
self::$_resourceMapped[] = $urlName;
}
return self::$_resourceMapped;
}
示例10: main
/**
* main
*
* @return void
*/
public function main()
{
$model = $this->in('Model name:');
$controller = Inflector::pluralize($model);
$controllerActions = $this->in('Do you want to bake the controller with admin prefix: yes/no', 'y/n', 'n');
$usePlugin = $this->in("Do you want to bake in plugin: yes/no", 'y/n', 'n');
if ($usePlugin == 'y') {
$pluginName = $this->in('Name of your plugin:', null, '');
if ($pluginName == '') {
$usePlugin = 'n';
}
}
if ($controllerActions == 'y') {
$controllerActions = '--admin';
} else {
$controllerActions = '--public';
}
$theme = 'fuelux';
$modelCommand = "ajax_template.ext_bake model {$model}";
$controllerCommand = "ajax_template.ext_bake controller {$controller} {$controllerActions}";
$viewCommand = "ajax_template.ext_bake view {$controller}";
$postfix = " --theme {$theme}";
if ($usePlugin == 'y') {
$postfix .= " --plugin {$pluginName}";
}
$this->dispatchShell($modelCommand . $postfix);
$this->dispatchShell($controllerCommand . $postfix);
$this->dispatchShell($viewCommand . $postfix);
}
示例11: 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);
}
示例12: display
/**
* Displays a view
*
* @param mixed What page to display
* @return void
*/
public function display() {
$path = func_get_args();
$count = count($path);
if (!$count) {
$this->redirect('/');
}
$page = $subpage = $titleForLayout = null;
if (!empty($path[0])) {
$page = $path[0];
}
if (!empty($path[1])) {
$subpage = $path[1];
}
if (!empty($path[$count - 1])) {
$titleForLayout = Inflector::humanize($path[$count - 1]);
}
$this->set(array(
'page' => $page,
'subpage' => $subpage,
'title_for_layout' => $titleForLayout
));
$this->render(implode('/', $path));
}
示例13: display
public function display()
{
$path = func_get_args();
$count = count($path);
if (!$count) {
$this->redirect('/');
}
$page = $subpage = $title_for_layout = null;
if (!empty($path[0])) {
$page = $path[0];
}
if (!empty($path[1])) {
$subpage = $path[1];
}
if (!empty($path[$count - 1])) {
$title_for_layout = Inflector::humanize($path[$count - 1]);
}
$this->loadModel('Category');
//$cats = $this->Category->find('list', array('order'=> array('Category.cat_name' => 'ASC')));
$cats = $this->Category->find('list');
// print_r($cats);
$posts = array();
$index = 1;
foreach ($cats as $key => $value) {
$this->loadModel('Post');
$threads = $this->Post->find('threaded', array('fields' => array('post_id', 'Category.cat_name', 'Topic.topic_subject', 'parent_id'), 'conditions' => array('Category.cat_name' => $value, 'Topic.topic_cat' => $key)));
$posts[$index]['Category'] = $value;
$posts[$index]['Threads'] = $threads;
$index++;
}
$this->set('posts', $posts);
$this->set(compact('page', 'subpage', 'title_for_layout'));
$this->render(implode('/', $path));
}
示例14: beforeSave
public function beforeSave($options = array())
{
if (isset($this->data[$this->alias]['slug']) && empty($this->data[$this->alias]['slug'])) {
$this->data[$this->alias]['slug'] = strtolower(Inflector::slug($this->data[$this->alias]['title'], '-'));
}
return parent::beforeSave($options);
}
示例15: home
/**
* Displays a view
*
* @return void
* @throws NotFoundException When the view file could not be found
* or MissingViewException in debug mode.
*/
public function home()
{
// Redirect to tasks page
Router::redirect('*', array('controller' => 'tasks', 'action' => 'index'));
$path = func_get_args();
$count = count($path);
if (!$count) {
return $this->redirect('/');
}
$page = $subpage = $title_for_layout = null;
if (!empty($path[0])) {
$page = $path[0];
}
if (!empty($path[1])) {
$subpage = $path[1];
}
if (!empty($path[$count - 1])) {
$title_for_layout = Inflector::humanize($path[$count - 1]);
}
$this->set(compact('page', 'subpage', 'title_for_layout'));
try {
$this->render(implode('/', $path));
} catch (MissingViewException $e) {
if (Configure::read('debug')) {
throw $e;
}
throw new NotFoundException();
}
}