私は2つのコントローラaccount.phpとaddress.phpを同じディレクトリのAPP /コントローラに持っています。最初のコントローラaccount.phpでは、私はURIのためのデフォルトルータを使用します:account/create、account/login、account/logout ... 2番目のコントローラを書くとき、私はaddress//。ここからわかるように、私は同じ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);
}
OKのようですが、ルータのアカウント/アドレス/作成が機能していません。 KohanaはそのURIの404メッセージをスローします。
なぜそれが起こるのか知っていますか?
恐ろしい男、それを最優先に入れます。そして、はい、あなたは正しいです、代わりにモデルで検証する必要があります、それは私たちのコントローラがきれいに見えるように見えるようになります。 – lnguyen55