Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Setting baseurl in cakephp

Tags:

url

cakephp

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.

like image 374
useranon Avatar asked Jan 22 '23 23:01

useranon


1 Answers

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

like image 132
jack Avatar answered Feb 15 '23 05:02

jack