Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to get the base Url in cakephp?

I'm using Html Helper css() method to link my stylesheets just like this: <?php echo $this->Html->css('reset.css');?> but what if my CakePHP app is accessed through a path other than http://site.domain.com, i.e. http://site.domain.com/my_app

What would be the best command to link my stylesheet?

like image 506
Rodrigo Souza Avatar asked Dec 06 '12 07:12

Rodrigo Souza


People also ask

How can I redirect to another page in CakePHP?

Redirecting to Other Pages The flow control method you'll use most often is Controller::redirect() . This method takes its first parameter in the form of a CakePHP-relative URL.


1 Answers

The exact same command should work:

<?php 
echo $this->Html->css('reset.css');
?>

It automatically adds the path to the CSS folder if the given path 'reset.css' doesn't start with a slash.

By the way, if you do need to get the base url in Cake, you can use the Router class:

//with http://site.domain.com/my_app
echo Router::url('/')       //-> /my_app
echo Router::url('/', true) //-> http://site.domain.com/my_app
like image 68
nIcO Avatar answered Sep 22 '22 16:09

nIcO