本文整理匯總了PHP中Inflector::friendly_title方法的典型用法代碼示例。如果您正苦於以下問題:PHP Inflector::friendly_title方法的具體用法?PHP Inflector::friendly_title怎麽用?PHP Inflector::friendly_title使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類Inflector
的用法示例。
在下文中一共展示了Inflector::friendly_title方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的PHP代碼示例。
示例1: get_user_info
public function get_user_info(Token_Access $token)
{
$url = 'https://identity.x.com/xidentity/resources/profile/me?' . http_build_query(array('oauth_token' => $token->access_token));
$user = json_decode(file_get_contents($url));
$user = $user->identity;
return array('uid' => $user['userId'], 'nickname' => \Inflector::friendly_title($user['fullName'], '_', true), 'name' => $user['fullName'], 'first_name' => $user['firstName'], 'last_name' => $user['lastName'], 'email' => $user['emails'][0], 'location' => $user->addresses[0], 'image' => null, 'description' => null, 'urls' => array('PayPal' => null));
}
示例2: initialSetup
/**
* Sets site specific stuff for admin,
* @param array $settings Settings to enter into config
* @return bool success or fail
*/
public static function initialSetup($title = null, $identifier = null)
{
static::ensureMinimumSetup();
if (\Fuel::$is_cli) {
while (empty($title)) {
$title = \Cli::prompt('Website Title');
if (empty($title)) {
\Cli::error('You must enter a site title');
}
}
while (empty($identifier)) {
$identifier = \Cli::prompt('Unique Identifier', str_replace('_', '', \Inflector::friendly_title($title, '_', true)));
if (empty($identifier)) {
\Cli::error('You must enter a unique identifier for this site');
}
}
}
$config_path = APPPATH . 'config/cmf.php';
$db_config_path = APPPATH . 'config/db.php';
$config = \Config::load($config_path, false, true);
$db_config = \Config::load($db_config_path, false, true);
$config['install'] = false;
$config['admin']['title'] = $title;
$db_config['doctrine2']['cache_namespace'] = $identifier;
if ($config_saved = \Config::save($config_path, $config)) {
\Config::load('cmf', true, true);
}
if ($db_config_saved = \Config::save($db_config_path, $db_config)) {
\Config::load('db', true, true);
}
static::cleanUpConfig($config_path);
static::cleanUpConfig($db_config_path);
return $config_saved && $db_config_saved;
}
示例3: displayForm
public static function displayForm($value, &$settings, $model)
{
$settings = static::settings($settings);
if (!is_array($value)) {
$value = array();
}
// Search input or
$searchInput = \Form::input($settings['mapping']['fieldName'] . '[search]', null, array('class' => 'input input-xxlarge search-input', 'placeholder' => \Lang::get('admin.common.map_search_placeholder')));
$searchButton = \Form::button('mapsearch', \Lang::get('admin.verbs.search'), array('class' => 'btn btn-primary'));
$searchInput = html_tag('div', array('class' => 'form form-inline search-form'), $searchInput . $searchButton);
// Hidden inputs
$latInput = \Form::hidden($settings['mapping']['fieldName'] . '[lat]', \Arr::get($value, 'lat'), array('class' => 'lat'));
$lngInput = \Form::hidden($settings['mapping']['fieldName'] . '[lng]', \Arr::get($value, 'lng'), array('class' => 'lng'));
$zoomInput = \Form::hidden($settings['mapping']['fieldName'] . '[zoom]', \Arr::get($value, 'zoom'), array('class' => 'zoom'));
// Other elements
$required = isset($settings['required']) ? $settings['required'] : false;
$label_text = $settings['title'] . ($required ? ' *' : '');
$label = \Form::label($label_text);
$mapDiv = html_tag('div', array('class' => 'map', 'id' => \Inflector::friendly_title($settings['mapping']['fieldName'], '-', true) . '-bing-map'), ' ');
// Check that we have an API key
if (empty($settings['api_key'])) {
$content = $label . '<div class="well"><p>' . \Lang::get('admin.bing.api_key_not_set') . '</p></div>';
} else {
$content = $label . $searchInput . $latInput . $lngInput . $zoomInput . $mapDiv;
}
$content = html_tag('div', array('class' => 'controls control-group field-type-bing-map', 'data-field-name' => $settings['mapping']['fieldName']), $content);
return array('content' => $content, 'js_data' => $settings);
}
示例4: get_user_info
public function get_user_info(Token_Access $token)
{
// define the get user information token
$url = 'https://apis.live.net/v5.0/me?' . http_build_query(array('access_token' => $token->access_token));
// perform network request
$user = json_decode(file_get_contents($url));
// create a response from the request and return it
return array('uid' => $user->id, 'name' => $user->name, 'email' => isset($user->emails->preferred) ? $user->emails->preferred : null, 'nickname' => \Inflector::friendly_title($user->name, '-', true), 'locale' => $user->locale, 'urls' => array('Windows Live' => $user->link));
}
示例5: action_add
public function action_add($id = null)
{
$this->data['isUpdate'] = $isUpdate = $id !== null ? true : false;
// Prepare form fieldset
$form = \Fieldset::forge('category_form', array('form_attributes' => array('class' => 'form-horizontal special')));
$form->add_model('Blog\\Model_Category');
$form->add('add', '', array('type' => 'submit', 'value' => $isUpdate ? __('backend.edit') : __('backend.add'), 'class' => 'btn btn-primary'));
// Get or create the post
if ($isUpdate) {
$this->data['category'] = $category = Model_Category::find($id);
$this->dataGlobal['pageTitle'] = __('backend.category.edit');
} else {
$this->data['category'] = $category = Model_Category::forge();
$this->dataGlobal['pageTitle'] = __('backend.category.add');
}
$form->populate($category);
// If POST submit
if (\Input::post('add')) {
$form->validation()->run();
if (!$form->validation()->error()) {
// Populate the category
$category->from_array(array('name' => $form->validated('name'), 'slug' => $form->validated('slug') != '' ? \Inflector::friendly_title($form->validated('slug'), '-', true) : \Inflector::friendly_title($form->validated('name'), '-', true), 'parent_id' => $form->validated('parent_id')));
if ($category->save()) {
// Delete cache
\Cache::delete('sidebar');
// Category Post count update
foreach (Model_Category::find('all') as $category) {
$category->post_count = count($category->posts);
$category->save();
}
if ($isUpdate) {
// \Messages::success(__('backend.category.edited'));
\Session::set_flash('success', __('backend.category.edited'));
} else {
// \Messages::success(__('backend.category.added'));
\Session::set_flash('success', __('backend.category.added'));
}
\Response::redirect_back(\Router::get('admin_category'));
} else {
// \Messages::error(__('error'));
\Session::set_flash('error', __('error'));
}
} else {
// Output validation errors
foreach ($form->validation()->error() as $error) {
echo $error;
// \Messages::error($error);
\Session::set_flash('error', $error);
}
}
}
$form->repopulate();
$this->data['form'] = $form;
return \Response::forge(\View::forge('backend/category/add')->set($this->data, null, false));
}
示例6: before_update
/**
* Creates a new unique slug and update the object
*
* @param Model The object
* @return void
*/
public function before_update(Model $obj)
{
// determine the slug
$properties = (array) $this->_source;
$source = '';
foreach ($properties as $property) {
$source .= '-' . $obj->{$property};
}
$slug = \Inflector::friendly_title(substr($source, 1), '-', true);
// update it if it's different from the current one
$obj->{$this->_property} === $slug or $this->before_insert($obj);
}
示例7: get_user_info
public function get_user_info(OAuth_Consumer $consumer, OAuth_Token $token)
{
// Create a new GET request with the required parameters
$request = Request::forge('resource', 'GET', 'https://www.google.com/m8/feeds/contacts/default/full?max-results=1&alt=json', array('oauth_consumer_key' => $consumer->key, 'oauth_token' => $token->access_token));
// Sign the request using the consumer and token
$request->sign($this->signature, $consumer, $token);
$response = json_decode($request->execute(), true);
// Fetch data parts
$email = \Arr::get($response, 'feed.id.$t');
$name = \Arr::get($response, 'feed.author.0.name.$t');
$name == '(unknown)' and $name = $email;
return array('uid' => $email, 'nickname' => \Inflector::friendly_title($name), 'name' => $name, 'email' => $email, 'location' => null, 'image' => null, 'description' => null, 'urls' => array());
}
示例8: action_add
public function action_add($id = null)
{
$this->data['isUpdate'] = $isUpdate = $id !== null ? true : false;
// Prepare form fieldset
$form = \Fieldset::forge('post_form', array('form_attributes' => array('class' => 'form-horizontal')));
$form->add_model('Model_Post');
$form->add('add', '', array('type' => 'submit', 'value' => $isUpdate ? __('backend.edit') : __('backend.add'), 'class' => 'btn btn-primary'));
// Get or create the post
if ($isUpdate) {
$this->data['post'] = $post = \Model_Post::find($id);
$this->dataGlobal['pageTitle'] = __('backend.post.edit');
} else {
$this->data['post'] = $post = \Model_Post::forge();
$this->dataGlobal['pageTitle'] = __('backend.post.add');
}
$form->populate($post);
// If POST submit
if (\Input::post('add')) {
$form->validation()->run();
if (!$form->validation()->error()) {
// Populate the post
$post->from_array(array('name' => $form->validated('name'), 'slug' => $form->validated('slug') != '' ? \Inflector::friendly_title($form->validated('slug')) : \Inflector::friendly_title($form->validated('name')), 'category_id' => $form->validated('category_id'), 'user_id' => $form->validated('user_id'), 'content' => $form->validated('content')));
if ($post->save()) {
// Delete cache
\Cache::delete('sidebar');
// Category Post count update
foreach (\Model_Category::find('all') as $category) {
$category->post_count = count($category->posts);
$category->save();
}
if ($isUpdate) {
\Messages::success(__('backend.post.edited'));
} else {
\Messages::success(__('backend.post.added'));
}
\Response::redirect_back(\Router::get('admin_post'));
} else {
\Messages::error(__('error'));
}
} else {
// Output validation errors
foreach ($form->validation()->error() as $error) {
\Messages::error($error);
}
}
}
$form->repopulate();
$this->data['form'] = $form;
$this->theme->set_partial('content', 'backend/post/add')->set($this->data, null, false);
}
示例9: sellers
/**
* Generates sellers.
*
* @return void
*/
protected static function sellers()
{
$date = date("Y-m-d H:i:s", self::BEGIN_DATETIME);
$companies = array('Stella Labs, Inc', 'Star Point Industries');
foreach ($companies as $company) {
$seller = \Service_Seller::create($company, array('contact' => array('company_name' => $company, 'email' => 'support@' . \Inflector::friendly_title($company) . '.com', 'address' => mt_rand(1, 5000) . ' Quail Springs Pkwy', 'city' => 'Oklahoma City', 'state' => 'Oklahoma', 'zip' => mt_rand(10000, 99999), 'country' => 'US'), 'created_at' => $date));
if ($seller) {
self::$sellers[] = $seller;
// Link the seller to the gateway.
\Service_Gateway::link(self::$gateway, $seller);
}
}
\Cli::write('Seller Simulation Complete', 'green');
}
示例10: _get_slug
protected function _get_slug()
{
$slug = \Inflector::friendly_title($this->name, '_', true);
$same = $this->query()->where('slug', 'LIKE', $slug . '%')->where('enum_id', $this->enum_id)->get();
// make sure our slug is unique
if (!empty($same)) {
$max = -1;
foreach ($same as $record) {
if (preg_match('/^' . $slug . '(?:_([0-9]+))?$/', $record->slug, $matches)) {
$index = isset($matches[1]) ? (int) $matches[1] : 0;
$max < $index and $max = $index;
}
}
$max < 0 or $slug .= '_' . ($max + 1);
}
return $slug;
}
示例11: findOne
public static function findOne($username)
{
$collection = MongoConnection::instance()->collection('owners');
$user = $collection->findOne(function ($query) use($username) {
/** @var \League\Monga\Query\Find $query */
$query->where('_id', $username);
});
$petResult = MongoConnection::instance()->collection('pets')->find(function ($query) use($user) {
/** @var \League\Monga\Query\Find $query */
$query->andWhereIn('_id', $user['pets']);
});
$pets = [];
foreach ($petResult as $pet) {
$petInfo = $pet;
$petInfo['name_slug'] = \Inflector::friendly_title($pet['name']);
$pets[] = $petInfo;
}
$user['pets'] = $pets;
return $user;
}
示例12: before_insert
/**
* Creates a unique slug and adds it to the object
*
* @param Model The object
* @return void
*/
public function before_insert(Model $obj)
{
$properties = (array) $this->_source;
$source = '';
foreach ($properties as $property) {
$source .= '-' . $obj->{$property};
}
$slug = \Inflector::friendly_title(substr($source, 1), '-', true);
$same = $obj->query()->where($this->_property, 'like', $slug . '%')->get();
if (!empty($same)) {
$max = -1;
foreach ($same as $record) {
if (preg_match('/^' . $slug . '(?:-([0-9]+))?$/', $record->{$this->_property}, $matches)) {
$index = isset($matches[1]) ? (int) $matches[1] : 0;
$max < $index and $max = $index;
}
}
$max < 0 or $slug .= '-' . ($max + 1);
}
$obj->{$this->_property} = $slug;
}
示例13: get
public function get()
{
if ($this->video_id) {
try {
// If value exists in cache ve just return it
$content = \Cache::get(\Inflector::friendly_title($this->video_id));
return $content;
} catch (\CacheNotFoundException $e) {
// Value not in cache
$request = \App\Curl::forge();
$request->cUrl(false);
$response = $request->get($this->url['first_part'] . $this->video_id . $this->url['second_part']);
if ($array = $request->is_json($response, true)) {
$return = array('id' => $this->video_id, 'link' => $array->entry->link[0]->href, 'title' => $array->entry->title->{'$t'}, 'description' => $array->entry->{'media$group'}->{'media$description'}->{'$t'}, 'duration' => $array->entry->{'media$group'}->{'media$content'}[0]->duration, 'thumbnail' => array('small' => $array->entry->{'media$group'}->{'media$thumbnail'}[0]->url, 'middle' => $array->entry->{'media$group'}->{'media$thumbnail'}[1]->url, 'large' => $array->entry->{'media$group'}->{'media$thumbnail'}[2]->url));
// Save value in cache for future use
\Cache::set(\Inflector::friendly_title($this->video_id), $return, 3600 * 24);
return $return;
}
}
}
return false;
}
示例14: action_create
public function action_create($id = null)
{
if (Input::method() == 'POST') {
$val = Model_Post::validate('create');
if ($val->run()) {
$post = Model_Post::forge(array('title' => Input::post('title'), 'slug' => Inflector::friendly_title(Input::post('title'), '-', true), 'summary' => Input::post('summary'), 'body' => Input::post('body'), 'user_id' => Input::post('user_id')));
if ($post and $post->save()) {
Session::set_flash('success', 'Added post #' . $post->id . '.');
Response::redirect('admin/posts');
} else {
Session::set_flash('error', 'Could not save post.');
}
} else {
Session::set_flash('error', $val->show_errors());
}
}
$this->template->title = "Create Post";
$view = View::forge('admin/posts/create');
// Set some data
$view->set_global('users', Arr::assoc_to_keyval(Model_User::find('all'), 'id', 'username'));
$this->template->content = $view;
}
示例15: action_base64_encode_image
public function action_base64_encode_image()
{
if ($_POST) {
$asciiFormat = Inflector::ascii(Input::post('filename'));
$webSafeName = Inflector::friendly_title($asciiFormat, '_', true);
$uploadLocation = 'assets/img/upload/';
$config = array('auto_process' => 'false', 'path' => DOCROOT . $uploadLocation, 'ext_whitelist' => array('img', 'jpg', 'jpeg', 'gif', 'png'), 'new_name' => $webSafeName, 'normalize' => true, 'change_case' => 'lower', 'auto_rename' => false, 'overwrite' => true);
// process the uploaded files in $_FILES
Upload::process($config);
// if there are any valid files
if (Upload::is_valid()) {
// save them according to the config
Upload::save();
// Grab the file extension
$uploadedFile = Upload::get_files(0);
$filename = $webSafeName . '.' . $uploadedFile['extension'];
$input_file = $uploadedFile['saved_to'] . $uploadedFile['saved_as'];
$image64Encoded = $this->_base64_encode_image($input_file, $uploadedFile['extension']);
$asset = Model_Asset::forge(array('name' => $uploadedFile['saved_as'], 'uri' => $uploadLocation, 'type' => $uploadedFile['extension']));
$asset->save();
return '<img src="' . $image64Encoded . '" />';
} else {
// and process any errors
foreach (Upload::get_errors() as $key => $file) {
// $file is an array with all file information,
// $file['errors'] contains an array of all error occurred
// each array element is an an array containing 'error' and 'message'
// Session::set_flash('error', $file['errors'] );
echo 'Error ' . $key . ' - ';
print_r($file['errors']);
echo ' <br />';
}
die;
}
}
return;
}