I 조언 당신은 규칙의 충돌을 피하기 위해 URL을 일부 식별 값을 추가 할 수 있습니다. 예를 들어 user '/ login', 'user/logout', 'user/register', 'user/change-password'등의 접두어 'user'아래 관련된 모든 'user' zfcuser 모듈에서 사용됨).
우리는/user/profile/: user와 같은 url을 만들 것입니다. 여기서 : user 부분은 url의 동적 부분입니다. UserController로 응답합니다 응용 프로그램을 config (설정)이 경로를 사용하여
'router' => array(
'routes' => array(
// other routes configs here
'user' => array(
'type' => 'Literal',
'priority' => 1000,
'options' => array(
'route' => '/user',
'defaults' => array(
'__NAMESPACE__' => 'Application\Controller',
'controller' => 'User',
'action' => 'index',
),
),
'may_terminate' => true,
'child_routes' => array(
'profile' => array(
'type' => 'Segment',
'options' => array(
'route' => '/profile/:user',
'defaults' => array(
'action' => 'profile',
),
),
),
),
),
(이름이 다른 경우 코드가 아래에 변경이 필요합니다)
는 당신이 응용 프로그램 모듈에서 작업하는 가정하고 작성하고 UserController을 등록 :: url/user가 호출 될 때의 인덱스. /user/profile/someuser가 호출 될 때 UserController :: profile로 응답합니다.
우리가 규칙에서 말했기 때문에 someuser 부분은 필수 항목입니다.
$this->params()->fromRoute('user')
에 따라 같은이 단지 당신이 할 수있는 솔루션 중 하나 인 사용자 값 : 그렇지 필수하려면 우리는 같은 규칙이 당신을 취할 수있는 UserController의 프로필 작업
'route' => '/profile/[:user]',
에 따라 작성해야 예를 들어, 다음과 같은 자녀 경로없이 규칙을 작성할 수 있습니다.
'user' => array(
'type' => 'Segment',
'options' => array(
'route' => '/user/profile/:user',
'defaults' => array(
'__NAMESPACE__' => 'Application\Controller',
'controller' => 'User',
'action' => 'profile',
),
),
),
귀하의 요구에 맞는 솔루션을 선택하는 것은 귀하의 책임입니다. ZF2 official routing documentation도 읽으십시오.
내 퀵 스타트를 다시 읽어보십시오. [제 5 장 - 라우팅 이해] (https : // github.com/manuakasam/ZF2_3_QuickStart_Rewrite/pull/12/files) – Sam