Prakash Madhak
Prakash Madhak

Reputation: 363

how to set base url in cake php 3 in config/app.php file and get that url in all view

i would like to set base 'url' like "codeigniter" and that can be access in all views. I want to get full url like "http://localhost/somepath"

Upvotes: 1

Views: 8985

Answers (2)

Alisa
Alisa

Reputation: 553

In CakePHP 3 You can define "BASE_URL" constant in

yourAppFolder/config/paths.php as

define('BASE_URL', 'www.yoursite.com/');

and use BASE_URL anywhere in your project.

Upvotes: 0

nIcO
nIcO

Reputation: 5001

You probably don't need to do that, as the Helpers in Cake do that automatically.

For example, if your app is under http://localhost/somepath, creating a link like this

echo $this->Html->link('home', '/');

will automatically point to http://localhost/somepath

Links to actions work the same way:

echo $this->Html->link('login', ['controller' => 'Users', 'action' => 'login']);

will automatically point to http://localhost/somepath/Users/login

And if you do need to get the url anywhere else than in a view, you can do it like this:

use Cake\Routing\Router;

$path = Router::url('/', true);

Upvotes: 6

Related Questions