本文整理汇总了PHP中JUri::setVar方法的典型用法代码示例。如果您正苦于以下问题:PHP JUri::setVar方法的具体用法?PHP JUri::setVar怎么用?PHP JUri::setVar使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类JUri
的用法示例。
在下文中一共展示了JUri::setVar方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: fetchUrl
/**
* Method to build and return a full request URL for the request. This method will
* add appropriate pagination details if necessary and also prepend the API url
* to have a complete URL for the request.
*
* @param string $path URL to inflect
* @param integer $page Page to request
* @param integer $limit Number of results to return per page
*
* @return string The request URL.
*
* @since 11.3
*/
protected function fetchUrl($path, $page = 0, $limit = 0)
{
// Get a new JUri object fousing the api url and given path.
$uri = new JUri($this->options->get('api.url') . $path);
if ($this->options->get('gh.token', false)) {
// Use oAuth authentication - @todo set in request header ?
$uri->setVar('access_token', $this->options->get('gh.token'));
} else {
// Use basic authentication
if ($this->options->get('api.username', false)) {
$uri->setUser($this->options->get('api.username'));
}
if ($this->options->get('api.password', false)) {
$uri->setPass($this->options->get('api.password'));
}
}
// If we have a defined page number add it to the JUri object.
if ($page > 0) {
$uri->setVar('page', (int) $page);
}
// If we have a defined items per page add it to the JUri object.
if ($limit > 0) {
$uri->setVar('per_page', (int) $limit);
}
return (string) $uri;
}
示例2: search
public function search()
{
$model = $this->getModel('user');
$uri = new JUri('index.php?option=com_kunena&view=user&layout=list');
$state = $model->getState();
$search = $state->get('list.search');
$limitstart = $state->get('list.start');
if ($search) {
$uri->setVar('search', $search);
}
if ($limitstart) {
$uri->setVar('limitstart', $search);
}
$this->setRedirect(KunenaRoute::_($uri, false));
}
示例3: _buildDataObject
/**
* Create and return the pagination data object.
*
* @return object Pagination data object.
*
* @since 1.5
*/
protected function _buildDataObject()
{
$data = new stdClass();
if (!$this->uri) {
$this->uri = KunenaRoute::$current;
}
// Build the additional URL parameters string.
foreach ($this->additionalUrlParams as $key => $value) {
$this->uri->setVar($key, $value);
}
$limitstartKey = $this->prefix . 'limitstart';
$data->all = new JPaginationObject(JText::_('JLIB_HTML_VIEW_ALL'), $this->prefix);
if (!$this->viewall) {
$this->uri->delVar($limitstartKey, '');
$data->all->base = '0';
$data->all->link = JRoute::_((string) $this->uri);
}
// Set the start and previous data objects.
$data->start = new JPaginationObject(JText::_('JLIB_HTML_START'), $this->prefix);
$data->previous = new JPaginationObject(JText::_('JPREV'), $this->prefix);
if ($this->pagesCurrent > 1) {
$page = ($this->pagesCurrent - 2) * $this->limit;
$this->uri->setVar($limitstartKey, '0');
$data->start->base = '0';
$data->start->link = JRoute::_((string) $this->uri);
$this->uri->setVar($limitstartKey, $page);
$data->previous->base = $page;
$data->previous->link = JRoute::_((string) $this->uri);
}
// Set the next and end data objects.
$data->next = new JPaginationObject(JText::_('JNEXT'), $this->prefix);
$data->end = new JPaginationObject(JText::_('JLIB_HTML_END'), $this->prefix);
if ($this->pagesCurrent < $this->pagesTotal) {
$next = $this->pagesCurrent * $this->limit;
$end = ($this->pagesTotal - 1) * $this->limit;
$this->uri->setVar($limitstartKey, $next);
$data->next->base = $next;
$data->next->link = JRoute::_((string) $this->uri);
$this->uri->setVar($limitstartKey, $end);
$data->end->base = $end;
$data->end->link = JRoute::_((string) $this->uri);
}
$data->pages = array();
$range = range($this->pagesStart, $this->pagesStop);
$range[] = 1;
$range[] = $this->pagesTotal;
sort($range);
foreach ($range as $i) {
$offset = ($i - 1) * $this->limit;
$data->pages[$i] = new JPaginationObject($i, $this->prefix);
if ($i != $this->pagesCurrent || $this->viewall) {
$this->uri->setVar($limitstartKey, $offset);
$data->pages[$i]->base = $offset;
$data->pages[$i]->link = JRoute::_((string) $this->uri);
} elseif ($i == $this->pagesCurrent) {
$data->pages[$i]->active = true;
}
}
return $data;
}
示例4: getUri
/**
* @param string $layout
*
* @return JUri
*/
public static function getUri($layout = null)
{
$uri = new JUri('index.php?option=com_kunena&view=announcement');
if ($layout) {
$uri->setVar('layout', $layout);
}
return $uri;
}
示例5: fetchUrl
/**
* Method to build and return a full request URL for the request. This method will
* add appropriate pagination details if necessary and also prepend the API url
* to have a complete URL for the request.
*
* @param string $path URL to inflect.
* @param integer $limit The number of objects per page.
* @param integer $offset The object's number on the page.
* @param timestamp $until A unix timestamp or any date accepted by strtotime.
* @param timestamp $since A unix timestamp or any date accepted by strtotime.
*
* @return string The request URL.
*
* @since 13.1
*/
protected function fetchUrl($path, $limit = 0, $offset = 0, $until = null, $since = null)
{
// Get a new JUri object fousing the api url and given path.
$uri = new JUri($this->options->get('api.url') . $path);
if ($limit > 0) {
$uri->setVar('limit', (int) $limit);
}
if ($offset > 0) {
$uri->setVar('offset', (int) $offset);
}
if ($until != null) {
$uri->setVar('until', $until);
}
if ($since != null) {
$uri->setVar('since', $since);
}
return (string) $uri;
}
示例6: getData
/**
* @see https://www.warcraftlogs.com/v1/docs#!/Reports/
* @throws RuntimeException
*
* @return stdClass
*/
public function getData($api_key)
{
$uri = new JUri();
$this->params->set('realm', str_replace("'", '', $this->params->get('realm')));
$this->params->set('guild', str_replace(' ', '+', $this->params->get('guild')));
$uri->setPath('/v1/reports/guild/' . $this->params->get('guild') . '/' . JApplicationHelper::stringURLSafe($this->params->get('realm')) . '/' . $this->params->get('region'));
$uri->setVar('api_key', $api_key);
return $this->getRemote($uri);
}
示例7: fetchUrl
/**
* Method to build and return a full request URL for the request. This method will
* add appropriate pagination details if necessary and also prepend the API url
* to have a complete URL for the request.
*
* @param string $path URL to inflect
* @param integer $page Page to request
* @param integer $limit Number of results to return per page
*
* @return string The request URL.
*
* @since 11.3
*/
protected function fetchUrl($path, $page = 0, $limit = 0)
{
// Get a new JUri object fousing the api url and given path.
$uri = new JUri($this->options->get('api.url') . $path);
if ($this->options->get('api.username', false)) {
$uri->setUser($this->options->get('api.username'));
}
if ($this->options->get('api.password', false)) {
$uri->setPass($this->options->get('api.password'));
}
// If we have a defined page number add it to the JUri object.
if ($page > 0) {
$uri->setVar('page', (int) $page);
}
// If we have a defined items per page add it to the JUri object.
if ($limit > 0) {
$uri->setVar('per_page', (int) $limit);
}
return (string) $uri;
}
示例8: getRemote
/**
* @param JUri $uri
* @param bool $persistent
*
* @return mixed
*/
protected function getRemote($uri, $persistent = false)
{
$uri->setScheme($this->params->get('scheme', 'https'));
$uri->setHost($this->params->get('region') . '.api.battle.net');
$uri->setVar('locale', $this->params->get('locale'));
$uri->setVar('apikey', $this->params->get('apikey'));
$this->url = $uri->toString();
$result = parent::getRemote($this->url, $persistent);
$result->body = json_decode($result->body);
if ($result->code != 200) {
// hide api key from normal users
if (!JFactory::getUser()->get('isRoot')) {
$uri->delVar('apikey');
$this->url = $uri->toString();
}
$msg = JText::sprintf('Server Error: %s url: %s', $result->body->reason, JHtml::_('link', $this->url, $result->code, array('target' => '_blank')));
// TODO JText::_()
throw new RuntimeException($msg);
}
return $result;
}
示例9: getBlogItemLink
function getBlogItemLink($item)
{
if ($item->params->get('access-view')) {
$link = JRoute::_(ContentHelperRoute::getArticleRoute($item->slug, $item->catid));
} else {
$menu = JFactory::getApplication()->getMenu();
$active = $menu->getActive();
$itemId = $active->id;
$link1 = JRoute::_('index.php?option=com_users&view=login&Itemid=' . $itemId);
$returnURL = JRoute::_(ContentHelperRoute::getArticleRoute($item->slug, $item->catid));
$link = new JUri($link1);
$link->setVar('return', base64_encode($returnURL));
}
return $link;
}
示例10: renderFormEdit
/**
* Renders a Form for an Edit view and returns the corresponding HTML
*
* @param Form &$form The form to render
* @param DataModel $model The model providing our data
*
* @return string The HTML rendering of the form
*/
public function renderFormEdit(Form &$form, DataModel $model)
{
// Get the key for this model's table
$key = $model->getKeyName();
$keyValue = $model->getId();
$html = '';
$validate = strtolower($form->getAttribute('validate'));
if (in_array($validate, array('true', 'yes', '1', 'on'))) {
\JHTML::_('behavior.formvalidation');
$class = ' form-validate';
$this->loadValidationScript($form);
} else {
$class = '';
}
// Check form enctype. Use enctype="multipart/form-data" to upload binary files in your form.
$template_form_enctype = $form->getAttribute('enctype');
if (!empty($template_form_enctype)) {
$enctype = ' enctype="' . $form->getAttribute('enctype') . '" ';
} else {
$enctype = '';
}
// Check form name. Use name="yourformname" to modify the name of your form.
$formname = $form->getAttribute('name');
if (empty($formname)) {
$formname = 'adminForm';
}
// Check form ID. Use id="yourformname" to modify the id of your form.
$formid = $form->getAttribute('id');
if (empty($formid)) {
$formid = $formname;
}
// Check if we have a custom task
$customTask = $form->getAttribute('customTask');
if (empty($customTask)) {
$customTask = '';
}
// Get the form action URL
$platform = $this->container->platform;
$actionUrl = $platform->isBackend() ? 'index.php' : \JUri::root() . 'index.php';
$itemid = $this->container->input->getCmd('Itemid', 0);
if ($platform->isFrontend() && $itemid != 0) {
$uri = new \JUri($actionUrl);
if ($itemid) {
$uri->setVar('Itemid', $itemid);
}
$actionUrl = \JRoute::_($uri->toString());
}
$html .= '<form action="' . $actionUrl . '" method="post" name="' . $formname . '" id="' . $formid . '"' . $enctype . ' class="form-horizontal' . $class . '">' . "\n";
$html .= "\t" . '<input type="hidden" name="option" value="' . $this->container->componentName . '" />' . "\n";
$html .= "\t" . '<input type="hidden" name="view" value="' . $form->getView()->getName() . '" />' . "\n";
$html .= "\t" . '<input type="hidden" name="task" value="' . $customTask . '" />' . "\n";
$html .= "\t" . '<input type="hidden" name="' . $key . '" value="' . $keyValue . '" />' . "\n";
$html .= "\t" . '<input type="hidden" name="' . \JFactory::getSession()->getFormToken() . '" value="1" />' . "\n";
$html .= $this->renderFormRaw($form, $model, 'edit');
$html .= '</form>';
return $html;
}
示例11: getListByRepository
/**
* Method to list issues.
*
* @param string $user The name of the owner of the GitHub repository.
* @param string $repo The name of the GitHub repository.
* @param string $milestone The milestone number, 'none', or *.
* @param string $state The optional state to filter requests by. [open, closed]
* @param string $assignee The assignee name, 'none', or *.
* @param string $mentioned The GitHub user name.
* @param string $labels The list of comma separated Label names. Example: bug,ui,@high.
* @param string $sort The sort order: created, updated, comments, default: created.
* @param string $direction The list direction: asc or desc, default: desc.
* @param JDate $since The date/time since when issues should be returned.
* @param integer $page The page number from which to get items.
* @param integer $limit The number of items on a page.
*
* @throws DomainException
* @since 11.3
*
* @return array
*/
public function getListByRepository($user, $repo, $milestone = null, $state = null, $assignee = null, $mentioned = null, $labels = null, $sort = null, $direction = null, JDate $since = null, $page = 0, $limit = 0)
{
// Build the request path.
$path = '/repos/' . $user . '/' . $repo . '/issues';
$uri = new JUri($this->fetchUrl($path, $page, $limit));
if ($milestone) {
$uri->setVar('milestone', $milestone);
}
if ($state) {
$uri->setVar('state', $state);
}
if ($assignee) {
$uri->setVar('assignee', $assignee);
}
if ($mentioned) {
$uri->setVar('mentioned', $mentioned);
}
if ($labels) {
$uri->setVar('labels', $labels);
}
if ($sort) {
$uri->setVar('sort', $sort);
}
if ($direction) {
$uri->setVar('direction', $direction);
}
if ($since) {
$uri->setVar('since', $since->toISO8601());
}
// Send the request.
$response = $this->client->get((string) $uri);
// Validate the response code.
if ($response->code != 200) {
// Decode the error response and throw an exception.
$error = json_decode($response->body);
throw new DomainException($error->message, $response->code);
}
return json_decode($response->body);
}
示例12: onJHarvestRetrieve
/**
* Retrieves items from an OAI-enabled url.
*
* @param JTable $harvest The harvesting details.
*/
public function onJHarvestRetrieve($harvest)
{
$params = new \Joomla\Registry\Registry();
$params->loadString($harvest->params);
if ($params->get('discovery.type') != 'oai') {
return;
}
$resumptionToken = null;
$http = JHttpFactory::getHttp();
$metadataPrefix = $params->get('discovery.plugin.metadata');
do {
$queries = array();
if ($resumptionToken) {
$queries['resumptionToken'] = $resumptionToken;
// take a break to avoid any timeout issues.
if (($sleep = $params->get('follow_on', self::FOLLOW_ON)) != 0) {
sleep($sleep);
}
} else {
$queries['metadataPrefix'] = $metadataPrefix;
if ($harvest->harvested != JFactory::getDbo()->getNullDate()) {
$queries['from'] = JFactory::getDate($harvest->harvested)->format('Y-m-d\\TH:i:s\\Z');
}
if ($set = $params->get('set')) {
$queries['set'] = $set;
}
$queries['until'] = $harvest->now->format('Y-m-d\\TH:i:s\\Z');
}
$url = new JUri($params->get('discovery.url'));
$url->setQuery($queries);
$url->setVar('verb', 'ListRecords');
JHarvestHelper::log('Retrieving ' . (string) $url . ' for harvest...', JLog::DEBUG);
$response = $http->get($url);
$reader = new XMLReader();
$reader->xml($response->body);
$prefix = null;
$identifier = null;
$resumptionToken = null;
// empty the resumptionToken to force a reload per page.
while ($reader->read()) {
if ($reader->nodeType == XMLReader::ELEMENT) {
$doc = new DOMDocument();
$doc->appendChild($doc->importNode($reader->expand(), true));
$node = simplexml_load_string($doc->saveXML());
$attributes = (array) $node->attributes();
if (isset($attributes['@attributes'])) {
$attributes = $attributes['@attributes'];
}
switch ($reader->name) {
case "record":
try {
$this->cache($harvest, $node);
} catch (Exception $e) {
JHarvestHelper::log($e->getMessage(), JLog::ERROR);
}
break;
case 'responseDate':
// only get the response date if fresh harvest.
if (!$resumptionToken) {
$this->harvested = JFactory::getDate($node);
}
break;
case 'request':
$prefix = JArrayHelper::getValue($attributes, 'metadataPrefix', null, 'string');
break;
case 'error':
if (JArrayHelper::getValue($attributes, 'code', null, 'string') !== "noRecordsMatch") {
throw new Exception((string) $node, 500);
}
break;
case 'resumptionToken':
$resumptionToken = (string) $node;
break;
default:
break;
}
}
}
} while ($resumptionToken);
}
示例13: testSetVar
/**
* Test the setVar method.
*
* @return void
*
* @since 11.1
* @covers JUri::setVar
*/
public function testSetVar()
{
$this->object->setVar('somevar', 'somevalue');
$this->assertThat($this->object->getVar('somevar'), $this->equalTo('somevalue'));
}
示例14: renderFormEdit
/**
* Renders a F0FForm for an Edit view and returns the corresponding HTML
*
* @param F0FForm &$form The form to render
* @param F0FModel $model The model providing our data
* @param F0FInput $input The input object
*
* @return string The HTML rendering of the form
*/
protected function renderFormEdit(F0FForm &$form, F0FModel $model, F0FInput $input)
{
// Get the key for this model's table
$key = $model->getTable()->getKeyName();
$keyValue = $model->getId();
JHTML::_('behavior.tooltip');
$html = '';
$validate = strtolower($form->getAttribute('validate'));
$class = '';
if (in_array($validate, array('true', 'yes', '1', 'on'))) {
JHtml::_('behavior.formvalidation');
$class = 'form-validate ';
$this->loadValidationScript($form);
}
// Check form enctype. Use enctype="multipart/form-data" to upload binary files in your form.
$template_form_enctype = $form->getAttribute('enctype');
if (!empty($template_form_enctype)) {
$enctype = ' enctype="' . $form->getAttribute('enctype') . '" ';
} else {
$enctype = '';
}
// Check form name. Use name="yourformname" to modify the name of your form.
$formname = $form->getAttribute('name');
if (empty($formname)) {
$formname = 'adminForm';
}
// Check form ID. Use id="yourformname" to modify the id of your form.
$formid = $form->getAttribute('name');
if (empty($formid)) {
$formid = 'adminForm';
}
// Check if we have a custom task
$customTask = $form->getAttribute('customTask');
if (empty($customTask)) {
$customTask = '';
}
// Get the form action URL
$actionUrl = F0FPlatform::getInstance()->isBackend() ? 'index.php' : JUri::root() . 'index.php';
if (F0FPlatform::getInstance()->isFrontend() && $input->getCmd('Itemid', 0) != 0) {
$itemid = $input->getCmd('Itemid', 0);
$uri = new JUri($actionUrl);
if ($itemid) {
$uri->setVar('Itemid', $itemid);
}
$actionUrl = JRoute::_($uri->toString());
}
$html .= '<form action="' . $actionUrl . '" method="post" name="' . $formname . '" id="' . $formid . '"' . $enctype . ' class="' . $class . '">' . PHP_EOL;
$html .= "\t" . '<input type="hidden" name="option" value="' . $input->getCmd('option') . '" />' . PHP_EOL;
$html .= "\t" . '<input type="hidden" name="view" value="' . $input->getCmd('view', 'edit') . '" />' . PHP_EOL;
$html .= "\t" . '<input type="hidden" name="task" value="' . $customTask . '" />' . PHP_EOL;
$html .= "\t" . '<input type="hidden" name="' . $key . '" value="' . $keyValue . '" />' . PHP_EOL;
$html .= "\t" . '<input type="hidden" name="' . JFactory::getSession()->getFormToken() . '" value="1" />' . PHP_EOL;
$html .= $this->renderFormRaw($form, $model, $input, 'edit');
$html .= '</form>';
return $html;
}
示例15: redirectToDownload
/**
* redirectToDownload
*
* @return void
*
* @throws \Exception
*/
public static function redirectToDownload()
{
$username = isset($_SERVER['PHP_AUTH_USER']) ? $_SERVER['PHP_AUTH_USER'] : null;
$password = isset($_SERVER['PHP_AUTH_PW']) ? $_SERVER['PHP_AUTH_PW'] : null;
$input = \JFactory::getApplication()->input;
$uri = new \JUri(\JUri::root());
$uri->setUser($username);
$uri->setPass($password);
$uri->setVar('access_token', $input->get('access_token'));
$uri->setVar('cmd', 'backup.download');
\JFactory::getApplication()->redirect($uri);
exit;
}