--------------------------------------------------------------------------------------------------------------------
controller file is messages_controller.php
--------------------------------------------------------------------------------------------------------------------
<?php
class MessagesController extends AppController{
var $name = 'Messages';
var $helpers = array (
'Html',
'Form',
'Time'
);
function index($id = null ){
if (!$id) {
$this->Session->setFlash('Invalid Topic');
$this->redirect(array (
'action' => 'index'
), null, true);
}
$this->Message->recursive = 1;
$messages = $this->Message->find('all',
array( 'conditions' => array( 'topic_id' => $id ),'order' =>
'Message.id DESC') );
$this->set('topic_id',$id);
$this->set('messages',$messages);
}
function add($id = null) {
if (!empty ($this->data)) {
$this->Message->create();
if ($this->Message->save($this->data)) {
$this->Session->setFlash('The message has been
added');
$this->redirect(array (
'action' => 'index'
), null, true);
} else {
$this->Session->setFlash('message posting
failed. Try again.');
}
}
$users = $this->Message->User->find('list');
$this->set('topic_id',$id);
$this->set('users',$users);
}
}
?>
---------------------------------------------------------------------------------------------------------------------------------
My view file is messages folders in views as add.ctp
---------------------------------------------------------------------------------------------------------------------------------
<?php echo $form->create('Message',array( 'url' => 'add/'.
$topic_id ));?>
<fieldset>
<legend>New topic</legend>
<?php
echo $form->input('message_text');
echo $form->input('user_id');
echo $form->hidden('topic_id',array( 'value' => $topic_id));
?>
</fieldset>
<?php echo $form->end('post a message');?>
<?php
echo $html->link('Go back', array('action'=>'index'));
?>
---------------------------------------------------------------------------------------------------------------------------------
When I fill up the add form and submit.
The data gets inserted into the messages table without any hiccups.
But I get an error during redirection back to the index page like this
------------------------------------------------------------------------------------------------------------
Warning (2): Cannot modify header information - headers already sent
by (output started at /opt/lampp/htdocs/cake/message_board/app/
controllers/messages_controller.php:115) [CORE/cake/libs/controller/
controller.php, line 587]
Code | Context
$status = "Location: http://localhost/cake/message_board/messages"
header - [internal], line ??
Controller::header() - CORE/cake/libs/controller/controller.php, line
587
Controller::redirect() - CORE/cake/libs/controller/controller.php,
line 568
MessagesController::add() - APP/controllers/messages_controller.php,
line 54
Object::dispatchMethod() - CORE/cake/libs/object.php, line 116
Dispatcher::_invoke() - CORE/cake/dispatcher.php, line 259
Dispatcher::dispatch() - CORE/cake/dispatcher.php, line 213
[main] - APP/webroot/index.php, line 90
---------------------------------------------------------------------------------------------------------------
The redirection to the index page fails.
The parameters supplied in the form in add.ctp was as I expected
"messages/add/1" which you can see the below code
---------------------------------------------------------------------------------------------------------------
<form method="post" action="/cake/message_board/messages/add/
1"><fieldset style="display:none;"><input type="hidden" name="_method"
value="POST" /></fieldset> <fieldset>
<legend>New topic</legend>
---------------------------------------------------------------------------------------------------------------
Please, help me out with this problem??
Thank you
Imranullah Mohammed
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups
"CakePHP" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at
http://groups.google.com/group/cake-php?hl=en
-~----------~----~----~----~------~----~------~--~---