Saturday, October 1, 2011

PLEASE HELP ME! Warning (2): Cannot modify header information - headers already sent by cake php

failure:
Warning (2): Cannot modify header information - headers already sent
by (output started at /var/customers/webs/usr05/mkn151/app/controllers/
categories_controller.php:1) [CORE/cake/libs/controller/controller.php

my controller:
<?php
class CategoriesController extends AppController {
var $name = 'Categories';
// Zugriff ohne Login
function beforeFilter(){
parent::beforeFilter();
$this->Auth->allow('choosecategories');
}
// Liste der Kategorien
function index() {
$this->Category->recursive = 0;
$this->set('categories', $this->paginate());
}
// Detailansicht
function view($id = null) {
if (!$id) {
$this->Session->setFlash(__('Ungültige Kategorie', true));
$this->redirect(array('action' => 'index'));
}
$this->set('category', $this->Category->read(null, $id));
}
// Kategorie hinzufügen
function add() {
if (!empty($this->data)) {
$this->Category->create();
if ($this->Category->save($this->data)) {
$this->Session->setFlash(__('Kategorie wurde gespeichert.',
true));
$this->redirect(array('action' => 'index'));
} else {
$this->Session->setFlash(__('Kategorie konnte nicht gespeichert
werden. Versuchen Sie es nochmal.', true));
}
}
$highscores = $this->Category->Highscore->find('list');
$this->set(compact('highscores'));
}
// Kategorie bearbeiten
function edit($id = null) {
if (!$id && empty($this->data)) {
$this->Session->setFlash(__('Ungültige Kategorie', true));
$this->redirect(array('action' => 'index'));
}
if (!empty($this->data)) {
if ($this->Category->save($this->data)) {
$this->Session->setFlash(__('Kategorie wurde gespeichert.',
true));
$this->redirect(array('action' => 'index'));
} else {
$this->Session->setFlash(__('Kategorie konnte nicht gespeichert
werden. Versuchen Sie es nochmal.', true));
}
}
if (empty($this->data)) {
$this->data = $this->Category->read(null, $id);
}
$highscores = $this->Category->Highscore->find('list');
$this->set(compact('highscores'));
}
// Kategorie löschen
function delete($id = null) {
if (!$id) {
$this->Session->setFlash(__('Ungültige Kategorie Id', true));
$this->redirect(array('action'=>'index'));
}
if ($this->Category->delete($id)) {
$this->Session->setFlash(__('Kategorie wurde gelöscht.', true));
$this->redirect(array('action'=>'index'));
}
$this->Session->setFlash(__('Kategorie wurden nicht gelöscht.',
true));
$this->redirect(array('action' => 'index'));
}
// Kategorien auswählen
function choosecategories() {
//Session zu Beginn des neuen Spieles leeren
$this->Session->destroy();
//Kategorien auslesen
if(empty($this->data)){
$this->set('categories', $this->Category->find('all'));
}else{
$categories = array();
foreach ($this->data['Category'] as $key => $cat):
if($cat == 1){
array_push($categories, $key);
}
endforeach;
//Sessions setzen
if(count($categories) > 0){
$this->Session->write('categories', $categories);
$this->Session->write('startTime', date('Y-m-d H:i:s'));
$this->Session->write('joker', true);
$this->Session->write('points', 0);
$this->redirect(array('controller' => 'questions', 'action' =>
'game'));
}else{
$this->set('categories', $this->Category->find('all'));
}
}
}
}
?>

my view:
<!-- Form für Kategorien auswählen definieren-->
<div class="categories index">
<h2><?php __('Kategorien wählen');?></h2>
<?php
echo $this->Form->create('Category');
foreach ($categories as $category):
echo $this->Form->checkbox($category['Category']['id']);
echo $category['Category']['name'];
echo '<br>';
endforeach;
echo $this->Form->end('Weiter');
?>
</div>

PLEASE HELP ME

--
Our newest site for the community: CakePHP Video Tutorials http://tv.cakephp.org
Check out the new CakePHP Questions site http://ask.cakephp.org and help others with their CakePHP related questions.


To unsubscribe from this group, send email to
cake-php+unsubscribe@googlegroups.com For more options, visit this group at http://groups.google.com/group/cake-php

No comments: