使用Kohana 3.3 RC3,KOstache和小胡子似乎生成变量的类多次运行。
因此,如果我执行以下操作,它将显示“这是一个文本”十次。
查看型号:
public function page()
{
$page = 'This is a text';
print_r($page);
return $page;
}
修改
这是完整的视图模型
class View_Admin_Pages_Edit extends View_Admin {
// Page title
public function page_title()
{
return i18n::get('Page edit');
}
/**
* Edit page
*
*
* @param string $type (error or success)
* @param string $description
* @param bool $state
*/
public function page()
{
// Check if fom was submitted and has only been run once
if (Request::current()->post())
{
$this->processed = TRUE;
$page = Model::factory('page');
// Get ready to validate data
$post = $page->validate(Request::current()->post());
if ($post->check())
{
// Try to save data
$rows = $page->update((int)$this->page_id, $post);
// Success message
$this->notice('success', __('Page saved'));
// Redirect to avoid back button problem
Controller::redirect('/admin/pages/list');
}
// Validation failed. Generate error message
$errors = $post->errors('post');
foreach ($errors AS $title => $description)
{
$this->notice('error', $description);
}
// Save $_POST data so it is available after the redirect
$_SESSION['post'] = Request::current()->post();
// Redirect to avoid back button problem
Controller::redirect('/admin/pages/edit/'.(int)$this->page_id);
}
else
{
if (isset($_SESSION['post']))
{// Get saved $_POST data to fill out form
$page = $_SESSION['post'];
unset($_SESSION['post']);
}
else
{// Get data from model to fill out form
$page = Model::factory('page')->get_page_id((int)$this->page_id);
}
// Setup status dropdown
$status = array(
2 => 'Active',
1 => 'Not in navigation but activated',
0 => 'Disabled',
);
$page['status'] = $this->_select_list($status, $page['status']);
// Setup template dropdown
$template = array(
'default' => 'Default',
);
$page['template'] = $this->_select_list($template, $page['template']);
print_r($page);
return $page;
}
}
} // End View_Admin_Pages_Edit