Creating a link from one site to another in cakephp

Asked

Viewed 162 times

1

I’m having a problem, I’m creating a button, which is on an X site, but the controller the action of the link is on the Y site. My problem is that when I click the button, it references the controller to action right, but the base of the site continues from Site X and not from Y.

<td> <?= (!empty($cnId)) ? $this->Html->link('Galeria', array('plugin'=>'Galeria','controller'=> 'Fotos','action' => 'index',$cnId),array('class'=>'btn btn-default')) : ''; ?> </td>

He’s linking me up http: X/galeria/fotos/index/$id, but I wanted him to link me to Y/galeria/fotos/index/$id. How do I do that?

  • According to the documentation: http://api.cakephp.org/2.1/class-HtmlHelper.html#_link If $url starts with "http://" this is treated as an external link. Else, it is treated as a path to controller/action and parsed with the HtmlHelper::url() method.. You have to provide some location with http:// before, otherwise it will always point "internally".

2 answers

1

Cannot use the structure routing array to reference external links. For this, you must inform all the URL in the second parameter, this being a string:

echo $this->Html->link('Galeria', 'http://...', array('class'=>'btn btn-default'));

0

Hello, try this on:

<td> <?= (!empty($cnId)) ? $this->Html->url('Galeria', array('plugin'=>'Galeria','controller'=> 'Fotos','action' => 'index',$cnId),array('class'=>'btn btn-default')) : '';?> </td>

OR

<td> <?= (!empty($cnId)) ? $this->Html-link('http://', 'Galeria', array('plugin'=>'Galeria','controller'=> 'Fotos','action' => 'index',$cnId),array('class'=>'btn btn-default')) : '';?> </td>
  • That way it worked, thank you all very much. Edited question with the right answer.

  • 1

    The syntax here of the two methods is incorrect, according to the manual. Anyway @Michelhenriq, no need to edit your question. Just leave your original problem and mark the correct answer as accepted, so you can help others with the same question.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.