Warning: Illegal string offset '_imagedir' in /home/cakephpf/public_html/lofiversion/index.php on line 545

Warning: Illegal string offset '_emodir' in /home/cakephpf/public_html/lofiversion/index.php on line 546
CakePHP UnOfficial Community Forum > How to make a link for a new page
Help - Search - Member List - Calendar
Full Version: How to make a link for a new page
CakePHP UnOfficial Community Forum > Layouts and Design

autolycus
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
Oldskool
You don't want to be adding links manually. Use the HtmlHelper link function instead, like this:

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

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.
winniwinter
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
Sir P
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.
cindyhorneto
I'm just geeting started with this one, where should I start guys?
Sir P
here....

http://book.cakephp.org/1.3/view/1528/Blog

smile.gif
maskodook
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
noahwilson
So nice thread, thanks to all of you for sharing your suggestion. its really so hlepful for me.
This is a "lo-fi" version of our main content. To view the full version with more information, formatting and images, please click here.
Invision Power Board © 2001-2014 Invision Power Services, Inc.
Lo-Fi 1.1 iDS Beta, Originally written by Matt,
re-written by Shaun Harrison, Layer 04.com, for pre IPB2.0 versions.