从CakePHP创建完整的URL 2.1.2控制台Shell [英] Creating full url from CakePHP 2.1.2 Console Shell
问题描述
我试图从CakePHP 2.1.2通过控制台shell(最终由cron作业)发送电子邮件。我发送的视图是一个日历,链接回应用程序网页。我发现的问题是,urls不包括正确的路径,从我读到的是因为没有请求对象,因为我使用控制台。例如,如果我在我的浏览器中创建视图,我得到这样的链接:
I am trying to send an email from CakePHP 2.1.2 via console shell (eventually by a cron job). The view I am sending is a calendar with links back to the applications web page. The problem I am finding is that the urls do not include the correct path and from what I have read it is because there is no request object since I am using the console. For example, if I create the view in my browser I get links like this:
http://localhost/ReportMonitor/scheduledReports/index/show_date:2012-06-10/result:GOOD
但在使用相同的电子邮件代码我得到这个:
but in the email using the same code I get this:
http://localhost/scheduledReports/index/show_date:2012-06-10/result:GOOD
这是接近的,但没有雪茄。
which is close, but no cigar.
我一直在试图找到全局,我可以设置某处只是硬编码的app子目录,但还没有找到任何有效的工作。链接由这样的代码:
I have been trying to find the global that I can set somewhere to just hard code the app subdirectory but haven't found anything that works yet. The links are made by a code like this:
$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),但我只是
I would think this is a common function (sending valid urls in console generated email) but I just can't figure it out.
感谢
推荐答案
code> full_base 选项
Use the full_base
option in the links
echo $this->Html->link(array(
'controller' => 'posts', 'action' => 'index', 'full_base' => true
));
并设置 FULL_BASE_URL
c $ c> bootstrap.php 到您的base-url:
and set the FULL_BASE_URL
constant in bootstrap.php
to your base-url:
define('FULL_BASE_URL', 'http://www.domain.com/subdir');
如果您为应用程序使用路由,则需要在shell中包含路由:
If you are using routes for your app, you need to include routing in your shell:
App::uses('Router', 'Routing');
config('routes');
这篇关于从CakePHP创建完整的URL 2.1.2控制台Shell的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!