尊龙凯时人生就是博

ThinkPHP6ÖÐÔõÑùʵÏÖ¶àÓïÑÔÍøÕ¾£¿

thinkphp6ÊÇÒ»¿îÓÅÒìµÄphp¿ª·¢¿ò¼Ü£¬ËüÌṩÁ˺ÜÊÇÓÅÒìµÄ´úÂëÖÎÀíºÍ¿ÉÀ©Õ¹ÐÔ¡£ÔÚÏÖʵ¿ª·¢ÖУ¬Ëæ×ÅÈ«Çò»¯µÄÇ÷ÊÆ£¬Ô½À´Ô½¶àµÄÍøÕ¾ÐèÒªÌṩ¶àÓïÑÔÖ§³Ö¡£ÄÇôÔÚthinkphp6ÖУ¬ÔõÑùʵÏÖ¶àÓïÑÔÍøÕ¾ÄØ£¿±¾ÎĽ«´ÓÒÔÏÂËĸö·½Ãæ¾ÙÐнâ˵¡£

Ò»¡¢ÉèÖÃÎļþÖнç˵¶àÓïÑÔ±äÁ¿

ÔÚThinkPHP6ÖУ¬ºÜÊÇÍƼöͨ¹ýÉèÖÃÎļþµÄ·½·¨À´½ç˵¶àÓïÑÔ±äÁ¿¡£Ê×ÏÈÎÒÃÇÐèÒªÔÚconfigĿ¼Ï½¨ÉèÒ»¸ölang.phpÎļþ£¬È»ºóÔÚÆäÖнç˵¶àÓïÑÔÊý×飬ÀýÈ磺

<?php
return [
    'welcome' => '½Ó´ý',
    'hello' => 'ÄãºÃ',
    'bye' => 'ÔÙ¼û',
    ...
];

µÇ¼ºó¸´ÖÆ

½Ó×ÅÔÚ¿ØÖÆÆ÷ÖÐͨ¹ýlangÖúÊÖº¯ÊýÀ´»ñÈ¡ÕâЩ¶àÓïÑÔ±äÁ¿£¬ÀýÈ磺

echo lang('welcome');

µÇ¼ºó¸´ÖÆ

ÕâÑù£¬µ±ÄãµÄÍøÕ¾ÐèÒªÖ§³Ö²î±ðµÄÓïÑÔʱ£¬Ö»ÐèÒªÐÞ¸Älang.phpÎļþÖжÔÓ¦µÄ¶àÓïÑÔ±äÁ¿Öµ¼´¿É¡£

Á¬Ã¦Ñ§Ï°¡°PHPÃâ·ÑѧϰÌõ¼Ç£¨ÉîÈ룩¡±£»

¶þ¡¢Ê¹ÓÃÖÐÐļþÀ´Æ¾Ö¤ÓïÑÔÉèÖÃSession

ΪÁËÄܹ»Çл»²î±ðµÄÓïÑÔ£¬ÎÒÃÇÐèÒªÔÚÍøÕ¾ÖÐÉèÖÃÒ»¸öÓïÑÔSession¡£Õâ¸öÓïÑÔSession¿ÉÒÔƾ֤ǰ̨´«À´µÄ²ÎÊý»òÕßä¯ÀÀÆ÷ÉèÖÃÀ´¾ÙÐÐ×Ô¶¯Ê¶±ð¡£

ÔÚThinkPHP6ÖУ¬ÎÒÃÇ¿ÉÒÔͨ¹ýÖÐÐļþÀ´ÊµÏÖÕâ¸ö¹¦Ð§¡£ÔÚapp/middlewareĿ¼Ï½¨ÉèÒ»¸öLanguage.phpµÄÖÐÐļþÎļþ£¬´úÂëÈçÏ£º

<?php
namespace appmiddleware;

use thinkacadeSession;
use thinkRequest;

class Language
{
    public function handle(Request $request, Closure $next)
    {
        $lang = $request->param('lang');
        if(!in_array($lang, ['zh-cn', 'en-us'])){
            $lang = $_SERVER['HTTP_ACCEPT_LANGUAGE'];
        }
        Session::set('lang', $lang);
        return $next($request);
    }
}

µÇ¼ºó¸´ÖÆ

ÆäÖУ¬ÅжÏת´ïµÄÓïÑÔ²ÎÊýÊÇ·ñÕýµ±£¬ÈôÊDz»¶Ô¹æÔòʹÓÃä¯ÀÀÆ÷ÉèÖÃÖеÄÓïÑÔ²ÎÊý¡£

ÔÚapp/middleware.phpÖÐÒýÈë¸ÃÖÐÐļþ£¬²¢ÔÚÐèÒªÖ§³Ö¶àÓïÑԵĿØÖÆÆ÷ÖÐʹÓã¬ÀýÈ磺

<?php
namespace appcontroller;

use thinkacadeSession;

class Index
{
    public function index()
    {
        $lang = Session::get('lang');
        return lang('welcome');
    }
}

µÇ¼ºó¸´ÖÆ

Èý¡¢Ê¹ÓöàÓïÑÔ·ÓÉ

Õë¶ÔһЩÐèÒªÖ§³Ö¶àÓïÑÔ·ÓɵÄÐèÇó£¬ThinkPHP6ÖÐÌṩÁ˺ÜÊÇÀû±ãµÄÒªÁì¡£ÀýÈ磬ÎÒÃÇ¿ÉÒÔ½ç˵ÒÔÏÂÁ½¸ö·ÓÉ£º

Route::get(':lang/index', 'index/index');
Route::get(':lang/about', 'index/about');

µÇ¼ºó¸´ÖÆ

ÕâÑùÎÒÃÇ»á¼ûhttps://example.com/zh-cn/indexºÍhttps://example.com/zh-cn/aboutʱ¾Í»á½øÈë¶ÔÓ¦µÄ¿ØÖÆÆ÷ÖУ¬²¢ÇÒǰ̨¾Í²»ÐèÒªµ¥¶Àת´ïÓïÑÔ²ÎÊýÁË¡£

ËÄ¡¢Ê¹ÓÃÄ£°å±êÇ©À´Êä³ö¶àÓïÑÔÄÚÈÝ

×îºó£¬ÎÒÃÇÐèÒªÔÚǰ̨¶Ô¶àÓïÑÔ±äÁ¿¾ÙÐÐÊä³ö¡£ÕâʱÎÒÃDZã¿ÉÒÔʹÓÃThinkPHP6ÌṩµÄ¡°Ä£°å±êÇ©¡±¹¦Ð§£¬ÀýÈ磺

{: lang('welcome') }

µÇ¼ºó¸´ÖÆ

ËäÈ»£¬¸üÍƼöʹÓÃÏÂÃæÕâÖÖ·½·¨£º

{lang name="welcome"}

µÇ¼ºó¸´ÖÆ

ÕâÑù¼ÈÄܹ»Êä³ö¶ÔÓ¦µÄ¶àÓïÑÔ±äÁ¿£¬Ò²Äܹ»Ìí¼ÓһЩĬÈÏÖµºÍ²ÎÊý¡£

×ܽá

ÒÔÉϾÍÊÇÔÚThinkPHP6ÖÐʵÏÖ¶àÓïÑÔÍøÕ¾µÄÒªÁ졣ͨ¹ý½ç˵¶àÓïÑÔ±äÁ¿¡¢Ê¹ÓÃÖÐÐļþÀ´ÉèÖÃSession¡¢Ê¹ÓöàÓïÑÔ·ÓɺÍÄ£°å±êÇ©¶Ô¶àÓïÑÔÄÚÈݾÙÐÐÊä³ö£¬ÎÒÃǾͿÉÒÔÇáËɵؽ¨ÉèÒ»¸öÍêÕûµÄ¶àÓïÑÔÍøÕ¾¡£ËäÈ»£¬ÔÚÏÖʵ¿ª·¢Öл¹ÐèҪ˼Á¿Ò»Ð©Ï¸½ÚÎÊÌ⣬µ«ÒÔÉÏÒªÁìΪThinkPHP6ÖоÙÐжàÓïÑÔ¿ª·¢ÌṩÁ˺ÜÊǺõĻù´¡¡£

ÒÔÉϾÍÊÇThinkPHP6ÖÐÔõÑùʵÏÖ¶àÓïÑÔÍøÕ¾£¿µÄÏêϸÄÚÈÝ£¬¸ü¶àÇë¹Ø×¢±¾ÍøÄÚÆäËüÏà¹ØÎÄÕ£¡

ÃâÔð˵Ã÷£ºÒÔÉÏչʾÄÚÈÝȪԴÓÚÏàÖúýÌå¡¢ÆóÒµ»ú¹¹¡¢ÍøÓÑÌṩ»òÍøÂçÍøÂçÕûÀí£¬°æȨÕùÒéÓë±¾Õ¾Î޹أ¬ÎÄÕÂÉæ¼°¿´·¨Óë¿´·¨²»´ú±í尊龙凯时人生就是博ÂËÓÍ»úÍø¹Ù·½Ì¬¶È£¬Çë¶ÁÕß½ö×ö²Î¿¼¡£±¾ÎĽӴýתÔØ£¬×ªÔØÇë˵Ã÷À´ÓÉ¡£ÈôÄúÒÔΪ±¾ÎÄÇÖÕ¼ÁËÄúµÄ°æȨÐÅÏ¢£¬»òÄú·¢Ã÷¸ÃÄÚÈÝÓÐÈκÎÉæ¼°ÓÐÎ¥¹«µÂ¡¢Ã°·¸Ö´·¨µÈÎ¥·¨ÐÅÏ¢£¬ÇëÄúÁ¬Ã¦ÁªÏµ尊龙凯时人生就是博ʵʱÐÞÕý»òɾ³ý¡£

Ïà¹ØÐÂÎÅ

ÁªÏµ尊龙凯时人生就是博

13452372176

¿É΢ÐÅÔÚÏß×Éѯ

ÊÂÇéʱ¼ä£ºÖÜÒ»ÖÁÖÜÎ壬9:30-18:30£¬½ÚãåÈÕÐÝÏ¢

QR code
sitemap¡¢ÍøÕ¾µØͼ