本文整理汇总了PHP中UrlHelper::url_for方法的典型用法代码示例。如果您正苦于以下问题:PHP UrlHelper::url_for方法的具体用法?PHP UrlHelper::url_for怎么用?PHP UrlHelper::url_for使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类UrlHelper
的用法示例。
在下文中一共展示了UrlHelper::url_for方法的10个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: MockAkActionController
function test_for_UrlHelper()
{
$Controller =& new MockAkActionController($this);
$Controller->setReturnValue('urlFor', '/url/for/test');
//$Controller->setReturnValue('_getCompleteRequestUri','/url/for/test');
$url = new UrlHelper();
$url->setController($Controller);
$this->assertReference($Controller, $url->_controller);
$input = array('disabled' => 1, 'checked' => false, 'selected' => '');
$expected = array('disabled' => 'disabled');
$this->assertEqual($url->_convert_boolean_attributes($input, array('disabled', 'checked', 'selected')), $expected);
$input = array('disabled' => true, 'id' => 'hithere');
$expected = array('disabled' => 'disabled', 'id' => 'hithere');
$this->assertEqual($url->_convert_boolean_attributes($input, 'disabled'), $expected);
$this->assertEqual($url->url_for(array('action' => 'create')), '/url/for/test');
$this->assertEqual($url->button_to('Edit'), '<form method="post" action="/url/for/test" class="button-to"><div>' . '<input type="submit" value="Edit" /></div></form>');
$this->assertEqual($url->link_to('Delete this page', array('action' => 'destroy', 'id' => 3), array('confirm' => 'Are you sure?')), '<a href="/url/for/test" onclick="return confirm(\'Are you sure?\');">Delete this page</a>');
$this->assertEqual($url->link_to('Help', array('action' => 'help'), array('popup' => true)), '<a href="/url/for/test" onclick="window.open(this.href);return false;">Help</a>');
$this->assertEqual($url->link_to('Help', array('action' => 'help'), array('popup' => true, 'confirm' => 'Are you sure?')), '<a href="/url/for/test" onclick="if (confirm(\'Are you sure?\')) { window.open(this.href); };return false;">Help</a>');
$this->assertEqual($url->link_to('Help', array('action' => 'help'), array('post' => true)), '<a href="/url/for/test" onclick="var f = document.createElement(\'form\'); document.body.appendChild(f); f.method = \'POST\'; f.action = this.href; f.submit();return false;">Help</a>');
$this->assertEqual($url->link_to('Destroy account', array('action' => 'destroy'), array('confirm' => 'Are you sure?'), array('post' => true)), '<a href="/url/for/test" onclick="return confirm(\'Are you sure?\');">Destroy account</a>');
$this->assertEqual($url->link_to_unless(true, 'Destroy account', array('action' => 'destroy'), array('confirm' => 'Are you sure?'), array('post' => true)), '');
$this->assertEqual($url->link_to_unless(false, 'Destroy account', array('action' => 'destroy'), array('confirm' => 'Are you sure?'), array('post' => true)), '<a href="/url/for/test" onclick="return confirm(\'Are you sure?\');">Destroy account</a>');
$this->assertEqual($url->_popup_javascript_function('A'), 'window.open(this.href);');
$this->assertEqual($url->_popup_javascript_function(array('A', 'B', 'C')), 'window.open(this.href,\'A\',\'C\');');
$this->assertEqual($url->_confirm_javascript_function('Are you sure?'), 'confirm(\'Are you sure?\')');
$this->assertEqual($url->mail_to('me@domain.com', 'My email', array('cc' => 'ccaddress@domain.com', 'bcc' => 'bccaddress@domain.com', 'subject' => 'This is an example email', 'body' => 'This is the body of the message.')), '<a href="mailto:me@domain.com?cc=ccaddress%40domain.com&bcc=bccaddress%40domain.com&body=This%20is%20the%20body%20of%20the%20message.&subject=This%20is%20an%20example%20email">My email</a>');
$this->assertEqual($url->mail_to('me@domain.com', 'My email', array('encode' => 'javascript')), '<script type="text/javascript">eval(unescape(\'%64%6f%63%75%6d%65%6e%74%2e%77%72%69%74%65%28%27%3c%61%20%68%72%65%66%3d%22%6d%61%69%6c%74%6f%3a%6d%65%40%64%6f%6d%61%69%6e%2e%63%6f%6d%22%3e%4d%79%20%65%6d%61%69%6c%3c%2f%61%3e%27%29%3b\'))</script>');
$this->assertEqual($url->mail_to('me@domain.com', 'My email', array('encode' => 'hex')), '<a href="mailto:%6d%65%40%64%6f%6d%61%69%6e%2e%63%6f%6d">My email</a>');
}
示例2: redirect_to
/**
* Sends a header redirect, moving the app to a new url.
* @access protected
* @param string $route
*/
public function redirect_to($options, $protocol = "http://", $status = 302)
{
switch (true) {
case is_array($options):
$url = $protocol . $_SERVER['HTTP_HOST'] . UrlHelper::url_for($options);
$this->response->redirect($url, $status);
break;
case preg_match("/^\\w+:\\/\\/.*/", $options):
$this->response->redirect($options, $status);
break;
case $options == "back":
if (!$_SERVER['HTTP_REFERER']) {
return false;
}
$this->response->redirect($_SERVER['HTTP_REFERER']);
break;
case is_string($options):
if (substr($options, 0, 1) != "/") {
if (substr($_SERVER['REQUEST_URI'], -1) != "/") {
$options = "/" . $options;
}
$options = $_SERVER['REQUEST_URI'] . $options;
}
$url = $protocol . $_SERVER['HTTP_HOST'] . $options;
$this->response->redirect($url, $status);
break;
}
$this->response->execute();
exit;
}
示例3: redirect_to
/**
* Sends a header redirect, moving the app to a new url.
* @access protected
* @param string $route
*/
public function redirect_to($options, $protocol = "http://")
{
switch (true) {
case is_array($options):
$url = $protocol . $_SERVER['HTTP_HOST'] . UrlHelper::url_for($options);
header("Location:{$url}");
exit;
break;
case preg_match("/^\\w+:\\/\\/.*/", $options):
header("Location:{$options}");
exit;
break;
case $options == "back":
if (!$_SERVER['HTTP_REFERER']) {
return false;
}
header("Location:{$_SERVER['HTTP_REFERER']}");
exit;
break;
case is_string($options):
if (substr($options, 0, 1) != "/") {
if (substr($_SERVER['REQUEST_URI'], -1) != "/") {
$options = "/" . $options;
}
$options = $_SERVER['REQUEST_URI'] . $options;
}
$url = $protocol . $_SERVER['HTTP_HOST'] . $options;
header("Location:{$url}");
exit;
break;
}
}
示例4: array
* [description including history]
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
* @author [creator, or "Original Author"]
* @license http://bit.ly/aVWqRV PayAsYouGo License
* @copyright Copyright (c) 2010 Broadband Mechanics
* @package PeopleAggregator
*/
$login_required = TRUE;
include_once "web/includes/page.php";
require_once "api/Theme/Template.php";
require_once "api/Login/PA_Login.class.php";
require_once "web/includes/classes/UrlHelper.class.php";
// if return url is set in the request then after logout redirect to the location else redirect to homepage.
if (!empty($_REQUEST['return'])) {
$return = $_REQUEST['return'];
} else {
// build rthe url via UrlHelper so we can respect the SSL directives
$return = UrlHelper::url_for(PA::$url . '/' . FILE_LOGIN, array(), 'https');
}
// destroy the login cookie
PA_Login::log_out();
// invalidate the cache for user profile
$file = PA::$theme_url . "/user_profile.tpl?uid=" . PA::$login_uid;
CachedTemplate::invalidate_cache($file);
// kill the session
$_SESSION = array();
session_destroy();
session_start();
// and go home :)
header("Location: {$return}");
exit;
示例5: getMessageSpecificData
public function getMessageSpecificData()
{
if (is_array($this->associated_obj)) {
// to keep compatibility with some old code, we must accept parameters given in arrays also
foreach ($this->associated_obj as $name => $value) {
$this->template_vars["%{$name}%"] = $value;
}
} else {
if (is_object($this->associated_obj)) {
if (is_a($this->associated_obj, 'User')) {
$this->addUserData($this->associated_obj, 'related.user');
} else {
if (is_a($this->associated_obj, 'Content')) {
$author = new User();
$author->load((int) $this->associated_obj->author_id);
$this->addUserData($author, 'content.author');
$this->template_vars["%content.title%"] = $this->associated_obj->title;
$this->template_vars["%content.url%"] = UrlHelper::url_for(PA_ROUTE_CONTENT, array('cid' => $this->associated_obj->content_id));
$this->template_vars["%content.link%"] = UrlHelper::link_to(PA_ROUTE_CONTENT, $this->associated_obj->title, null, array('cid' => $this->associated_obj->content_id));
$this->template_vars["%content.delete_url%"] = UrlHelper::url_for(PA_ROUTE_CONTENT, array('cid' => $this->associated_obj->content_id, 'action' => 'deleteContent'));
$this->template_vars["%content.delete_link%"] = UrlHelper::link_to(PA_ROUTE_CONTENT, $this->template_vars["%content.delete_url%"], null, array('cid' => $this->associated_obj->content_id, 'action' => 'deleteContent'));
$this->template_vars["%content.moderation_url%"] = UrlHelper::url_for(PA::$url . '/' . FILE_NETWORK_MANAGE_CONTENT);
$this->template_vars["%content.moderation_link%"] = UrlHelper::link_to(PA::$url . '/' . FILE_NETWORK_MANAGE_CONTENT, $this->template_vars["%content.moderation_url%"]);
if (get_class($this->associated_obj) == 'Image' || get_class($this->associated_obj) == 'Audio' || get_class($this->associated_obj) == 'Video') {
if (!empty($this->associated_obj->group_id)) {
// if Group Media
$this->group = new Group();
$this->group->load((int) $this->associated_obj->group_id);
$this->addGroupData($this->group);
}
$this->template_vars["%media.title%"] = $this->associated_obj->title;
$this->template_vars["%media.full_view_url%"] = UrlHelper::url_for(PA::$url . '/' . FILE_MEDIA_FULL_VIEW, array('cid' => $this->associated_obj->content_id, 'login_required' => 'true'));
$this->template_vars["%media.full_view_link%"] = UrlHelper::link_to(PA::$url . '/' . FILE_MEDIA_FULL_VIEW, $this->template_vars["%media.full_view_url%"], null, array('cid' => $this->associated_obj->content_id, 'login_required' => 'true'));
}
} else {
if (is_a($this->associated_obj, 'Comment')) {
$author = new User();
$author->load((int) $this->associated_obj->user_id);
$this->addUserData($author, 'comment.author');
$this->template_vars["%comment.text%"] = $this->associated_obj->comment;
$this->template_vars["%comment.url%"] = UrlHelper::url_for(PA_ROUTE_CONTENT, array('cid' => $this->associated_obj->content_id));
$this->template_vars["%comment.link%"] = UrlHelper::link_to(PA_ROUTE_CONTENT, $this->template_vars["%comment.url%"], null, array('cid' => $this->associated_obj->content_id));
$this->template_vars["%comment.delete_url%"] = UrlHelper::url_for(PA::$url . '/deletecomment.php', array('comment_id' => $this->associated_obj->comment_id));
$this->template_vars["%comment.delete_link%"] = UrlHelper::link_to(PA::$url . '/deletecomment.php', $this->template_vars["%comment.delete_url%"], null, array('comment_id' => $this->associated_obj->comment_id));
} else {
if (is_a($this->associated_obj, 'Invitation')) {
$inviter = new User();
$inviter->load((int) $this->associated_obj->user_id);
$this->addUserData($inviter, 'invite.inviter');
if (!empty($this->associated_obj->inv_collection_id) && $this->associated_obj->inv_collection_id != -1) {
$group = new Group();
$group->load((int) $this->associated_obj->inv_collection_id);
$this->group = $group;
$this->addGroupData($this->group);
}
if (empty($this->associated_obj->inv_user_id) || $this->associated_obj->inv_summary == "internal_invitation") {
// invitation sent
$reg_link_desc = abbreviate_text($this->associated_obj->register_url, 52, 36);
$acc_link_desc = abbreviate_text($this->associated_obj->accept_url, 52, 36);
$reg_link = "<a href=\"{$this->associated_obj->register_url}\">{$reg_link_desc}</a>";
$acc_link = "<a href=\"{$this->associated_obj->accept_url}\">{$acc_link_desc}</a>";
$this->template_vars["%invite.message%"] = $this->associated_obj->inv_message;
$this->template_vars["%invite.accept_url%"] = $this->associated_obj->accept_url;
$this->template_vars["%invite.accept_link%"] = $acc_link;
$this->template_vars["%invite.register_url%"] = $this->associated_obj->register_url;
$this->template_vars["%invite.register_link%"] = $reg_link;
$this->template_vars["%invite.invited_user_name%"] = $this->associated_obj->inv_user_first_name;
$this->template_vars["%invite.invited_user_email%"] = $this->associated_obj->inv_email;
$this->template_vars["%recipient.email_address%"] = $this->associated_obj->inv_email;
} else {
// invitation accepted
$invited = new User();
$invited->load((int) $this->associated_obj->inv_user_id);
$this->addUserData($invited, 'invite.invited');
if (!empty($this->associated_obj->inv_relation_type)) {
$this->template_vars["%invite.relation_type%"] = $this->associated_obj->inv_relation_type;
}
}
} else {
if (is_a($this->associated_obj, 'RelationData')) {
$requester = new User();
$relateduser = new User();
$requester->load((int) $this->associated_obj->user_id);
$relateduser->load((int) $this->associated_obj->relation_id);
$this->addUserData($requester, 'relation.inviter');
$this->addUserData($relateduser, 'relation.invited');
$this->template_vars["%relation.type%"] = Relation::lookup_relation_type($this->associated_obj->relationship_type);
$this->template_vars["%relation.friend_list_url%"] = UrlHelper::url_for(PA::$url . '/' . FILE_VIEW_ALL_MEMBERS, array('view_type' => 'in_relations', 'uid' => $this->associated_obj->user_id, 'login_required' => 'true'));
$this->template_vars["%relation.friend_list_link%"] = UrlHelper::link_to(PA::$url . '/' . FILE_VIEW_ALL_MEMBERS, $this->template_vars["%relation.friend_list_url%"], null, array('view_type' => 'in_relations', 'uid' => $this->associated_obj->user_id, 'login_required' => 'true'));
$this->template_vars["%relation.appr_deny_url%"] = UrlHelper::url_for(PA::$url . '/' . FILE_VIEW_ALL_MEMBERS, array('view_type' => 'in_relations', 'uid' => $this->associated_obj->relation_id, 'login_required' => 'true'));
$this->template_vars["%relation.appr_deny_link%"] = UrlHelper::link_to(PA::$url . '/' . FILE_VIEW_ALL_MEMBERS, $this->template_vars["%relation.appr_deny_url%"], null, array('view_type' => 'in_relations', 'uid' => $this->associated_obj->relation_id, 'login_required' => 'true'));
} else {
if (is_a($this->associated_obj, 'ReportAbuse')) {
$author = new User();
$author->load((int) $this->associated_obj->reporter_id);
$this->addUserData($author, 'abuse.reporter');
$this->template_vars["%abuse.report%"] = $this->associated_obj->body;
$this->template_vars["%abuse.url%"] = UrlHelper::url_for(PA_ROUTE_CONTENT, array('cid' => $this->associated_obj->parent_id));
$this->template_vars["%abuse.link%"] = UrlHelper::link_to(PA_ROUTE_CONTENT, $this->template_vars["%abuse.url%"], null, array('cid' => $this->associated_obj->parent_id));
$this->template_vars["%abuse.delete_comment_url%"] = UrlHelper::url_for(PA::$url . '/deletecomment.php', array('comment_id' => $this->associated_obj->parent_id));
//.........这里部分代码省略.........
示例6: auto_complete_field
/**
* Adds AJAX autocomplete functionality to the text input field with the
* DOM ID specified by +field_id+.
*
* This function expects that the called action returns a HTML <ul> list,
* or nothing if no entries should be displayed for autocompletion.
*
* You'll probably want to turn the browser's built-in autocompletion off,
* so be sure to include a autocomplete="off" attribute with your text
* input field.
*
* The autocompleter object is assigned to a Javascript variable named <tt>field_id</tt>_auto_completer.
* This object is useful if you for example want to trigger the auto-complete suggestions through
* other means than user input (for that specific case, call the <tt>activate</tt> method on that object).
*
* Required +options+ are:
* <tt>url</tt>:: URL to call for autocompletion results
* in url_for format.
*
* Addtional +options+ are:
* <tt>update</tt>:: Specifies the DOM ID of the element whose
* innerHTML should be updated with the autocomplete
* entries returned by the AJAX request.
* Defaults to field_id + '_auto_complete'
* <tt>with</tt>:: A JavaScript expression specifying the
* parameters for the XMLHttpRequest. This defaults
* to 'fieldname=value'.
* <tt>indicator</tt>:: Specifies the DOM ID of an element which will be
* displayed while autocomplete is running.
* <tt>tokens</tt>:: A string or an array of strings containing
* separator tokens for tokenized incremental
* autocompletion. Example: <tt>tokens => ','</tt> would
* allow multiple autocompletion entries, separated
* by commas.
* <tt>min_chars</tt>:: The minimum number of characters that should be
* in the input field before an Ajax call is made
* to the server.
* <tt>on_hide</tt>:: A Javascript expression that is called when the
* autocompletion div is hidden. The expression
* should take two variables: element and update.
* Element is a DOM element for the field, update
* is a DOM element for the div from which the
* innerHTML is replaced.
* <tt>on_show</tt>:: Like on_hide, only now the expression is called
* then the div is shown.
* <tt>select</tt>:: Pick the class of the element from which the value for
* insertion should be extracted. If this is not specified,
* the entire element is used.
* @deprecated
*/
function auto_complete_field($field_id, $options = array())
{
$function = "var {$field_id}_auto_completer = new Ajax.Autocompleter(";
$function .= "'{$field_id}', ";
$function .= !empty($options['update']) ? "'{$options['update']}', " : "'{$field_id}_auto_complete', ";
$function .= "'".UrlHelper::url_for($options['url'])."'";
$js_options = array();
if (!empty($options['tokens'])){
$js_options['tokens'] = JavaScriptHelper::_array_or_string_for_javascript($options['tokens']) ;
}
if (!empty($options['with'])) {
$js_options['callback'] = "function(element, value) { return {$options['with']} }";
}
if (!empty($options['indicator'])) {
$js_options['indicator'] = "'{$options['indicator']}'";
}
if (!empty($options['select'])) {
$js_options['select'] = "'{$options['select']}'";
}
$default_options = array(
'on_show' => 'onShow',
'on_hide' => 'onHide',
'min_chars' => 'min_chars'
);
foreach ($default_options as $key=>$default_option) {
if (!empty($options[$key])) {
$js_options[$default_option] = $options[$key];
}
}
$function .= ', '.JavaScriptHelper::_options_for_javascript($js_options).')';
return JavaScriptHelper::javascript_tag($function);
}
示例7: if
<a href="#" onclick="$('#relationType').toggle(); return false;"><?=__("Update relation")?></a>
<br/>
<? } else { ?>
<b><?= $mod->join_this_group_string;?></b>
<? } ?>
<div id="relationType" <? if ($mod->is_member) echo 'style="display:none;"'; ?>>
<select name="relation"
<option value=""><?=__("-- Please select --")?></option>
<?php
foreach ($mod->availRelations as $k=>$v) {
?>
<option value="<?=$k?>" <?php
if ($k == @$mod->relationType) echo 'selected="selected"'
?>><?=$v?></option>
<?
}
?>
</select>
<input type="submit" name="submit" id="joinbutton" value="<?= ($mod->is_member) ? __("Update") : __("Join now") ?>" />
</div>
</form>
<?php } ?>
<?php if ($mod->is_admin) { ?>
<a href="<?= PA::$url.PA_ROUTE_FAMILY_EDIT?>?gid=<?= $mod->group_details->collection_id?>"><?= __('Family Settings')?></a> |
<a href='<?= UrlHelper::url_for(PA_ROUTE_FAMILY_MODERATION, array('gid' => $mod->group_details->collection_id)) ?>'><?= __("Add a Child") ?></a>
<?php
}
?>
</div>
示例8: url_for
/**
* Make a new UrlHelper object and call its url_for() method
* @uses UrlHelper::url_for()
*/
function url_for($options = array())
{
$url_helper = new UrlHelper();
return $url_helper->url_for($options);
}
示例9: testUrl_for_method
/**
* Test url_for() method
*
* Thest the {@link UrlHelper::url_for()} method
*/
public function testUrl_for_method()
{
$uh = new UrlHelper();
$this->assertEquals('http://www.example.com/testprefix/testcontrol', $uh->url_for());
$this->assertEquals('http://www.example.com/testprefix/foocontrol', $uh->url_for(array(':controller' => 'foocontrol')));
$this->assertEquals('http://www.example.com/testprefix' . '/barcontrol/fooaction', $uh->url_for(array(':controller' => 'barcontrol', ':action' => 'fooaction')));
$this->assertEquals('http://www.example.com/testprefix' . '/barcontrol/baraction/fooid', $uh->url_for(array(':controller' => 'barcontrol', ':action' => 'baraction', ':id' => 'fooid')));
}
示例10: handlePOST_deleteFamilyMembers
public function handlePOST_deleteFamilyMembers($request_data)
{
global $app;
if (!empty($request_data["members"]) && !empty($request_data["family_id"])) {
$membersArr = array();
$membersArr = $request_data["members"];
$family = new Group();
$family->collection_id = $request_data["family_id"];
$membersArr_count = count($membersArr);
for ($counter = 0; $counter < $membersArr_count; $counter++) {
list($res, $msg) = $this->leaveFamily($family, (int) $membersArr[$counter]);
if (!$res) {
return;
}
}
$msg = __("Member(s) Deleted");
} else {
$msg = __('Please select a member');
}
$url = UrlHelper::url_for(PA_ROUTE_FAMILY_MODERATION, array('gid' => $request_data["family_id"], 'msg' => urlencode($msg)));
$app->redirect($url);
}