Setting baseurl in cakephp
Solution 1
Try writing following code
'http://'.$_SERVER['HTTP_HOST'].$this->base
$_SERVER['HTTP_HOST']
----it will give you working host
and $this->base
---will give you working url
Solution 2
You can use $this->base to get base url.
Solution 3
you may use
<?php echo Router::fullbaseUrl();?>
as well.
Refer http://book.cakephp.org/2.0/en/core-libraries/global-constants-and-functions.html for more details.
Solution 4
You could set default URL for all your ajax requests that way:
$.ajaxSetup({
url: 'http://172.20.52.99/FormBuilder/index.php/'
});
Solution 5
Use any one method of following
<?php echo $this->Html->url('/');?>
<?php Router::url('/', true); ?>
<?php echo $this->base;?>
<?php echo $this->webroot; ?>
Define constant in Config/core.php as
define("BASE_URL", "www.yoursite.com/");
and useBASE_URL
anywhere in your project
useranon
Updated on August 23, 2020Comments
-
useranon over 3 years
I am working on an application which is running in CakePHP and I am using AJAX queries from within.
In all the cases for all the ajax post i have used the url as
var ht = $.ajax({ type: "GET", url: "http://172.20.52.99/FormBuilder/index.php/forms/viewChoices/"+attribute_id, async: false }).responseText; var myObject = eval('(' + ht + ')');
Is there any way in CakePHP where I can give my base URL as
http://172.20.52.99/FormBuilder/index.php/
and to call the base URL in all the places I want.