作者:mobiledu2502924857 | 来源:互联网 | 2014-03-27 00:19
差点混淆了,看了半天,原来主要有两个控制器Controller和Controller_Template,这两者加载视图,传递变量是不同的,前者:<?phpclassControll
差点混淆了,看了半天,原来主要有两个控制器Controller和Controller_Template,这两者加载视图,传递变量是不同的,
前者:
find_all();
$view = View::factory('test/index');
$view->category = $category;
if($_POST)
{
$artile = ORM::factory('article')->values($_POST);
$vali = Validation::factory($_POST, '_external', array());
try{
$artile->save($vali);
}
catch (ORM_Validation_Exception $e)
{
$view->errors = $e->errors('models');
}$this->response->body($view);
}
}
}
后者:
*/
class Controller_Test extends Controller_Template{
public $template = 'test/index';
public function action_index()
{
$category = ORM::factory('category')->find_all();
$this->template->category = $category;
if($_POST)
{
$artile = ORM::factory('article')->values($_POST);
$vali = Validation::factory($_POST, '_external', array());
try{
$artile->save($vali);
}
catch (ORM_Validation_Exception $e)
{
$this->template->errors = $e->errors('models');
}
}
}
}