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

标签 url cakephp console

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

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'));

我认为这是一个常见的功能(在控制台生成的电子邮件中发送有效的网址),但我就是无法弄清楚。

谢谢

最佳答案

在链接中使用full_base选项

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

并将 bootstrap.php 中的 FULL_BASE_URL 常量设置为您的基本 URL:

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

如果您的应用程序使用路由,则需要在 shell 中包含路由:

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

关于url - 从 CakePHP 2.1.2 控制台 Shell 创建完整 url,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11109785/

相关文章:

javascript - Firebug 控制台缩短记录数组中的字符串?

php - MVC 网址重定向

ios - 将 NSString(文件路径)包装在 NSURL 中会破坏 Unicode 吗?

cakephp - 强制 cakephp 3 auth->user() 显示虚拟字段

php - 每个 CakePHP 1.3 页面请求的 httpd.exe 使用率很高

cakephp - 我如何调用 cakePHP 中的元素?

c# - 在 C# 控制台应用程序上更改背景颜色

ruby-on-rails - 这是代码/脚本注入(inject)攻击吗?/script><script type=

http - RESTful 建议 : default value for given resource

javascript - GreaseMonkey - Firefox Web 控制台未显示所有 javascript 错误