Zend Framework 2 - Zend\Mvc outer\Http\Part - تكوين الوحدة
-
12-12-2019 - |
سؤال
أقوم بإنشاء تطبيق متعدد اللغات باستخدام ZF2..ولا يمكن تحديد كيفية إضافة عنوان URL للجزء الذي سيشكل أساس كل عنوان URL بغض النظر عن الوحدات النمطية.
http://localhost/en/us/application/index/index/
أنا أفهم تماما كيفية تكوين /[:namespace[/:controller[/:action]]]
باستخدام دي
http://localhost/application/index/index/
http://localhost/guestbook/index/index/
http://localhost/forum/index/index/
ما لا أفهمه هو كيفية تكوين أ جزء الطريق الذي سيكون الأساس لجميع الطرق..في ZF1 اعتدت تسلسل الطريق لتحقيق هذا..
لذلك أنا بحاجة إلى تكوين أ جزء طريق /[:lang[/:locale]]
الذي ينطبق على الموقع بالكامل ثم يسمح للوحدة بالتكوين /[:namespace[/:controller[/:action]]]
أو أي طريق آخر ضروري..
http://localhost/en/us/application/index/index/
http://localhost/zh/cn/application/index/index/
http://localhost/en/uk/forum/index/index/
المحلول
أعتقد أن ما تبحث عنه هو child_routes
مفتاح التكوين.نلقي نظرة على كيف يقوم ZfcUser بتكوين التوجيه (هنا):يقوم بإنشاء مسار حرفي أساسي (/ مستخدم) ثم يربط المسارات الفرعية (/ مستخدم/تسجيل الدخول، وما إلى ذلك) به عبر child_routes
مجموعة مصفوفة.
أعتقد أن شيئًا كهذا سيفي بالغرض بالنسبة لك:
'router' => array(
'routes' => array(
'myapp' => array(
'type' => 'Segment',
'options' => array(
'route' => '/[:lang[/:locale]]',
'defaults' => array(
'lang' => 'en',
'locale' => 'us',
),
),
'may_terminate' => false,
'child_routes' => array(
'default' => array(
'type' => 'Segment',
'options' => array(
'route' => '/[:controller[/:action]]',
'constraints' => array(
'controller' => '[a-zA-Z][a-zA-Z0-9_-]*',
'action' => '[a-zA-Z][a-zA-Z0-9_-]*',
),
'defaults' => array(
'controller' => 'index',
'action' => 'index',
),
),
),
),
),
),
ثم في وحدة التحكم الخاصة بك يمكنك القيام بذلك للحصول على اللغة والإعدادات المحلية:
$this->params()->fromRoute('lang');
$this->params()->fromRoute('locale');