2012-06-19 24 views
5

我想通過控制檯shell(最終通過cron作業)從CakePHP 2.1.2發送一封電子郵件。我發送的視圖是一個帶有指向應用程序網頁鏈接的日曆。我發現的問題是,網址沒有包含正確的路徑,而且從我讀過的內容來看,這是因爲我使用控制檯時沒有請求對象。例如,如果我在瀏覽器中創建視圖我得到的鏈接是這樣的:從CakePHP創建完整的URL 2.1.2控制檯Shell

http://localhost/ReportMonitor/scheduledReports/index/show_date:2012-06-10/result:GOOD 

但電子郵件中使用相同的代碼我得到這個:

http://localhost/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')); 

我認爲這是一種常見的功能(在生成的控制檯電子郵件發送有效網址),但我無法弄清楚。

感謝

回答

3

使用full_base選項中的鏈接

echo $this->Html->link(array(
    'controller' => 'posts', 'action' => 'index', 'full_base' => true 
)); 

bootstrap.phpFULL_BASE_URL常數設置爲你的基地,網址:

define('FULL_BASE_URL', 'http://www.domain.com/subdir'); 

如果你正在使用的路線爲您的應用程序,您需要在您的外殼中包含路由:

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

這可能會有所幫助http://stackoverflow.com/a/13660262/1868660 –