HOWTO: Дополнительные поля при создании топика
Мне требовалось создать одно дополнительное поле, выводящееся при создании, редактировании и просмотре топика.
Прежде всего хочу сказать спасибо тов.eXtravert за подсказку .
Итак, поехали…
В файле: templates/skin/new/actions/ActionTopic/add.tpl
после
В файле: classes/modules/topic/entity/Topic.entity.class.php
в любое понравившееся (в пределах класса) место вставляем
В файле: classes/actions/ActionTopic.class.php
после строчки (ориентировочно 166 строка)
далее после строки (встречается два раза — примерно 384 и 537 строки)
В файле: templates/skin/new/topic.tpl
после строк
В файле: templates/skin/new/topic_list.tpl
после строк
Постарался расписать все более или менее подробно, т.к. самому сначала было сложно :-)
Прежде всего хочу сказать спасибо тов.
Итак, поехали…
В файле: templates/skin/new/actions/ActionTopic/add.tpl
после
<p><label for="topic_tags">{$aLang.topic_create_tags}:</label><br />
<input type="text" id="topic_tags" name="topic_tags" value="{$_aRequest.topic_tags}" class="w100p" /><br />
<span class="form_note">{$aLang.topic_create_tags_notice}</span></p>
вставляем<p><label for="topic_somecontent">Some text:</label><br />
<input type="text" id="topic_somecontent" name="topic_somecontent" value="{$_aRequest.topic_somecontent}" class="w100p" /></span></p>
В файле: classes/modules/topic/entity/Topic.entity.class.php
в любое понравившееся (в пределах класса) место вставляем
public function getSomeContent() {
$this->extractExtra();
if (isset($this->aExtra['some_content'])) {
$somecontent=$this->aExtra['some_content'];
return $somecontent;
}
return null;
}
public function setSomeContent($data) {
$this->extractExtra();
$this->aExtra['some_content']=$data;
$this->setExtra($this->aExtra);
}
В файле: classes/actions/ActionTopic.class.php
после строчки (ориентировочно 166 строка)
$_REQUEST['topic_forbid_comment']=$oTopic->getForbidComment();
вставляем строчку$_REQUEST['topic_somecontent']=$oTopic->getSomeContent();
далее после строки (встречается два раза — примерно 384 и 537 строки)
$oTopic->setTextHash(md5(getRequest('topic_text')));
вставляем$oTopic->setSomeContent(getRequest('topic_somecontent'));
В файле: templates/skin/new/topic.tpl
после строк
{$oTopic->getText()}
</div>
вставляем<a href="{$oTopic->getsetSomeContent()}">Some text: {$oTopic->getTitle()}</a>
В файле: templates/skin/new/topic_list.tpl
после строк
{$oTopic->getTextShort()}
{if $oTopic->getTextShort()!=$oTopic->getText()}
( <a href="{$oTopic->getUrl()}" title="{$aLang.topic_read_more}">
{if $oTopic->getCutText()}
{$oTopic->getCutText()}
{else}
{$aLang.topic_read_more}
{/if}
</a> )
{/if}
</div>
вставляем<a href="{$oTopic->getsetSomeContent()}">Some text: {$oTopic->getTitle()}</a>
Постарался расписать все более или менее подробно, т.к. самому сначала было сложно :-)
4 комментария
находим функцию
там, где стоит topic_text_hash — ставите запятую, дописываете topic_somecontent.
в VALUES — добавляем один знак вопроса.
После $oTopic->getTextHash() пару строками ниже дописываете через запятую $oTopic->getSomeContent().
далее — правка функции
ищем topic_text_hash = ?, ставим запятую, дописываем topic_somecontent =?
Двумя строками ниже ДО $oTopic->getId() вставляем $oTopic->getSomeContent(),
Fatal error: Uncaught exception 'Exception' with message 'Не найден класс модуля — getsetSomeContent' in W:\home\fishg.ru\www\classes\engine\Engine.class.php:95 Stack trace: #0 W:\home\fishg.ru\www\classes\engine\Engine.class.php(183): Engine->LoadModule('getsetSomeConte...', true) #1 W:\home\fishg.ru\www\classes\engine\Entity.class.php(61): Engine->_CallModule('getsetSomeConte...', Array) #2 [internal function]: Entity->__call('getsetSomeConte...', Array) #3 W:\home\fishg.ru\www\templates\compiled\%%F3^F3B^F3B39BC9%%topic_list.tpl.php(120): TopicEntity_Topic->getsetSomeContent() #4 W:\home\fishg.ru\www\classes\lib\external\Smarty-2.6.19\libs\Smarty.class.php(1868): include('W:\home\fishg.r...') #5 W:\home\fishg.ru\www\templates\compiled\%%2B^2BF^2BF53ECB%%index.tpl.php(10): Smarty->_smarty_include(Array) #6 W:\home\fishg.ru\www\classes\lib\external\Smarty-2.6.19\libs\Smarty.class.php(1255): include('W:\home\fishg.r...') #7 W:\home\fishg.ru\www\classes\lib\external\Smarty-2.6.19\libs\Smarty.class.php(11 in W:\home\fishg.ru\www\classes\engine\Engine.class.php on line 95
В чем может быть проблема?