Thanx писал(а):assign_vars
s
лишняя появиласьВ остальном всё так
Код: Выделить всё
class listener implements EventSubscriberInterface
{
/**
* Constructor
*/
public function __construct(\phpbb\template\template $template)
{
$this->template = $template;
}
/**
* Assign functions defined in this class to event listeners in the core
*
* @return array
* @static
* @access public
*/
static public function getSubscribedEvents()
$request
, ни $this->request
не заданоКеш-кеш-кеш. Не видит движок изменений вThanx писал(а):Опять белый экран
.yml
без физочистки кешаКод: Выделить всё
public function sCode($event)
{
$string = request->server('REQUEST_URI');
echo $string;
}
Код: Выделить всё
public function sCode($event)
{
$string = $this->request->server('REQUEST_URI');
echo $string;
}
sevices.yml
и через конструктор в слушателе переменную подключили?"Сломает" всю вёрстку и "наполнит" форум кракозябрамиThanx писал(а):echo $string;
$this->temlate->assign_var(s)
Код: Выделить всё
services:
fofo.mytest.listener:
class: fofo\mytest\event\listener
arguments:
- @string
Код: Выделить всё
class listener implements EventSubscriberInterface
{
/**
* Constructor
*/
public function __construct(\phpbb\template\template $string)
{
$this->string = $string;
}
Код: Выделить всё
arguments:
- @string
Надо объявитьThanx писал(а):Код: Выделить всё
arguments: - @string
request
, а вы string
какой-то объявляете (которого вообще в phpBB нет)будет уже неThanx писал(а):__construct(\phpbb\template\template
\phpbb\template\template
, а \phpbb\request\request
(это задаётся путь к файлу, содержащему класс request)Код: Выделить всё
services:
acme.demo.controller:
class: acme\demo\controller\main
arguments:
- @config
- @controller.helper
- @template
- @user
acme.demo.listener:
class: acme\demo\event\main_listener
arguments:
- @controller.helper
- @template
tags:
- { name: event.listener }
controller
, надо сначала этот класс создать (а для нескольких строк кода он не нужен)Код: Выделить всё
/index.php?sid=a304cebd547d145a466ea2076dc067f7
Код: Выделить всё
static public function getSubscribedEvents()
{
return array(
'core.index_modify_page_title' => 'sCode',
'core.overall_header_content_before' => 'artHeader',
);
}
Код: Выделить всё
public function artHeader($event)
{
$this->template->assign_var('ART_HEADER', $this->request->server('REQUEST_URI'));
}
Код: Выделить всё
<?
namespace fofo\mytest\event;
use Symfony\Component\EventDispatcher\EventSubscriberInterface;
class listener implements EventSubscriberInterface
{
/**
* Assign functions defined in this class to event listeners in the core
*
* @return array
* @static
* @access public
*/
static public function getSubscribedEvents()
{
return array(
'core.index_modify_page_title' => 'sCode',
'core.overall_header_content_before' => 'artHeader',
);
}
public function __construct(\phpbb\request\request $request)
{
$this->request = $request;
}
public function sCode($event)
{
echo $this->request->server('REQUEST_URI');
}
public function artHeader($event)
{
echo $this->request->server('REQUEST_URI');
}
}
?>
Код: Выделить всё
'core.viewforum_get_topic_data' => 'artHeader',
Код: Выделить всё
/viewforum.php?f=3
Код: Выделить всё
public function artHeader($event)
{
echo $this->request->server('REQUEST_URI');
$this->template->assign_var('ART_HEADER', $this->request->server('REQUEST_URI'));
}
Естественно.Thanx писал(а):Видимо, нужно переменную template объявлять