为表单元素分配不适当的操作

时间:2012-02-11 05:44:48

标签: php html kohana-3

在Kohana文档3.2中,ORM目录下有一个验证示例。让我来 重申一些与我的问题相关的代码:

<form action="<?= URL::site(**'/members'**); ?>" method="post" accept-charset="utf-8">
<label for="username">Username:</label>
<input id="username" type="text" name="username" value="<?= Arr::get($values, 'username'); ?>" />
<label for="username" class="error"><?= Arr::get($errors, 'username'); ?>

<label for="password">Password:</label>
<input id="password" type="password" name="password" value="<?= Arr::get($values, 'password'); ?>" />
<label for="password" class="error"><?= Arr::get($errors, 'password'); ?>

<label for="password_confirm">Repeat Password:</label>
<input id="password_confirm" type="password" name="_external[password_confirm]" value="<?= Arr::path($values, '_external.password_confirm'); ?>" />
<label for="password_confirm" class="error"><?= Arr::path($errors, '_external.password_confirm'); ?>

<button type="submit">Create</button>
</form>

然后它定义了一个控制器:

public function action_create()
{
    $view = View::factory(**'members/create'**)
    ->set('values', $_POST)
    ->bind('errors', $errors);

    if ($_POST)
    {
        $member = ORM::factory('member')
        // The ORM::values() method is a shortcut to assign many values at once
        ->values($_POST, array('username', 'password'));

        $external_values = array(
            // The unhashed password is needed for comparing to the password_confirm field
            'password' => Arr::get($_POST, 'password'),
        // Add all external values
        ) + Arr::get($_POST, '_external', array());
        $extra = Validation::factory($external_values)
        ->rule('password_confirm', 'matches', array(':validation', ':field', 'password'));

        try
        {
            $member->save($extra);
            // Redirect the user to his page
            $this->request->redirect('members/'.$member->id);
        }
        catch (ORM_Validation_Exception $e)
        {
            $errors = $e->errors('models');
        }
    }

    $this->response->body($view);
}

我的问题是为什么它指定&#39; /成员&#39;而不是&#39; / members / create&#39;行动 表单元素的属性?

1 个答案:

答案 0 :(得分:0)

这是一个错字。从3.1 form开始应始终指向您的路线。