[英]Redirect users to the correct database according to their country on the url, i worked with i18n for php and im using kohana framework
我有可以包含數據庫連接參數的數據數組,但是我不知道如何在應用程序內部使其動態化,盡管將數據庫連接參數從國家/地區存儲到i18n文件中,但我還是將i18n用於貨幣和主要國家/地區字符串像這個文件一樣使用__('database_array_params'):
<?php
return array(
'CountryName' => 'Perú',
'CountryForVariable' => 'perú',
'locale_id' => 'pe',
'CurrencyForPricing' => 'Soles',
'CurrencyIsoCode' => 'PEN',
'CurrencySymbol' => 'S/',
'CurrencySign' => 'S/. ',
'CountryLat' => '-12.046374',
'CountryLong' => '-77.042793',
'TopCities' =>
array(
array(
'CityName' => 'Lima',
'PostalCode' => 'Blah'
),
array(
'CityName' => 'Cusco',
'PostalCode' => 'Blah'
),
array(
'CityName' => 'Puno',
'PostalCode' => 'Blah'
),
array(
'CityName' => 'Arequipa',
'PostalCode' => 'Blah'
)
),
'default' =>
array(
'type' => 'MySQL',
'connection' => array(
'hostname' => '127.0.0.1',
'database' => 'database_name',
'username' => 'root',
'password' => '123',
'persistent' => FALSE,
),
'table_prefix' => '',
'charset' => 'utf8',
'caching' => FALSE,
'profiling' => FALSE,
),
);
我覺得這是一個不好的方法,我怎樣才能通過一種更清潔的方法來實現目標呢?
這是一個非常非常骯臟的解決方案,但可能會有所幫助。
為每個數據庫創建一個php文件(假設有3個,用於連接數據庫的php文件為confic.php)。 因此,用於訪問的config1.php來自亞洲和大洋洲,訪問美洲的config2.php和訪問歐洲和非洲的config3.php。
您可以使用重寫規則作為下面的示例(來自加拿大的連接示例。
RewriteCond %{REQUEST_URI} /country=CA*
RewriteRule (.+)$ /config2.php
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.