本文整理汇总了PHP中UrlHelper::link_to方法的典型用法代码示例。如果您正苦于以下问题:PHP UrlHelper::link_to方法的具体用法?PHP UrlHelper::link_to怎么用?PHP UrlHelper::link_to使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类UrlHelper
的用法示例。
在下文中一共展示了UrlHelper::link_to方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的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: 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));
//.........这里部分代码省略.........
示例3: link_to
/**
* Make a new UrlHelper object and call its link_to() method
* @uses UrlHelper::link_to()
*/
function link_to($name, $options = array(), $html_options = array())
{
$url_helper = new UrlHelper();
return $url_helper->link_to($name, $options, $html_options);
}
示例4: link_to
function link_to($text, $controller_name, $action, $params = null)
{
UrlHelper::link_to($text, $controller_name, $action, $params);
}