<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:dc="http://purl.org/dc/elements/1.1/">
			<channel>
			<title>Передать объект через хук / Вопросы, проблемы и их решения / Alto CMS</title>
			<link>http://79.174.14.219/comments/527/</link>
			<description><![CDATA[Добрый вечер, дорогие друзья. Сразу же прошу прощения за не очень хорошее поведение прошлым летом. Не передается объект $oTopic через]]></description>
			<language>ru</language>
			<managingEditor>noreply@altocms.ru</managingEditor>
			<webMaster>noreply@altocms.ru</webMaster>
			<generator>Alto CMS v.1.5.0b1</generator>
							<item>
					<title>Передать объект через хук (comment #8648)</title>
					<guid isPermaLink="true">http://79.174.14.219/t/527/#comment8648</guid>
					<link>http://79.174.14.219/527.html#comment8648</link>
					<author>s@dtkp.ru</author>
					<description><![CDATA[Уверен, что немного подробностей не помешают.]]></description>
					<pubDate>Mon, 03 Mar 2014 22:03:06 +0400</pubDate>
									</item>
							<item>
					<title>Передать объект через хук (comment #8665)</title>
					<guid isPermaLink="true">http://79.174.14.219/t/527/#comment8665</guid>
					<link>http://79.174.14.219/527.html#comment8665</link>
					<author>grigor.smirnow7@yandex.ru</author>
					<description><![CDATA[Экшн топика, add.tpl. Вызывается хук. В хуке нужно определить объект oTopic, раз уж в шаблоне это не сделать.]]></description>
					<pubDate>Tue, 04 Mar 2014 14:31:41 +0400</pubDate>
									</item>
							<item>
					<title>Передать объект через хук (comment #8669)</title>
					<guid isPermaLink="true">http://79.174.14.219/t/527/#comment8669</guid>
					<link>http://79.174.14.219/527.html#comment8669</link>
					<author>andreyv@gladcode.ru</author>
					<description><![CDATA[Шаблон add.tpl вызывается в двух случаях — при создании топика и при его редактировании.<br/>
 — При редактировании топика переменная-объект oTopic существует и ее можно использовать как угодно.<br/>
 — При <u>создании</u> топика этой переменной нет, поскольку нет еще самого топика — он не сохранен. Получить этот объект вы не сможете ни каким образом по причине его отсутствия.<br/>
<br/>
Я что-то не так понял?]]></description>
					<pubDate>Tue, 04 Mar 2014 14:58:09 +0400</pubDate>
									</item>
							<item>
					<title>Передать объект через хук (comment #8699)</title>
					<guid isPermaLink="true">http://79.174.14.219/t/527/#comment8699</guid>
					<link>http://79.174.14.219/527.html#comment8699</link>
					<author>grigor.smirnow7@yandex.ru</author>
					<description><![CDATA[Нет, все так поняли. Но при редактировании она не доступна! Сами попробуйте.]]></description>
					<pubDate>Wed, 05 Mar 2014 17:51:31 +0400</pubDate>
									</item>
							<item>
					<title>Передать объект через хук (comment #8709)</title>
					<guid isPermaLink="true">http://79.174.14.219/t/527/#comment8709</guid>
					<link>http://79.174.14.219/527.html#comment8709</link>
					<author>s@dtkp.ru</author>
					<description><![CDATA[Вы что-то не так делаете, ибо вот содержимое объекта $oTopic типа ModuleTopic_EntityTopic при вызове метода EventEdit() при редактировании топика.<br/>
<pre class="prettyprint"><code>CLASSNAME   string	&quot;ModuleTopic_EntityTopic&quot;	
aExtra	    array[5]		
aValues	    boolean	0	
_aData	    array[39]		
aValidateRules	array[8]		
aValidateErrors	array[0]		
sValidateScenario	string	&quot;&quot;</code></pre><br/>
<br/>
Посмотрите в любой IDE через xdebug.]]></description>
					<pubDate>Wed, 05 Mar 2014 20:43:41 +0400</pubDate>
									</item>
							<item>
					<title>Передать объект через хук (comment #8722)</title>
					<guid isPermaLink="true">http://79.174.14.219/t/527/#comment8722</guid>
					<link>http://79.174.14.219/527.html#comment8722</link>
					<author>grigor.smirnow7@yandex.ru</author>
					<description><![CDATA[Мне надо узнать логин текущего юзера. Как это сделать в экшне редактирования топика?]]></description>
					<pubDate>Thu, 06 Mar 2014 17:32:50 +0400</pubDate>
									</item>
							<item>
					<title>Передать объект через хук (comment #8723)</title>
					<guid isPermaLink="true">http://79.174.14.219/t/527/#comment8723</guid>
					<link>http://79.174.14.219/527.html#comment8723</link>
					<author>andreyv@gladcode.ru</author>
					<description><![CDATA[В экшене:<br/>
<pre class="prettyprint"><code>$sLogin = $this-&gt;oUserCurrent-&gt;getLogin();</code></pre><br/>
<br/>
В шаблоне экшена:<br/>
<pre class="prettyprint"><code>{$oUserCurrent-&gt;getLogin()}</code></pre>]]></description>
					<pubDate>Thu, 06 Mar 2014 17:43:58 +0400</pubDate>
									</item>
							<item>
					<title>Передать объект через хук (comment #8724)</title>
					<guid isPermaLink="true">http://79.174.14.219/t/527/#comment8724</guid>
					<link>http://79.174.14.219/527.html#comment8724</link>
					<author>grigor.smirnow7@yandex.ru</author>
					<description><![CDATA[Спасибо. Теперь oTopic недоступна…]]></description>
					<pubDate>Thu, 06 Mar 2014 17:50:49 +0400</pubDate>
									</item>
							<item>
					<title>Передать объект через хук (comment #8725)</title>
					<guid isPermaLink="true">http://79.174.14.219/t/527/#comment8725</guid>
					<link>http://79.174.14.219/527.html#comment8725</link>
					<author>andreyv@gladcode.ru</author>
					<description><![CDATA[напишите в шаблоне <br/>
<pre class="prettyprint"><code>**{$oTopic|print_r}**</code></pre><br/>
если выведется <u>**1**</u>, то переменная действительно недоступна, если выведет объект, значит переменная доступна, а вы что-то не так делаете.]]></description>
					<pubDate>Thu, 06 Mar 2014 18:05:43 +0400</pubDate>
									</item>
							<item>
					<title>Передать объект через хук (comment #8726)</title>
					<guid isPermaLink="true">http://79.174.14.219/t/527/#comment8726</guid>
					<link>http://79.174.14.219/527.html#comment8726</link>
					<author>grigor.smirnow7@yandex.ru</author>
					<description><![CDATA[1, к сожалению.]]></description>
					<pubDate>Thu, 06 Mar 2014 18:07:04 +0400</pubDate>
									</item>
							<item>
					<title>Передать объект через хук (comment #8729)</title>
					<guid isPermaLink="true">http://79.174.14.219/t/527/#comment8729</guid>
					<link>http://79.174.14.219/527.html#comment8729</link>
					<author>andreyv@gladcode.ru</author>
					<description><![CDATA[ — Какой адрес страницы?<br/>
 — Какой полный путь к шаблону?]]></description>
					<pubDate>Thu, 06 Mar 2014 18:16:28 +0400</pubDate>
									</item>
							<item>
					<title>Передать объект через хук (comment #8711)</title>
					<guid isPermaLink="true">http://79.174.14.219/t/527/#comment8711</guid>
					<link>http://79.174.14.219/527.html#comment8711</link>
					<author>andreyv@gladcode.ru</author>
					<description><![CDATA[Фрагмент кода выложите с той его частью, где проблема.]]></description>
					<pubDate>Wed, 05 Mar 2014 20:49:39 +0400</pubDate>
									</item>
							<item>
					<title>Передать объект через хук (comment #8727)</title>
					<guid isPermaLink="true">http://79.174.14.219/t/527/#comment8727</guid>
					<link>http://79.174.14.219/527.html#comment8727</link>
					<author>grigor.smirnow7@yandex.ru</author>
					<description><![CDATA[в хуке все нормально. возвращаю<br/>
$oTopic = $aData['oTopic'];<br/>
return $oTopic-&gt;getUserTwo();<br/>
<br/>
в экшне делаю так<br/>
$this-&gt;Viewer_Assign('userTwo', $this-&gt;Hook_Run('topic_edit_show',array('oTopic'=&gt;$oTopic)));<br/>
<br/>
но приходит пустой массив.]]></description>
					<pubDate>Thu, 06 Mar 2014 18:10:29 +0400</pubDate>
									</item>
							<item>
					<title>Передать объект через хук (comment #8730)</title>
					<guid isPermaLink="true">http://79.174.14.219/t/527/#comment8730</guid>
					<link>http://79.174.14.219/527.html#comment8730</link>
					<author>andreyv@gladcode.ru</author>
					<description><![CDATA[У вас ошибка. В хуке не нужно возвращать $oTopic. В хук передаются параметры по ссылке, то есть: если в экшене вы пишете:<br/>
<pre>&lt;code&gt;$this-&gt;Hook_Run('topic_edit_show',array('oTopic'=&gt;$oTopic));
echo($oTopic-&gt;getTitle());&lt;/code&gt;</pre>и, если хук меняет значение переданной переменной так:<br/>
<pre>&lt;code&gt;public function DoIt($aData) {
    $aData['oTopic']-&gt;setTitle('title from hook');
}&lt;/code&gt;</pre><br/>
то в результате echo выведет заголовок топика, установленный хуком = 'title from hook', а не тот, который был.]]></description>
					<pubDate>Thu, 06 Mar 2014 18:28:23 +0400</pubDate>
									</item>
							<item>
					<title>Передать объект через хук (comment #8762)</title>
					<guid isPermaLink="true">http://79.174.14.219/t/527/#comment8762</guid>
					<link>http://79.174.14.219/527.html#comment8762</link>
					<author>grigor.smirnow7@yandex.ru</author>
					<description><![CDATA[Спасибо большое, именно после этого комментария я понял смысл хуков!]]></description>
					<pubDate>Fri, 07 Mar 2014 13:54:19 +0400</pubDate>
									</item>
							<item>
					<title>Передать объект через хук (comment #8651)</title>
					<guid isPermaLink="true">http://79.174.14.219/t/527/#comment8651</guid>
					<link>http://79.174.14.219/527.html#comment8651</link>
					<author>andreyv@gladcode.ru</author>
					<description><![CDATA[1. В Экшене вызываем хук, а в него передаем <u>массивом</u> набор параметров.<br/>
<pre class="prettyprint"><code>$this-&gt;Hook_Run('my_unhappy_hook', array('oTopic' =&gt; $oTopic, 'bShow' =&gt; true));</code></pre><br/>
или в шаблоне *.tpl<br/>
<pre class="prettyprint"><code>{hook run='my_unhappy_hook' oTopic=$oTopic bShow=true}</code></pre><br/>
<br/>
2. В хуке плагина регистрируем обработчик хука в методе их регистрации. Заметьте, для хука шаблона используется префикс <u>template</u><br/>
<pre class="prettyprint"><code>/**
* Регистрация хуков
*/
public function RegisterHook() {
    $this-&gt;AddHook('my_unhappy_hook', 'DoIt');
    // или для шаблона
    $this-&gt;AddHook('template_my_unhappy_hook', 'DoIt');
}</code></pre><br/>
<br/>
3. Реализуем метод обработки хука и в нем получаем переданные параметры<br/>
<pre class="prettyprint"><code>public function DoIt($aData) {
    $oTopic = $aData['oTopic'];
    $bShow= $aData['bShow'];
    // Дальше реализуем логику метода с использованием этих параметров  
}</code></pre>]]></description>
					<pubDate>Tue, 04 Mar 2014 09:59:44 +0400</pubDate>
									</item>
							<item>
					<title>Передать объект через хук (comment #8664)</title>
					<guid isPermaLink="true">http://79.174.14.219/t/527/#comment8664</guid>
					<link>http://79.174.14.219/527.html#comment8664</link>
					<author>grigor.smirnow7@yandex.ru</author>
					<description><![CDATA[Спасибо. Ном не надо вызвать метод $oTopic-&gt;getUserId(), а он не доходит до экшна создания топика. Что же тогда делать?]]></description>
					<pubDate>Tue, 04 Mar 2014 14:30:48 +0400</pubDate>
									</item>
					</channel>
	</rss>
