Pregunta

How to create email link from CakePHP Shell? If I did the normal way, e.g:

<?php echo 
$this->Html->link($task['Project']['subject'], array('full_base' => true,
  'admin' => false,
  'controller' => 'projects',
  'action' => 'view',
  $task['Project']['id']                                  
  )
);
?>

it will resulting in localhost/projects/view/12 instead of flat.com/projects/view/12

I did try overwrite in bootstap smtg like:

define('FULL_BASE_URL', 'http://flat.com');

It will work but will cause session problem, which I'm not sure why. e.g: when I logout on flat.com, if I go to www.flat.com, it will still show login. Is there any other way to solve this?

¿Fue útil?

Solución

Avoid the problem

It will work but will cause session problem, [...] when I logout on flat.com, if I go to www.flat.com

Having an application which responds to multiple hostnames can be problematic, and is best avoided. The easiest solution to that problem, is to ensure that there is only one domain in use for the application

For example using apache add the following to the webroot .htaccess file:

RewriteCond %{HTTP_HOST} ^www\.(.+)$ [NC]
RewriteRule ^ http://%1%{REQUEST_URI} [R=301,L]

Or using nginx add a server block like so:

server {
  listen 80;

  # listen on the www host
  server_name www.example.com;

  # and redirect to the non-www host
  return 301 $scheme://example.com$request_uri;
}

Or just define the constant on the cli

Alternatively, conditionally define the constant in your bootstrap file:

if (php_sapi_name() === 'cli') {
    define('FULL_BASE_URL', 'http://example.com');
}

Otros consejos

Just put this at Config/core.php:

Configure::write('App.fullBaseURL', 'http://domain.ext/');
Licenciado bajo: CC-BY-SA con atribución
No afiliado a StackOverflow
scroll top