Ajax – problem s headers
- MelkorNemesis
- Člen | 36
Ahoj,
pracuju ted se snippetama – a az do teto chvile vsecko krasne fungovalo.
Mam presenter:
<?php
class ArticlesPresenter extends BasePresenter{
// ajax data container
private $_ajaxData = array();
// article container
private $_article;
// default render, review of last articles
public function renderDefault() {
$this->template->title = $this->_title . "Hlavní strana";
// vytahnuti clanku je v BasePresenteru - pouzivaji se v kazdem requestu
}
/*
* detail of article
* @param string $url
*/
public function actionDetail($url) {
$this->_article = ArticlesTable::getArticleByParams(array('url' => $url), true); // musi se volat pred handleAddcomment, kvuli zjisteni id clanku
if(!$this->_article) {
throw new BadRequestException('Článek s adresou ' . $url . ' neexistuje!');
}
$this->_ajaxData['article_id'] = $this->_article->id;
}
public function renderDetail($url) {
$this->_article = ArticlesTable::getArticleByParams(array('url' => $url), true); // duplicita v kodu s radkem 30, musi se volat po handleAddcomment, protoze stranka obsahuje nova data (uz jina nez pri actionDetail)
$this->template->tags = ArticlesTagsTable::getTagsByArticles($this->_article->id);
$this->template->article = $this->_article;
$this->template->title = $this->_title . $this->_article->header;
$this->template->heading = $this->_article->header;
$this->template->comments = ArticlesCommentsTable::getCommentsByParams(array('url' => $url));
}
protected function _init() {
$this->template->activeMenu = 'home';
}
/*
* Adds a shout to the shoutbox via ajax
* @param string text
*/
public function handleAddshout($text) {
$user = Environment::getUser();
if ($user->isAuthenticated()) {
if (!empty($text)) {
$data = array(
'message' => $text,
'datetime_created' => dibi::datetime(),
'user_id' => $user->getIdentity()->id
);
ShoutboxTable::addShout($data);
// invalidate
$this->invalidateControl('shoutbox');
} else {
$this->flashMessage('Text vzkazu nemůže být prázdný!');
}
} else {
$this->flashMessage('Vzkaz nebyl přidán - prosím přihlašte se.', 'error');
}
}
}
?>
Pokud jsem v detailu clanku, tak handleAddshout($text) funguje jak ma, invaliduje jeden snippet a vrati ho v JSONu.
Pokud jsem v renderDefault(), tak novy vzkaz („shout“) se prida, ale snippety se neinvaliduji, ve firebugu mi prijde chyba:
Cannot send header after HTTP headers have been sent (output started at /Users/michalsevcik/Sites/web/app/temp/c-Nette.Template/_f83c6f8d0c07ce8fa6955d47f2bba317.default.phtml.php:16)
Na tomhle radku je akorat echo – ale to je v detail.phtml taky, a nerve to. Jedineho rozdilu, ktereho jsem si vsiml je, ze v cachovane detail.phtml je nahore
if (SnippetHelper::$outputAllowed) { ?>
a to v default.phtml neni.
Muze mi prosim nekdo dat voditko k chybe?
Diky za Vas cas
Editoval MelkorNemesis (14. 1. 2010 13:11)
- MelkorNemesis
- Člen | 36
Majkl578 napsal(a):
Zavináč?
Je to zatim primo v @layout.phtml, tak neni asi zadny potreba
EDIT: pardon .. tohle mi nejak uniklo, myslel sem, ze zavinace se davaji jen tam, abych se postupne probojoval k snippetum, a ne k souborum, ktere snippety neobsahuji, ale nacitaji se pres ajaxovy request.
Diky Majkl578e :)
Editoval MelkorNemesis (14. 1. 2010 13:23)
- MelkorNemesis
- Člen | 36
Majkl578 napsal(a):
Ukaž šablonu default.phtml
@{block #content}
{foreach $articles as $article}
{if $iterator->getCounter() == 2}
<img src="/images/ban_nosferatu.jpg" alt="" class="banner_468" />
{/if}
<div class='article'>
<h4><a href="{plink Articles:detail, 'url' => $article->url}">{$article->header}</a></h4> <div class="datetime">{$article->datetime_created|date:d.m.Y}</div>
<div class="clear"></div>
<div class="text">
{!$article->text|truncate:500," [...]"}
<div class="clear"></div>
</div>
<div class="footer">
Autor: <a href="{plink Users:default, 'user' => $article->login}">{$article->login}</a>
{if isset($articlesTags[$article->id])}
Tagy:
{foreach $articlesTags[$article->id] as $tag}
<a href="{link Search:tag, 'keyword' => $tag}">{$tag}</a> {if !$iterator->isLast()},{/if}
{/foreach}
{/if}
<div class="comments">Komentářů: [<a href="{plink Articles:detail, 'url' => $article->url}#comments">{$article->comment_count}</a>]</div>
</div>
</div>
{/foreach}
@{/block}
Prave me zmatlo, ze tu nepouzivam zadny ajax a presto tam musi byt zavinac jenom proto, ze to posilam jako subrequest? :/