本文整理汇总了PHP中Cake\Routing\Router::url方法的典型用法代码示例。如果您正苦于以下问题:PHP Router::url方法的具体用法?PHP Router::url怎么用?PHP Router::url使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Cake\Routing\Router
的用法示例。
在下文中一共展示了Router::url方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: beforeRedirect
/**
* Manage redirect for specific buttons that posted.
*
* @param Event $event
* @param array|string $url
* @param Response $response
* @return bool
*/
public function beforeRedirect(Event $event, $url, Response $response)
{
if ($this->request->param('prefix') == 'admin') {
if (isset($this->request->data['apply'])) {
$response->location(Router::url($this->request->here(false), true));
}
}
return true;
}
示例2: beforeFilter
public function beforeFilter(Event $event)
{
$this->current_user = $this->Auth->user();
//$this->set('logged_in', $this->logged_in);
$this->set('current_user', $this->current_user);
$menu_items = array('home' => array('text' => 'Home', 'link' => Router::url(['controller' => 'home', 'action' => 'index']), 'icon' => 'icon-home'), 'users' => array('text' => 'Users', 'link' => Router::url(['controller' => 'users', 'action' => 'index']), 'icon' => '', 'sub_menu' => array('index' => array('text' => 'List users', 'link' => Router::url(['controller' => 'users', 'action' => 'index']), 'icon' => ''), 'new' => array('text' => 'Add new users', 'link' => Router::url(['controller' => 'users', 'action' => 'add']), 'icon' => ''))), 'demos' => array('text' => 'Demos', 'link' => Router::url(['controller' => 'demos', 'action' => 'index']), 'icon' => ''), 'tests' => array('text' => 'Tests', 'link' => Router::url(['controller' => 'tests', 'action' => 'index']), 'icon' => ''), 'icon' => array('text' => 'Icon', 'link' => Router::url(['controller' => 'home', 'action' => 'icon']), 'icon' => ''));
$this->set('menu_items', $menu_items);
$menu_active = strtolower($this->request->params['controller']);
$this->set('menu_active', $menu_active != '' ? $menu_active : 'index');
$sub_menu_active = $this->request->params['action'];
$this->set('sub_menu_active', $sub_menu_active != '' ? $sub_menu_active : 'index');
$SessionExprieTime = $this->request->session()->read('Admin.SessionExprieTime');
if (!empty($SessionExprieTime)) {
if ($SessionExprieTime <= time()) {
if ($SessionExprieTime <= time()) {
$controller = $this->request->params['controller'];
$action = $this->request->params['action'];
$avoid_action = array('validateSessionExprie', 'sessionLogout', 'login');
if ($controller != 'Users' || $controller == 'Users' && !in_array($action, $avoid_action)) {
$this->Auth->logout();
}
}
}
}
$this->set('SessionExprieIn', $this->createSessionExprie());
}
示例3: _save
/**
*
*
* FUNCTIONS PRIVATE
*
*/
private function _save($entity)
{
if ($this->request->is(['patch', 'post', 'put'])) {
$entity = $this->Contentbuilders->patchEntity($entity, $this->request->data);
// On ajoute les traductions
$I18ns = TableRegistry::get('I18ns');
$langs = $I18ns->find('list', ['keyField' => 'id', 'valueField' => 'locale'])->toArray();
// On merge nos translations
if (isset($entity->translations)) {
$entity->_translations = array_merge($entity->_translations, $entity->translations);
unset($entity->translations);
}
foreach ($entity->_translations as $lang => $data) {
if (in_array($lang, $langs)) {
if ($entity->type_id !== Type::TYPE_HOMEPAGE && empty($data['slug']) && !empty($data['title'])) {
$data['slug'] = strtolower(Inflector::slug($data['title']));
// @ TODO : Il faudra penser a vérifier que le slug n'existe pas, sinon on rajoute -x
}
$entity->translation($lang)->set($data, ['guard' => false]);
}
}
if ($this->Contentbuilders->save($entity)) {
$this->set('response', [true, __("Object saved with success !"), Router::url(['controller' => 'Contentbuilders', 'action' => 'edit', $entity->id, '_ext' => 'html'])]);
$this->set('_serialize', 'response');
} else {
$this->set('response', [false, __("Error occured while saving object !"), $entity->errors()]);
$this->set('_serialize', 'response');
}
}
$types = Contentbuilder::getPrettyType();
$parents = $this->Contentbuilders->find('treeList', ['keyPath' => 'id', 'valuePath' => 'label', 'spacer' => ' --- ']);
$this->set(compact('entity', 'types', 'parents'));
}
示例4: findMap
/**
* Custom finder for map the ntofications.
*
* @param \Cake\ORM\Query $query The query finder.
* @param array $options The options passed in the query builder.
*
* @return \Cake\ORM\Query
*/
public function findMap(Query $query, array $options)
{
return $query->formatResults(function ($notifications) use($options) {
return $notifications->map(function ($notification) use($options) {
$notification->data = unserialize($notification->data);
switch ($notification->type) {
case 'conversation.reply':
$username = $notification->data['sender']->username;
$conversationTitle = Text::truncate($notification->data['conversation']->title, 50, ['ellipsis' => '...', 'exact' => false]);
//Check if the creator of the conversation is the current user.
if ($notification->data['conversation']->user_id === $options['session']->read('Auth.User.id')) {
$notification->text = __('<strong>{0}</strong> has replied in your conversation <strong>{1}</strong>.', h($username), h($conversationTitle));
} else {
$notification->text = __('<strong>{0}</strong> has replied in the conversation <strong>{1}</strong>.', h($username), h($conversationTitle));
}
$notification->link = Router::url(['controller' => 'conversations', 'action' => 'go', $notification->data['conversation']->last_message_id, 'prefix' => false]);
break;
case 'bot':
$notification->text = __('Welcome on <strong>{0}</strong>! You can now post your first comment in the blog.', \Cake\Core\Configure::read('Site.name'));
$notification->link = Router::url(['controller' => 'blog', 'action' => 'index', 'prefix' => false]);
$notification->icon = $notification->data['icon'];
break;
case 'badge':
$notification->text = __('You have unlock the badge "{0}".', $notification->data['badge']->name);
$notification->link = Router::url(['_name' => 'users-profile', 'id' => $notification->data['user']->id, 'slug' => $notification->data['user']->username, '#' => 'badges', 'prefix' => false]);
break;
}
return $notification;
});
});
}
示例5: variant
/**
* Return the webroot path to the image generated variant if this exist or to the controller if not.
*
* @param string $imagePath Path to the original image file from webroot if absolute, or relative to img/
* @param string|array $variantName Name of the variant configuration key or options array
* @param array $options options
* @return string
*/
public function variant($imagePath, $variantName, array $options = [])
{
if (!array_key_exists('plugin', $options) || $options['plugin'] !== false) {
list($plugin, $imagePath) = $this->_View->pluginSplit($imagePath, false);
}
$url = false;
$imagePath = $imagePath[0] === '/' ? substr($imagePath, 1) : $imagePath;
if (!isset($plugin)) {
$originalFile = WWW_ROOT . $imagePath;
$variantFile = dirname($originalFile) . DS . $variantName . DS . basename($originalFile);
if (is_file($variantFile)) {
$url = str_replace(DS, '/', str_replace(WWW_ROOT, '/', $variantFile));
}
} else {
$originalFile = WWW_ROOT . Inflector::underscore($plugin) . DS . $imagePath;
$variantFile = dirname($originalFile) . DS . $variantName . DS . basename($originalFile);
if (is_file($variantFile)) {
$url = str_replace(DS, '/', str_replace(WWW_ROOT, '/', $variantFile));
} else {
$originalFile = Plugin::path($plugin) . 'webroot' . DS . $imagePath;
$variantFile = dirname($originalFile) . DS . $variantName . DS . basename($originalFile);
if (is_file($variantFile)) {
$url = str_replace(Plugin::path($plugin) . 'webroot' . DS, '/' . Inflector::underscore($plugin) . '/', $variantFile);
$url = str_replace(DS, '/', $url);
}
}
}
if ($url === false) {
$url = ['controller' => 'Presenter', 'action' => 'variant', 'plugin' => 'ImagePresenter', 'prefix' => false, '?' => ['image' => isset($plugin) ? "{$plugin}.{$imagePath}" : $imagePath, 'variant' => $variantName]];
}
return Router::url($url);
}
示例6: getIndexDataTable
/**
* Get index DataTable
*
* @param Query $query CakePHP query
*
* @return Table
*/
protected function getIndexDataTable(Query $query)
{
$table = new Table('pages');
$titleCol = new Column();
$titleCol->setTitle('Title')->setData('Pages.title');
$authorCol = new Column();
$authorCol->setTitle('Author')->setData('Users.username')->setFormatter(function ($username, Page $page) {
return $this->createView()->Html->link($username, ['author' => $page->getUserId()]);
});
$commentsCol = new Column();
$commentsCol->setTitle('Comments')->setData('Pages.comment_count')->isSearchable(false);
$dateCol = new Column();
$dateCol->setTitle('Date')->setData('Pages.created_at')->isSearchable(false)->setFormatter(function (Time $cell) {
return $cell->nice();
});
$action = new Column\Action();
$action->setManager(function (Column\ActionBuilder $action, Page $page) {
$action->addAction('view', __d('pages', 'View'), Router::url(['prefix' => false, 'controller' => 'Pages', 'action' => 'view', $page->getId()]), ['title' => __d('pages', 'View “%d”', $page->getTitle()), 'rel' => 'permalink']);
$action->addAction('edit', __d('pages', 'Edit'), Router::url(['controller' => 'Pages', 'action' => 'edit', $page->getId()]), ['title' => __d('pages', 'Edit this item')]);
$action->addAction('delete', __d('pages', 'Delete'), Router::url(['action' => 'delete', $page->getId()]), ['title' => __d('pages', 'Delete this item')]);
})->setTitle('Action');
$table->addColumn($titleCol)->addColumn($authorCol)->addColumn($commentsCol)->addColumn($dateCol)->addColumn($action);
$table->setDataSource(new CakePHP($query, $this->request->here()));
return $table;
}
示例7: initialize
public function initialize()
{
parent::initialize();
$this->viewBuilder()->layout('frontend');
$this->response->disableCache();
$this->set('webroot_full', Router::url('/', true));
}
示例8: build
/**
* Returns a URL based on provided parameters.
*
* ### Options:
*
* - `fullBase`: If true, the full base URL will be prepended to the result
*
* @param string|array|null $url Either a relative string url like `/products/view/23` or
* an array of URL parameters. Using an array for URLs will allow you to leverage
* the reverse routing features of CakePHP.
* @param array $options Array of options
* @return string Full translated URL with base path.
*/
public function build($url = null, array $options = [])
{
$defaults = ['fullBase' => false];
$options += $defaults;
$url = Router::url($url, $options['fullBase']);
return $url;
}
示例9: beforeFilter
public function beforeFilter(Event $event)
{
if ($this->request->is('ajax') && $this->request->params['action'] == 'delete_upload') {
$this->eventManager()->off($this->Csrf);
}
$this->current_user = $this->Auth->user();
//$this->set('logged_in', $this->logged_in);
$this->set('current_user', $this->current_user);
$this->set('menu_items', ['users' => ['text' => 'Users', 'link' => Router::url(['controller' => 'users', 'action' => 'index']), 'allow_access' => ['admin']], 'Members' => ['text' => 'Thành viên', 'link' => Router::url(['controller' => 'members', 'action' => 'index']), 'allow_access' => ['admin']], 'Introduces' => ['text' => 'Giới thiệu', 'link' => Router::url(['controller' => 'introduces', 'action' => 'index']), 'allow_access' => ['admin']], 'Posts' => ['text' => 'Thông báo', 'link' => Router::url(['controller' => 'posts', 'action' => 'index']), 'allow_access' => ['admin']], 'Contacts' => ['text' => 'Liên hệ', 'link' => Router::url(['controller' => 'contacts', 'action' => 'index']), 'allow_access' => ['admin']]]);
$this->set('active_menu_item', $this->request->params['controller']);
$SessionExprieTime = $this->request->session()->read('Admin.SessionExprieTime');
if (!empty($SessionExprieTime)) {
if ($SessionExprieTime <= time()) {
if ($SessionExprieTime <= time()) {
$controller = $this->request->params['controller'];
$action = $this->request->params['action'];
$avoid_action = array('validateSessionExprie', 'sessionLogout', 'login');
if ($controller != 'Users' || $controller == 'Users' && !in_array($action, $avoid_action)) {
$this->Auth->logout();
}
}
}
}
$this->set('SessionExprieIn', $this->createSessionExprie());
}
示例10: add
/**
* Adds a comment in DB and redirects
*
* @return void
*/
public function add()
{
$comment = $this->Comments->newEntity();
// the body field should be empty as it's a honeypot for bots
if ($this->request->is('post') && empty($this->request->data('body'))) {
$data = $this->request->data;
// Preparing data
if (!empty($this->Auth->user('id'))) {
$data['user_id'] = $this->Auth->user('id');
$data['name'] = $this->Auth->user('username');
$data['email'] = $this->Auth->user('email');
} else {
$data['user_id'] = null;
}
unset($data['body']);
// Getting the route
$route = Router::parse(str_replace(Router::url('/', true), '', $this->referer(true)));
$data['fkid'] = $route['pass'][0];
$data['model'] = $route['controller'];
$comment = $this->Comments->patchEntity($comment, $data);
if ($this->Comments->save($comment)) {
if ($comment->allow_contact) {
$this->Flash->success(__d('elabs', 'Thank you for your comment. The author will contact you soon.'));
} else {
$this->Flash->success(__d('elabs', 'Thank you for your comment.'));
}
$this->redirect($this->referer());
} else {
$this->Flash->error(__d('elabs', 'The comment could not be saved. Please try again.'));
}
}
$this->redirect($this->referer());
}
示例11: _getFacebookRedirectLoginHelper
/**
* Get a new instance of FacebookRedirectLoginHelper with optional redirectUrl
*
* @param string $redirectUrl destination to be redirect to after calling the login URL
* @return Facebook\FacebookRedirectLoginHelper new instance
*/
protected function _getFacebookRedirectLoginHelper($redirectUrl = null)
{
if ($redirectUrl == null) {
$redirectUrl = Router::url(['controller' => 'Login', 'action' => 'facebook_login', 'plugin' => null], true);
}
return new FacebookRedirectLoginHelper($redirectUrl);
}
示例12: upload
/**
* Uploads a new file for the given FileField instance.
*
* @param string $name EAV attribute name
* @throws \Cake\Network\Exception\NotFoundException When invalid slug is given,
* or when upload process could not be completed
*/
public function upload($name)
{
$instance = $this->_getInstance($name);
require_once Plugin::classPath('Field') . 'Lib/class.upload.php';
$uploader = new \upload($this->request->data['Filedata']);
if (!empty($instance->settings['extensions'])) {
$exts = explode(',', $instance->settings['extensions']);
$exts = array_map('trim', $exts);
$exts = array_map('strtolower', $exts);
if (!in_array(strtolower($uploader->file_src_name_ext), $exts)) {
$this->_error(__d('field', 'Invalid file extension.'), 501);
}
}
$response = '';
$uploader->file_overwrite = false;
$folder = normalizePath(WWW_ROOT . "/files/{$instance->settings['upload_folder']}/");
$url = normalizePath("/files/{$instance->settings['upload_folder']}/", '/');
$uploader->process($folder);
if ($uploader->processed) {
$response = json_encode(['file_url' => Router::url($url . $uploader->file_dst_name, true), 'file_size' => FileToolbox::bytesToSize($uploader->file_src_size), 'file_name' => $uploader->file_dst_name, 'mime_icon' => FileToolbox::fileIcon($uploader->file_src_mime)]);
} else {
$this->_error(__d('field', 'File upload error, details: {0}', $uploader->error), 502);
}
$this->viewBuilder()->layout('ajax');
$this->title(__d('field', 'Upload File'));
$this->set(compact('response'));
}
示例13: _parseItem
private function _parseItem($item, $options = array())
{
$template = $this->_defaultConfig['template'];
if (isset($options['template'])) {
$template['menuItem'] = $options['template'];
}
$active = false;
$currentParams = $this->request->params;
$url = $item['url'];
if (is_array($url)) {
if ($currentParams['plugin'] === @$url['plugin'] and $currentParams['controller'] === @$url['controller'] and $currentParams['action'] === @$url['action']) {
$active = true;
}
$url = Router::url($url);
}
if ($active) {
$itemResult = str_replace('{{url}}', $url, $template['menuItemActive']);
} else {
$itemResult = str_replace('{{url}}', $url, $template['menuItem']);
}
$itemResult = str_replace('{{text}}', $item['text'], $itemResult);
if (isset($item['child'])) {
$itemResult .= $this->_parseChildMenu($item['child']);
}
return $itemResult;
}
示例14: setUri
public function setUri($uri)
{
if (is_array($uri)) {
$uri = Router::url($uri);
}
return parent::setUri($uri);
}
示例15: seeCurrentRouteIs
/**
* Asserts that current url matches route.
*
* @param array|string $route Route's array or name.
* @param array $params Extra route parameters (i.e. prefix, _method, etc.)
*/
public function seeCurrentRouteIs($route, $params = [])
{
if (!is_array($route)) {
$route = ['_name' => $route];
}
$this->seeCurrentUrlEquals(Router::url($route + $params));
}