收藏本站 Archiver
    请 后使用快捷导航
    没有账号?入住 CI 中国社区
    查看: 7018|回复: 5

    CodeIgniter 模型的一个特点

    [复制链接]
    楼主
    发表于 2007年10月15日 13:28:52 | 只看该作者 回帖奖励 |倒序浏览 |
    反复调用
    $this->load->model("someModel");
    $this->load->model("someModel");
    $this->load->model("someModel");
    model 函数有规避机制,即仅调用一次。
    沙发
    发表于 2007年11月9日 18:31:20 | 只看该作者

    ding !!!!!!!!!!!!!!

    多发一点啊......
    藤椅
    楼主| 发表于 2007年11月9日 21:19:37 | 只看该作者
    呵呵,一定多发!
    不过还需要大家一起努力啊!
    板凳
    发表于 2013年9月5日 18:28:57 | 只看该作者
    飘过。
    。。。
    报纸
    发表于 2013年9月7日 21:20:23 | 只看该作者
    本帖最后由 phper08 于 2013年9月7日 21:24 编辑

    public function model($model, $name = '', $db_conn = FALSE)
    {
    if (is_array($model))
    {
    foreach ($model as $babe)
    {
    $this->model($babe);
    }
    return;
    }

    if ($model == '')
    {
    return;
    }

    $path = '';

    // Is the model in a sub-folder? If so, parse out the filename and path.
    if (($last_slash = strrpos($model, '/')) !== FALSE)
    {
    // The path is in front of the last slash
    $path = substr($model, 0, $last_slash + 1);

    // And the model name behind it
    $model = substr($model, $last_slash + 1);
    }

    if ($name == '')
    {
    $name = $model;
    }

    if (in_array($name, $this->_ci_models, TRUE))
    {
    return;
    }

    $CI =& get_instance();
    if (isset($CI->$name))
    {
    show_error('The model name you are loading is the name of a resource that is already being used: '.$name);
    }

    $model = strtolower($model);

    foreach ($this->_ci_model_paths as $mod_path)
    {
    if ( ! file_exists($mod_path.'models/'.$path.$model.'.php'))
    {
    continue;
    }

    if ($db_conn !== FALSE AND ! class_exists('CI_DB'))
    {
    if ($db_conn === TRUE)
    {
    $db_conn = '';
    }

    $CI->load->database($db_conn, FALSE, TRUE);
    }

    if ( ! class_exists('CI_Model'))
    {
    load_class('Model', 'core');
    }

    require_once($mod_path.'models/'.$path.$model.'.php');

    $model = ucfirst($model);

    $CI->$name = new $model();

    $this->_ci_models[] = $name;
    return;
    }

    // couldn't find the model
    show_error('Unable to locate the model you have specified: '.$model);
    }
    地板
    发表于 2013年9月7日 21:28:43 | 只看该作者
    所谓的规避机制就是把类名放到一个数组里吧
    返回列表
    您需要登录后才可以回帖 登录 | 入住 CI 中国社区

    本版积分规则

    AltStyle によって変換されたページ (->オリジナル) /