我有一个问题是在电子邮件视图中建立一个链接,它不会因为某些原因而把我从控制器传递的URL ...
我传递给视图的网址字符串缺少http://domain
前缀
usersController中的一些操作:
$email = new Email(['gmail','transport'=>'gmail']);
$email->template('recover', 'default')
->emailFormat('html')
->viewVars([
'username' => $user['username'],
'url' => '/users/resetpwd/u/'.$user['username'].'/t/'.$user['token']
])
->from(['mailer@domain.com' => 'My Site'])
->to('example@domain.com')
->subject('Password recovery')
->send()
recover.ctp:
<p>Welcome <b><?= $username; ?></b>,<br/>
you requested a password change.<br/>
To set a new password, please: <?php echo $this->Html->link('Click Here', $url, ['_full' => true,'escape' => true]); ?></p>
<?= $this->Html->image('banniere.gif', array('fullBase' => true));?><br/>
<p>This email was sent from <a href="http://cakephp.org">My Site</a></p>
答案 0 :(得分:0)
如果您想确保网址始终是&#34;完整的&#34;一,那么这里适当的解决方案是Router::url()
。这样你甚至可以用数组格式声明URL(通常应该是首选的样式)而不会破坏。
use Cake\Routing\Router;
// ...
<?= $this->Html->link('Click Here', Router::url($url, true), ['escape' => true]); ?>