2

我正在使用 CakePHP 3.4

我有一个 shell 脚本作为 cron 运行并向用户发送电子邮件,电子邮件包含返回到指定控制器的网站的链接。

为了实现这一点,我Router::url()在 Shell 中使用来生成基本 url,因为Html->link在那里不工作

$fullBaseUrl = Router::url('/', true);
$scan_result_url = Router::url(['controller' => 'Notifications', 'action' => 'notificationRedirect', $notification->id], true);

但这是以 localhost 作为主机生成 url

http://localhost/notifications/notification-redirect/<id>

测试时控制器中的同一行给出 url

http://mywebsite.com/notifications/notification-redirect/<id>

如何在 Shell 中获取完整的 url。我的网站托管在服务器上并mywebsite.com用于访问它?

4

1 回答 1

0

Cron 不会在您的应用程序中选择服务器 url。您需要在配置文件中设置一个常量并仅使用它。要做到这一点,请看一下这个完整的基本网址示例

于 2017-04-22T16:11:52.377 回答