0

我的库中有类和一组方法。

类名称为 classA ,其方法调用 generateCSS 方法。在这些函数中,已经定义了一些元标记集。现在我想向现有函数 generateCSS 添加更多元标记。同样,这些过度骑行不应该干扰现有的功能 generateCSS 我也希望在该 generateCSS 功能中使用我的新元标记。

这里每一个访问 generateCSS 方法。所以我的新元标记更改也应该反映在这一点上。

class classb extends classa{

    public function add_generateCSS (){
        parent::generateCSS();      
        return $html = "<script src='new.js'></script>";
    }   
}
4

1 回答 1

1

I'm not completely sure if I understood the question right, but I think you are looking for this:

class classb extends classa{

  public function add_generateCSS (){
    $html = parent::generateCSS();      
    return $html . "<script src='new.js'></script>";
  }   
}

You were calling the generateCSS() method on the parent and then disposing the result immediately. You should save that result in a variable and concatenate your additional code to it. Then return that.

于 2013-07-13T13:29:42.273 回答