There are n ways, the best I consider for sure is to virtualize the host of your site (vhost) and create a constant for each virtualized environment, keeping constant output by default (by editing the file (in linux): /etc/apache2/sites-available/seusite.conf
and putting it in the list with the command: a2ensite seusite.conf
, in Windows (xampp), just edit the file: C:/xampp/apache/config/extra/httpd-vhosts.config
and restart apache.
<VirtualHost *:80>
ServerName seusite.local
ServerAlias www.seusite.local
ServerAlias seusite_outronome.local
#para xampp windows: DocumentRoot C:/xampp/htdocs/seuprojeto/
DocumentRoot /var/www/html/seuprojeto/
#--->desenvolvimento
SetEnv APPLICATION_ENV "development"
#--->homologação
#SetEnv APPLICATION_ENV "staging"
#--->testes
#SetEnv APPLICATION_ENV "testing"
#--->produção
#SetEnv APPLICATION_ENV "production"
<Directory />
DirectoryIndex index.php
AllowOverride All
Order allow,deny
Allow from all
</Directory>
</VirtualHost>
Remembering to enable your browser, just put the IP in sequence for each virtualized host in Windows
%systemroot%\windows32\drivers\etc\hosts
In Ubuntu linux:
/etc/hosts
And edit the paths:
127.0.0.1 localhost
127.0.1.1 seusite.local
127.0.2.1 seusite2.local
127.0.3.1 seusite3.local
Obs: These addresses should be accessed in the browser with link , if you type only yourite.local will not scroll.
Then you create a file in your config folder, named: application.ini . Inside it put the variables for each environment:
[production]
;configurações comum a todos
appnamespace = "Application"
adapter = "PDO_Mysql"
driver_options = "SET NAMES UTF8"
[development : production]
;aqui vem configurações de desenvolvimento
username = "root"
password = "senha"
dbname = "banco_local"
host = "localhost"
site = "http://www.seusite.com.br"
[testing : production]
;aqui vem configurações de testes
username = "root"
password = "senha"
dbname = "banco_testing"
host = "localhost"
site = "http://eusite.testing.local"
[staging : production]
;aqui vem configurações de homologação
username = "root"
password = "senha"
dbname = "banco_staging"
host = "localhost"
site = "http://homolog.seusite.com.br"
[development : production]
;aqui vem configurações de produção
username = "root"
password = "senha"
dbname = "banco_production"
host = "localhost"
site = "http://seusite.local"
Then you load your file into your project:
$application = parse_ini_file('config/application.ini');
defined('APPLICATION_ENV')
|| define('APPLICATION_ENV', (getenv('APPLICATION_ENV') ? getenv('APPLICATION_ENV') : 'production'));
define("DATABASE_SERVER", $application['host']);
define("DATABASE_USER", $application['username']);
define("DATABASE_PASS", $application['password']);
define("DATABASE_DB", $application['dbname']);
define("URL_SITE", $application['site']);
More information here:
link
Is here:
link
If you use some version driver like git or svn, you can create the same file as application.ini.template
and put it in the versioning, in the case of git, just create a .gitignore in the root with the path: /config/application.ini
and in svn I believe it to be .cvsignore.
In case you could do something like this, in PHP:
$bool = $_POST['redirect'];
if ($bool) {
echo json_encode(array('url'=>URL_SITE)); die();
}
Now you just have to call your Controller from AngularJS, remembering that you need to have the jQuery library in your view:
$scope.redirectUrl = function(strUrl) {
$.post('houte.php',{redirect:true},function(data) {
var host = jQuery.parseJSON(data);
var reg_exp = new RegExp(host['url'] + '/api\/(.*)\/(.+)');
var id = strUrl.replace(reg_exp, '$2');
window.location.href = "/#/info/" + id;
});
};
If the URL being passed is from the same server, you do not need to deploy the host, just get the direct path by passing its URL:
angularApp.controller('SeuController', ['$scope', '$routeParams', '$location', '$http',
function ($scope, $routeParams, $location, $http) {
$scope.visualizar = function(pathUrl) {
var reg_exp = new RegExp('/api\/(.*)\/(.+)');
$location.path(pathUrl.replace(reg_exp, "/info/$2"));
};
});
]);