简体   繁体   中英

CakePHP: How can redirect to a new web page with html anchor <a>… </a>?

The comment form =>

echo $this->Form->create('Comment',array('url'=>array('controller' => 'comments', 'action' =>'add', $listposts['Post']['id']) ) );

echo $this->Form->input('post_id',array('type'=>'hidden','style'=>'width:30%','value'=>$listposts['Post']['id']));  
echo $this->Form->input('name',array('style'=>'width:30%'));
echo $this->Form->input('email',array('style'=>'width:30%'));   
echo $this->Form->input('body',array('rows'=>'5'));

echo $this->Form->end('Comment');

In the body field of the comment form if i type like this =>

<a href="www.google.com"> google </a>

I get a link "google" in that web page but if i click that link it doesn't redirect to www.google.com. Why doesn't redirect ?

If i hover that link i see =>

http://www.mysite.com/posts/view/www.google.com

How can i redirect to www.google.com clicking that link ?

You need to make the url "http://www.google.com". Because there's no protocol specifier it interprets the href field as a relative link instead of a link to another domain.

您可以使用Cakephp的html帮助:

<?php echo $this->Html->link('google', 'http://www.google.com'); ?>

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM