Creating the Complete URL from CakePHP 2.1.2 Console Shell

I am trying to send an email from CakePHP 2.1.2 through a console shell (eventually using a cron job). The view I am posting is a calendar with links to the application web page. The problem that I find is that the URLs do not include the correct path and from what I read, because there is no request object since I use the console. For example, if I create a view in my browser, I get links like this:

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

but in the letter, using the same code, I get the following:

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

which is close but no cigar.

I am trying to find a global one that I can install somewhere to just copy the application subdirectory, but have not yet found anything that works. Links are created using this code:

$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 that this is a normal feature (sending the correct URLs to the console generated email), but I just can't figure it out.

thank

+5
source share
1 answer

Use parameter full_basein links

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

and set the constant FULL_BASE_URLin bootstrap.phpto your base url:

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

If you use routes for your application, you need to include routing in your shell:

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

All Articles