동일한 컨트롤러 APP/컨트롤러에 account.php와 address.php 컨트롤러가 2 개 있습니다. 첫 번째 컨트롤러 인 account.php의 경우 다음과 같이 URI에 대한 기본 라우터를 사용합니다. account/create, account/login, account/logout ... 두 번째 컨트롤러를 작성할 때 account.add와 함께 address.php의 모든 URI를 사용하고 싶습니다. /. 여기에서 볼 수 있듯이 계정 컨트롤러와 일치하는 동일한 URI 라우터를 사용하고 있습니다.Kohana 3.2 접두어 URI가있는 컨트롤러 용 라우터는 다른 컨트롤러에 속합니다.
내 첫 번째 방법 :
// Add new address
Route::set('address', 'account/address/<action>')
->defaults(array(
'controller' => 'address',
'action' => 'index',
));
내 주소 컨트롤러는
public function before()
{
parent::before();
if (! Auth::instance()->logged_in())
{
// Redirect to a login page (or somewhere else).
$this->request->redirect('');
}
}
// nothing here
public function action_index()
{
$this->request->redirect('');
}
// create account
public function action_create()
{
// Create an instance of a model
$profile = new Model_Address();
// received the POST
if (isset($_POST) && Valid::not_empty($_POST))
{
// // validate the form
$post = Validation::factory($_POST)
->rule('firstname', 'not_empty')
->rule('lastname', 'not_empty')
->rule('address', 'not_empty')
->rule('phone', 'not_empty')
->rule('city', 'not_empty')
->rule('state', 'not_empty')
->rule('zip', 'not_empty')
->rule('country', 'not_empty')
->rule('primary_email_address', 'email');
// if the form is valid and the username and password matches
if ($post->check())
{
if($profile->create_profile($_POST))
{
$sent = kohana::message('profile', 'profile_created');
}
} else {
// validation failed, collect the errors
$errors = $post->errors('address');
}
}
// display
$this->template->title = 'Create new address';
$this->template->content = View::factory('address/create')
->bind('post', $post)
->bind('errors', $errors)
->bind('sent', $sent);
}
이 확인 될 것으로 보인다하지만, 라우터 계정/주소/작동하지 않습니다 만듭니다. Kohana는 해당 URI에 대해 404 메시지를 발생시킵니다.
왜 이런 일이 발생하는지 알고 계십니까?
굉장한 남자, 최우선 순위에 넣는 것이 트릭입니다. 그리고 네, 맞습니다. 유효성 검사가 모델에 대신 있어야합니다. 그러면 컨트롤러가 깨끗하고 읽기 쉽게 보이게됩니다. – lnguyen55