帮助理解 PHP5 错误

发布于 2024-10-19 21:53:52 字数 1049 浏览 1 评论 0原文

简而言之......问题是......“说什么?”扩展...“我没有收到错误”

严格标准:非静态方法 Pyro\Template::preLoad() 不应静态调用,假设 $this 来自 /opt/lampp/htdocs/dc/pyro/app/controllers/admin/courses 中不兼容的上下文。 php 第 14 行

public function actionIndex() {
    $this->data->users = $this->DB->query("SELECT id, name, description FROM :@courses")->getAll();
    $this->data->title = 'Courses';
    $this->data->content_area = \Pyro\Template::preLoad('admin/courses/index', $this->data); // Line 14
}

模板...不完整...

<?php
namespace Pyro;

class Template {

    // Stores default master template
    public static $defaultTemplate = 'template.php';

    public function preLoad($template, $page) {
        ob_start();

        include( VIEWS . "{$template}.php");

        $buffer = ob_get_contents();
        @ob_end_clean();
        return $buffer;
    }

    public function load($page) {
        include( VIEWS . self::$defaultTemplate);
    }
}

为什么会出现这个错误?干杯

In short.. question is... "Say what?" To expand... "I don't get the error"

Strict Standards: Non-static method Pyro\Template::preLoad() should not be called statically, assuming $this from incompatible context in /opt/lampp/htdocs/dc/pyro/app/controllers/admin/courses.php on line 14

public function actionIndex() {
    $this->data->users = $this->DB->query("SELECT id, name, description FROM :@courses")->getAll();
    $this->data->title = 'Courses';
    $this->data->content_area = \Pyro\Template::preLoad('admin/courses/index', $this->data); // Line 14
}

Template... its incomplete...

<?php
namespace Pyro;

class Template {

    // Stores default master template
    public static $defaultTemplate = 'template.php';

    public function preLoad($template, $page) {
        ob_start();

        include( VIEWS . "{$template}.php");

        $buffer = ob_get_contents();
        @ob_end_clean();
        return $buffer;
    }

    public function load($page) {
        include( VIEWS . self::$defaultTemplate);
    }
}

Why does this error appear? Cheers

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(4

迷路的信 2024-10-26 21:53:52

那么 preLoad 函数不是静态的。这意味着只有 Template 类的对象可以使用此方法。静态方法独立于类的任何对象而存在。

Template::preLoad 是静态调用:您没有创建 Template 对象,然后调用 preLoad 方法。所以基本上,你有两个解决方案:

  • 使 preLoad 静态;
  • 创建一个Template对象,然后调用它的preLoad函数。

Well the preLoad function is not static. Which means only an object of the class Template can use this method. A static method exists indepedently of any object of the class.

Template::preLoad is a static call : you didn't create a Template object, then call the preLoad method. So basically, you've got two solutions :

  • Making preLoad static;
  • Creating a Template object, and then call its preLoad function.
梦回旧景 2024-10-26 21:53:52

preLoad 函数应该是静态的

public static function preLoad($template, $page) {

preLoad function should be static

public static function preLoad($template, $page) {
永不分离 2024-10-26 21:53:52

preLoad 函数不是静态的。 ti 应该看起来像这样:

public static function preLoad($template, $page) {
        ob_start();

        include( VIEWS . "{$template}.php");

        $buffer = ob_get_contents();
        @ob_end_clean();
        return $buffer;
    }

preLoad function isn't static. ti should look like this:

public static function preLoad($template, $page) {
        ob_start();

        include( VIEWS . "{$template}.php");

        $buffer = ob_get_contents();
        @ob_end_clean();
        return $buffer;
    }
因为看清所以看轻 2024-10-26 21:53:52

正如大家所说,您将函数作为静态方法调用:

Template::preLoad(xxx)

:: 在 PHP 中表示静态。函数通常被称为静态 :: 或对象 -> 调用。

函数定义是其中之一:

public static function preLoad($template, $page)

调用方式如下: Template::preLoad('admin/courses/index', $this-> ;data);

OR

public function preLoad($template, $page)

调用方式类似于 Template->preLoad('admin/courses/index ', $this->data);

作为参考,静态函数无需实例化对象即可调用。如果您的函数不需要对象来运行,您可以将其设为静态。基本上,这意味着您无法在静态方法中引用 $this。它将使用给定的输入运行,而无需构造对象。

Like everyone said, the you called the function with as a static method:

Template::preLoad(xxx)

The :: means static in PHP. Functions are typically called as static :: or object -> calls.

The function definition is one or the other:

public static function preLoad($template, $page)

Called like: Template::preLoad('admin/courses/index', $this->data);

OR

public function preLoad($template, $page)

Called like Template->preLoad('admin/courses/index', $this->data);

For reference, a static function is able to be called without instantiating an object. If your function doesn't need an object to run, you could make it static. Basically, this means you can't reference $this in a static method. It will run with the given inputs without having to construct the object.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文