Category: Routing

Q: Get base_url in controller

I need to fix one of my client's cakephp application (version 2.4). And in most web applications we need base_url to get current path for link building. Now I want to build a link to image so:

$base_url = 'http://' . $_SERVER['SERVER_NAME'] . Router::url('/');

$image_path = $base_url . '/img/abcd.png';

I wonder if there is any alternative? I'm sure there should be a global configuration. 

SOLVED
2 Answers

Version: 2.4

user
Pidara

4

Accepted by Pidara

To get full url in controller:

$base_url = Router::url('/', true);
$image_path = $base_url . '/img/abcd.png';
Kristi
Kristi

137

use App\Controller\Router;

$image_path = Router::url('/', true) . '/img/abcd.png';
Pidara
Pidara

4