我正在使用 kohana 3.3 和 kostache。请帮我解决这个问题。如何将错误传递给视图。
控制器
public function action_add()
{
$renderer = Kostache_Layout::factory();
$view = new View_Pages_Album_List();
try
{
$album = ORM::factory('Album_Information');
$album_name = $this->request->post('inputAlbum');
$artist = $this->request->post('inputArtist');
$album->Album_Name = $album_name;
$album->Artist = $artist;
$album->save();
}
catch (ORM_Validation_Exception $e)
{
$errors = $e->errors('models');
$view->errors = $errors;
}
$this->response->body($renderer->render($view));
}
模板文件
<h3>Add A New Album</h3>
<form method="POST" action="album/add">
<label>Album Name:</label>
<input type="text" name="inputAlbum" /><br />
<label>Artist:</label>
<input type="text" name="inputArtist" /><br />
<input type="submit" name="submit" value="Add" />
</form>
{{errors}}
规则..
public function rules()
{
return array(
'inputAlbum' => array(
array('not_empty'),
),
'inputArtist' => array(
array('not_empty'),
),
);
}
留言..
<?php defined('SYSPATH') or die('No Direct Script Access');
return array(
'not_empty' => ':field must not be empty',
);
每次我单击提交按钮时,我都没有收到任何错误。我得到的是数组到字符串的转换问题。