从CakePHP 2.1.2控制台Shell创建完整url

从CakePHP 2.1.2控制台Shell创建完整url,url,cakephp,console,Url,Cakephp,Console,我试图通过控制台shell(最终通过cron作业)从CakePHP 2.1.2发送一封电子邮件。我发送的视图是一个日历,带有指向应用程序网页的链接。我发现的问题是URL没有包含正确的路径,从我读到的内容来看,这是因为在我使用控制台时没有请求对象。例如,如果在浏览器中创建视图,则会得到如下链接: http://localhost/ReportMonitor/scheduledReports/index/show_date:2012-06-10/result:GOOD $newUrl = arra

我试图通过控制台shell(最终通过cron作业)从CakePHP 2.1.2发送一封电子邮件。我发送的视图是一个日历,带有指向应用程序网页的链接。我发现的问题是URL没有包含正确的路径,从我读到的内容来看,这是因为在我使用控制台时没有请求对象。例如,如果在浏览器中创建视图,则会得到如下链接:

http://localhost/ReportMonitor/scheduledReports/index/show_date:2012-06-10/result:GOOD
$newUrl = array();
$newUrl['controller'] = 'scheduledReports';
$newUrl['action'] = 'index';
$newUrl['url'] = array();

foreach ($data as $key => $value) {
  $newUrl['show_date'] = "$year-$month-$key";
  $newUrl['result'] = 'GOOD';
  $data[$key]['num_complete'] = $this->Html->link(__('Complete: ') . $value['num_complete'], Router::reverse($newUrl, true), array('class' => 'green'));
但在使用相同代码的电子邮件中,我得到以下信息:

http://localhost/scheduledReports/index/show_date:2012-06-10/result:GOOD
很接近,但没有雪茄

我一直在试图找到一个全局的,我可以设置在某个地方,只是硬代码的应用程序子目录,但还没有找到任何工作尚未。链接由以下代码组成:

http://localhost/ReportMonitor/scheduledReports/index/show_date:2012-06-10/result:GOOD
$newUrl = array();
$newUrl['controller'] = 'scheduledReports';
$newUrl['action'] = 'index';
$newUrl['url'] = array();

foreach ($data as $key => $value) {
  $newUrl['show_date'] = "$year-$month-$key";
  $newUrl['result'] = 'GOOD';
  $data[$key]['num_complete'] = $this->Html->link(__('Complete: ') . $value['num_complete'], Router::reverse($newUrl, true), array('class' => 'green'));
我认为这是一个常见的功能(在控制台生成的电子邮件中发送有效的URL),但我就是搞不懂


谢谢

使用链接中的
full\u base
选项

echo $this->Html->link(array(
    'controller' => 'posts', 'action' => 'index', 'full_base' => true
));
并将
bootstrap.php
中的
FULL\u BASE\u URL
常量设置为基本URL:

define('FULL_BASE_URL', 'http://www.domain.com/subdir');
如果您正在为应用程序使用路由,则需要在shell中包含路由:

App::uses('Router', 'Routing');
config('routes');