0

我需要编辑某人的网站。我需要做的是更改标题。这听起来很容易,但事实并非如此(至少对我而言)。这是相关行的样子:

<title><?php echo Header::instance()->title; ?></title>
  1. 第一部分是Header::什么?我以前从未见过。
  2. 在其他文件上,我看到了:

    <h1 class="title"><?php echo $serial->name; ?></h1>
    

    那是用来显示序列名的。我想用它作为上面的标题,但它说“未定义的变量:串行”。

我该如何改变呢?

4

3 回答 3

0

You're editing a website made in : the header of the page (which should control headers, title and meta I guess) is controlled by a class named Header, which has an instance (get by instance()) and the <title> content is store in its title attribute.

The same scenario occured for the <h1>: an object, stored in the $serial variable has an attribute name which contains the name of the current page.

TL;DR

  • To change the website title, search the Header class and edit the title attribute.
  • To change the name of a page, find the right controller which generate the page and change its name attribute
于 2013-08-08T20:34:46.207 回答
0

First block of code (#1) means that you are calling static instance() method of Header class which returns an object containing title property, which is echoed.

Second one echoes name property of $serial object. Thing is, how that variable is passed to the view - you can call static method of any class (#1) anywhere you want, at least when the class is loaded or you have autoloader set up. I assume that view file is require_once()'d or simply in the same file, in that case you need to check where (if anywhere) $serial variable is set and what value it contains.

If you provide more code, I can tell you more things. :)

于 2013-08-08T20:34:56.023 回答
0

该类很可能Header被设置为单例。单例是一种设计模式,它只允许一个类的一个实例存在。在 PHP 中,这是通过将__construct方法创建为受保护方法或私有方法来完成的。methid::instance()是一个公共静态方法。因为是静态的,不需要实例化对象就可以调用,静态方法构造了Header。因为该方法是类的一部分,所以它可以访问私有或公共构造函数。在此处查看示例:

在 PHP5 中创建单例设计模式

简单地::告诉 PHP 你调用了一个静态方法。instance()返回一个实例HeaderHeader包含一个名为 title 的公共属性,然后用 PHP 回显该属性。

错误的第二个问题。$serial 可能没有在您的代码中定义。

于 2013-08-08T20:35:29.313 回答