日期:2014-05-17  浏览次数:20496 次

刚刚看了几个推荐框架的帖子,蛮多推荐codeigniter的,请恕我直言,那框架实在不敢恭维啊~个人意见,仅供参考。
首先我是用过codeigniter的,刚开始学框架的时候用过一阵子,然后后来公司用thinkphp,就没再用了,用了2个之后,就会有一些对比性。首先这2个框架文件夹容量都比较大,称不上轻量级之类的,我都不怎么看好。
今天单说codeigniter框架
举个官网控制器调用模板的例子
<?php
class Blog extends CI_Controller {

 function index()
 {
  $data['title'] = "My Real Title";
  $data['heading'] = "My Real Heading";
  
  $this->load->view('blogview', $data);
 }
}
?> 

<html>
<head>
<title><?php echo $title;?></title>
</head>
<body>
 <h1><?php echo $heading;?></h1>
</body>
</html>


感觉这种模式很不好,难道这就是传说中的控制器模板分离?这种模式只能忽悠刚刚入门的那些PHPer,先不论调用smarty之类的来反驳我,只是说他的自身特性,而且什么框架都能结合smarty来用。

以上的代码用PHP的一个函数就能实现了,请查阅extract函数的用法。

很多用codeigniter的PHPer估计就是冲着所谓写法优美去的,可以用连贯写法-> ->

究其实质,并没有对模板(视图)产生有多大的作用,

只是把变量全部先计算出来,换个名称,再在需要的时候,把新名称填入到所需地方。

然后个人在国外网站闲逛的时候呢,发现一个模板,它和codeigniter的这种模式有很大的相似性。模板名未知,就叫他template吧。你们可以看看,就可以对codeigniter原理有大致的了解吧

它的核心模板代码我写一下
<?php
//template.php
/**
 * Copyright (c) 2003 Brian E. Lozier (brian@massassi.net)
 *
 * Permission is hereby granted, free of charge, to any person obtaining a copy
 * of this software and associated documentation files (the "Software"), to
 * deal in the Software without restriction, including without limitation the
 * rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
 * sell copies of the Software, and to permit persons to whom the Software is
 * furnished to do so, subject to the following conditions:
 *
 * The above copyright notice and this permission notice shall be included in
 * all copies or substantial portions of the Software.
 *
 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
 * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
 * IN THE SOFTWARE.
 */

class Template {
var $vars; /// Holds all the template variables
var $path; /// Path to the templates

/**
 * Constructor
 *
 * @param string $path t