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.
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'));
I would think this is a common function (sending valid urls in console generated email) but I just can't figure it out.
Thanks
Use the full_base
option in the links
echo $this->Html->link(array(
'controller' => 'posts', 'action' => 'index', 'full_base' => true
));
and set the FULL_BASE_URL
constant in bootstrap.php
to your base-url:
define('FULL_BASE_URL', 'http://www.domain.com/subdir');
If you are using routes for your app, you need to include routing in your shell:
App::uses('Router', 'Routing');
config('routes');
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With