Powered by Invision Power Board



  Reply to this topicStart new topicStart Poll

> How to make a link for a new page
autolycus
Posted: Apr 24 2011, 12:53 AM
Quote Post


Newbie
*

Group: Members
Posts: 3
Member No.: 2803
Joined: 24-April 11



I am learning cakephp and my installation is as follow

localhost/wordpress/cakephpapplication

now I created a basic page and in the elements I created the top navigation links. I wanted to create an About us page, so under pages folder, where I have my home.ctp page, I created a page called about.ctp. Then in elements top.ctp page I entered the link as

<li><a href="wordpress/pages/about">About Us</a></li>
and when I click it doesnt find the page. Then I tried this

<li><a href="/pages/about">About Us</a></li>
and that didnt work either
PMEmail Poster
Top
Oldskool
Posted: Apr 25 2011, 09:40 AM
Quote Post


Advanced Member
***

Group: Members
Posts: 46
Member No.: 2748
Joined: 23-March 11



You don't want to be adding links manually. Use the HtmlHelper link function instead, like this:

PHP Code
<?php

echo '<li>' $this->Html->link('About Us', array('controller' => 'pages''action' => 'display''about')) . '</li>';

?>


That way Cake will figure out what the right URL to the page is, saving you a lot of headaches wink.gif

Also try reading the basics/tutorial on http://book.cakephp.org/ , it covers these kind of essential things.
PMEmail Poster
Top
winniwinter
Posted: Nov 10 2011, 02:39 PM
Quote Post


Newbie
*

Group: Members
Posts: 1
Member No.: 3206
Joined: 10-November 11



Hi, this post is a little bit older but I am also currently learning cakephp and stuck on a linking problem too.

I'm using this Code
CODE

<?php echo $this->Html->link($test2['content'], $this->Html->url(array('controller' => 'users', 'action' => 'add', '?' => array('group' => 'company') ))); ?>


My Project is located under localhost/test

what I expect is that:
CODE

/users/add?group=company


what I got is:
CODE

/test/users/add?group=company


even if I put out the whole URL I get:
CODE

http://localhost/test/users/add?group=company


Is the line of code wrong or do I have to customize something with routes?! blink.gif
PMEmail Poster
Top
Sir P
Posted: Nov 13 2011, 03:15 PM
Quote Post


Advanced Member
***

Group: Members
Posts: 500
Member No.: 217
Joined: 13-February 08



Hello winniwinter,

When you use the url attribute I don't think you can pass the controller value..try not something like this (untested) ...

CODE

echo $html->link($test2['content'], array('controller'=>'users', 'action' => 'add', '?' => array('group'=>'company')));




As I said, that is untested. A sure fire way (not very cake though) would be:

CODE

echo $html->link($test2['content'], array("controller"=>"users", "action" => "add", "?group=company"));



Or even:

CODE

echo $html->link($test2['content'], array("controller"=>"users", "action" => "add?group=company"));



Have a play.

Good luck.


--------------------
PMEmail PosterUsers Website
Top
cindyhorneto
Posted: Apr 13 2012, 08:59 AM
Quote Post


Newbie
*

Group: Members
Posts: 1
Member No.: 3435
Joined: 13-April 12



I'm just geeting started with this one, where should I start guys?


--------------------
Some things must never be said
PMEmail PosterUsers Website
Top
Sir P
Posted: Apr 13 2012, 10:25 AM
Quote Post


Advanced Member
***

Group: Members
Posts: 500
Member No.: 217
Joined: 13-February 08





--------------------
PMEmail PosterUsers Website
Top
maskodook
Posted: Apr 18 2012, 11:55 PM
Quote Post


Newbie
*

Group: Members
Posts: 2
Member No.: 3447
Joined: 18-April 12



hey mr biggrin.gif
you can use this way:

CODE
<li><a href="<?php echo Router::url('/',true); ?>/pages/about">About Us</a></li>


this code: Router::url('/',true); definiting about your base url: http://localhost/wordpress/blabla/

/pages/about : controller = pages | action = about

biggrin.gif

okey, hopefully help biggrin.gif
sorry, if my bad english: D


--------------------
::: My Home: http://id-webmaster.com | Follow Me: @maskodook :::
PMEmail PosterUsers WebsiteYahoo
Top
noahwilson
Posted: May 8 2013, 10:27 AM
Quote Post


Advanced Member
***

Group: Members
Posts: 88
Member No.: 3816
Joined: 30-March 13



So nice thread, thanks to all of you for sharing your suggestion. its really so hlepful for me.


--------------------
PMEmail PosterUsers Website
Top
0 User(s) are reading this topic (0 Guests and 0 Anonymous Users)
0 Members:

Topic Options Reply to this topicStart new topicStart Poll

 

Disclaimer:
This forum is in no way affiliated with the Cake Software Foundation
The CakePHP name and icon is a trademark of the Cake Software Foundation


Lo-Fi Version