2009-11-06 66 views
0

我打算为我的系统添加一个日历功能,但是我已经搞乱了那些没有链接到我想要的直接地址的链接.. 我对cakephp仍然很陌生,需要一些帮助才能理解代码和正确的方法让我指向我想要的正确地址。如何在这种情况下指出我的正确地址?需要帮助

这里是控制器中的一些代码,其他方面不是运行问题,只是留下了让我发疯的指向地址 当我按下链接,我想查看我的数据,它只是跳转到另一端,而不是在我的设置。

// here is the declaration which in the original controller that i learn from the net. 

$view_base_url = $this->webroot. 'calendars'; 

//this the original link that i using which cant point to my correct side. 

$data[$day] .= 'a href="'.$view_base_url.'/view/'. $v['Calendar']['id'] . '">' . $v['Calendar']['name'] . '</a>'; 
在细节

, 我想只用日历/视图/我点了链接的ID链接到我的身边。 但使用此代码,我将重定向到app/webroot/view/id端。 我可以更改$ this-> webroot以链接到我想要的位置? 如果我不使用$这个 - >根目录,我不能够重定向,而我点击日历中的其他网页..

它可能是一个贫穷的解释,因为我是还是新把CakePHP。 只要任何一个可以请我评论我能做什么?

回答

1

您应该使用Router类来创建应用程序内的链接。例如:

Router::url(array('controller' => 'my_controller', 'action' => 'view', $id)); 
// returns, for example, /my_controller/view/5 

Router::url(array('controller' => 'my_controller', 'action' => 'view', $id), true); 
// returns, for example, http://example.com/root_directory/my_controller/view/5 

该方法用于由许多功能在整个蛋糕,例如由HTML辅助:

echo $html->link('My Link', array('controller' => 'my_controller', 'action' => 'view', $id)); 
// echos: 
<a href="/my_controller/view/5">My Link</a> 

Router返回基于在app/config/routes.php定义的路由的网址。这样你可以定义方便的快捷键:

Router::connect('/view/*', array('controller' => 'my_controller', 'action' => 'view')); 

echo $html->link('My Link', array('controller' => 'my_controller', 'action' => 'view', $id)); 
// echos: 
<a href="/view/5">My Link</a> 

这是你应该处理Cake应用程序中所有链接的方式。您不应在控制器中创建链接,只能在视图中使用HTML助手。在极少数情况下,您确实需要Controller中的链接,请使用Router::url()

+0

确定thx为您的信息..真的有很大的帮助。 – 2009-11-10 06:18:08

相关问题