首页 > PHP资讯 > PHP培训技术 > Kohana视图View使用(如何加载视图,传递变量)

Kohana视图View使用(如何加载视图,传递变量)

PHP培训技术

差点混淆了,看了半天,原来主要有两个控制器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');            }        }    }}

PHP培训技术

本文由欣才IT学院整理发布,未经许可,禁止转载。
支持41不支持0