MainelyDesign.com Blog

Adding Anchors to Your CakePHP Generated Urls (#link)

Posted on 07/02/2009 at 09:02 am by Kevin Wentworth
Viewed 11,415 times | 6 comments

This may seem simple and trivial, but it took me a little while to figure out.  If it saves someone a little trial-and-error then great (I know I won't forget how to do it).

I needed to create a redirect in CakePHP that redirected to an inline, on-page anchor- <a name="destination">Scroll to Here</a>.  Typing the link directly into the address bar of the browser, it would need to look like this: http://www.mainelydesign.com/blog/view/1219/#destination.  The #destination is what I needed to figure out how to append to the redirected url.  Turns out it was easy...

Use the Pound Sign (#) as a Key in Your Link Options

  1. echo $html->link('Click Me, Please', array('controller'=>'blog', 'action'=>'view', 1219, '#' => 'destination'));

or, Use the Pound Sign (#) as a Key in Your Redirect Call

  1. $this->redirect(array('controller'=>'blog', 'action'=>'view', 1219, '#'=>'destination'));

That was easy wasn't it?  Note the '#'=>'destination'.  Sometimes it's the easy things that can stop and make you think, though.

Cheers,

-Kevin Wentworth

Bookmark and Share

Tags for Adding Anchors to Your CakePHP Generated Urls (#link)

Cakephp | Web Programming | Usage | Usability

Comments for this Posting

Posted by SooxnogYBix

on 5/3/10

Wassup, First time here, this site seems like a very informative board.
Will try to help in to the best I am able :)

Posted by bancer

on 29/4/10

The same result you can achieve with

echo $html->link('Click Me, Please', array('controller'=>'blog', 'action'=>'view', 1219, '#destination'));

http://sourceforge.net/projects/bancer/

Posted by ingenuppy

on 24/1/11

It is my great pleasure to visit your website and to enjoy your awesome posts, I appriciate that very much. I know that you put much attention in those topics, as all of them make sense and are very useful.
Naked Girls

http://britishteentube.com

Posted by MoorieProri

on 24/1/11

What's Happening everybody, charming board I find It absolutely accommodating & it has helped me alot
I hope to be able to contribute & help others like this website has helped me

_________________
jailbreak iphone 4.2.1

http://iphoneusers.com

Posted by acculouro

on 23/2/11

Unlock iPhone 4
Unlock iPhone 3GS
Unlock iPhone 4.2
Unlock iPhone 4.3
iPhone Unlock
how to unlock iphone

http://www.3gsunlock.co.uk

Posted by artibleappake

on 26/2/11

hi, good site very much appreciatted

http://www.google.com

Sorry, comments are closed for this posting.

Please Email Kevin if you have any questions. Thanks!

Meet Site Avenger - Hosted Content Management System

Powered By: Site Avenger | Site Production: Saco Design