我不。了解我的代码中的错误在哪里。但我认为在init()
功能上!
var_dump ($this->newsType());
No method or closure named "my" was found in the NewsStream class and its behaviors.
这是 NewsStream.php(小部件类)
public function init()
{
$data = [
'content' => [],
'error' => 'Модуль отключен.',
];
if (config('news_stream.allow') == 0) {
$data = cache()->get(CacheNames::NEWS_STREAM);
if ($data === false) {
$data = [];
try {
// Подключаюсь к БД
$this->db = Yii::createComponent([
'class' => 'CDbConnection',
'connectionString' => 'mysql:host=127.0.0.1;port=3306;dbname=la2worldweb',
'enableProfiling' => YII_DEBUG,
'enableParamLogging' => true,
'username' => 'root',
'password' => 'xdemonx1234',
'charset' => 'utf8',
'emulatePrepare' => true,
'tablePrefix' => 'ghtweb',
]);
app()->setComponent('NewsStreamDb', $this->db);
$newsType = config('news_types.type');
if (method_exists($this, $newsType)) {
$data['content'] = $this->$newsType();
foreach ($data['content'] as $k => $v) {
$data['content'][$k]['id'] = $this->getNewsLink($v['id']);
$data['content'][$k]['title'] = $this->getNewsTitle($v['title']);
$data['content'][$k]['updated_at'] = $this->getLastDate($v['updated_at']);
$data['content'][$k]['user_id'] = $this->getAuthorId($v['author_id']);
}
if (30) {
cache()->set(CacheNames::NEWS_STREAM, $data, 30 * 60);
}
} else {
$data['error'] = 'Метод для обработки форума не найден.';
}
} catch (Exception $e) {
$data['error'] = $e->getMessage();
}
}
}
app()->controller->renderPartial('//news_stream', $data);
}
这是该小部件的调用
<div class="icon" id="icon_blue1"></div>
<div class="line_blue">
<h1 class="line">Новости </h1>
<?php $this->widget('app.widgets.NewsStream.NewsStream') ?>
</div>
这是捕捉错误