【问题标题】:CodeIgniter access parent function variableCodeIgniter 访问父函数变量
【发布时间】:2011-06-08 11:07:21
【问题描述】:

我制作了一个将文件添加到 zip 的脚本(经过大量解析等),我有这个功能:

function _add_file($command)
{
    if (!isset($command["source"]) || !isset($command["dest"])) {
        return;
    }

    if (!get_file_info("files/".$command["source"])) {
        return;
    }

    $zip->addFile("files/".$command["source"], $command["destination"]);
}

它给出了一个错误,因为 $zip 没有在 _add_file 中定义。如何让 _add_file 访问调用它的函数中定义的 $zip(没有_add_file($command, $zip))?

【问题讨论】:

    标签: php codeigniter variables scope parent


    【解决方案1】:

    将其设为类变量var $zip 并使用$this->zip 访问它

    【讨论】:

    • 解析错误:语法错误,意外的 T_VAR?我明白你的意思,但现在由于某种原因它不起作用。
    • 我正要写一个长更新 :) 很高兴你修好了它。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2016-11-08
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2016-03-16
    • 2011-06-23
    • 2012-01-13
    相关资源
    最近更新 更多