CodeIgniter 源码解读之视图
视图 控制器及模型都讲完了,这篇,顺理成章的可以讲讲视图类,从此,MVC三剑客,都凑齐了。 接着模型中提到的例子,我在控制器里调用了视图 view 方法,并在 application/views 目录中新建了对应的视图文件。 我们现在研究一下视图加载的原理: <?php defined ( 'BASEPATH' ) OR exit ( 'No direct script access allowed' ) ; class Test extends CI_Controller { public function __construct ( ) { parent : : __construct ( ) ; $this - > load - > model ( 'Test_model' ) ; } public function index ( ) { $data [ 'title' ] = $this - > Test_model - > list ( ) ; # 调用load 中的 view 方法,并将 $data 数组传递给他 $this - > load - > view ( 'test_view' , $data ) ; } } 现在将目光转向 Loader 中的view方法: # 这里的 view 方法很简单 public function view ( $view ,