帮助理解 PHP5 错误 [英] Help understanding PHP5 error
问题描述
简而言之……问题是……说什么?"展开...我没有收到错误信息"
In short.. question is... "Say what?" To expand... "I don't get the error"
严格标准:非静态方法 Pyro\Template::preLoad() 不应静态调用,假设 $this 来自/opt/lampp/htdocs/dc/pyro/app/controllers/admin/courses 中的不兼容上下文.php 第 14 行
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
推荐答案
preLoad 函数不是静态的.这意味着只有类 Template 的对象才能使用此方法.静态方法独立于类的任何对象.
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 是静态调用:您没有创建 Template 对象,然后调用了 preLoad 方法.所以基本上,你有两个解决方案:
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 :
- 使 preLoad 成为静态;
- 创建一个 Template 对象,然后调用它的 preLoad 函数.
这篇关于帮助理解 PHP5 错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!