Re: Making comments on motives

2008-09-11 Thread luigi7up

No,no, I don't have Comment controller... I have MotivesController
with Comment() action...
Save() method works well but it doesn't use validation from comment
model.!?

Maybe I should create comment_controller and define comment() action
there, then call it from my form and then after save() redirect back
to motives_controller view() action?

Hope I've been clear :)



On Sep 11, 1:05 pm, "Amit Badkas" <[EMAIL PROTECTED]> wrote:
> 2008/9/11 luigi7up <[EMAIL PROTECTED]>
>
>
>
>
>
> > Hello everyone,
>
> > I have two models
>
> > MOTIVE  var $hasMany = array('Comment');
> > COMMENT var $belongsTp=array('Motive');
>
> > I want to make comments on motives so I added comment() function into
> > Motive controller and in views/motive/view.php I added following form:
> > 
> >        echo $form->create('Motive',array('action' => 'comment'));
> >        echo $form->hidden('Comment.motive_id',array('value'=>
> > $motive['Motive']['id']));
> >        echo $form->input('Comment.author');
> >        echo $form->input('Comment.text',array('type'=>'textarea'));
> >        echo $form->end('Send');
> > 
>
> > In comment() function of Motives controller i have:
> > 
> > if (!empty($this->data)) {
> >        if($this->Motive->Comment->save($this->data))
> >        {
> >                $this->Session->setFlash(__('Posted!', true));
> >               $this-
> > >redirect(array('controller'=>'motives','action'=>'view/'.$this-
> > >data['Comment']['motive_id'].''));
> >        }
> >        else
> >        {
> >                $this->Session->setFlash(__('Error!', true));
>
> >        }
> > }
> > 
>
> > I also added validation to my comment model:
> > *
> >        var $validate = array(
> >                        'author' =>
> > array('rule'=>VALID_NOT_EMPTY,'message'=>'Blank
> > field!'),
> >                        'text' =>
> > array('rule'=>VALID_NOT_EMPTY,'message'=>'Blank field!')
> >        );
> > *
>
> > and there seems to be a problem. If I leave an empty author field it
> > will not throw a validation error?
>
> > I think this has something to do with putting comment() function in
> > motives_controller and than expecting comment model validation to do
> > the job?!?!
>
> > How can I make my validation work so it redirects back to the form and
> > throws an error next to the field that was left empty etc.?
>
> > thnx
>
> - You have used incorrect model name in $form->create(), please use Comment
> instead of Motive and then you don't need to prefix Comment model in any of
> the $form->input()
>
> --
> Amit
>
> http://amitrb.wordpress.com/http://coppermine-gallery.net/http://cheesecake-photoblog.org/http://www.sanisoft.com/blog/author/amitbadkas
--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
"CakePHP" group.
To post to this group, send email to cake-php@googlegroups.com
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
-~--~~~~--~~--~--~---



Re: Making comments on motives

2008-09-11 Thread Amit Badkas
2008/9/11 luigi7up <[EMAIL PROTECTED]>

>
> Hello everyone,
>
> I have two models
>
> MOTIVE  var $hasMany = array('Comment');
> COMMENT var $belongsTp=array('Motive');
>
> I want to make comments on motives so I added comment() function into
> Motive controller and in views/motive/view.php I added following form:
> 
>echo $form->create('Motive',array('action' => 'comment'));
>echo $form->hidden('Comment.motive_id',array('value'=>
> $motive['Motive']['id']));
>echo $form->input('Comment.author');
>echo $form->input('Comment.text',array('type'=>'textarea'));
>echo $form->end('Send');
> 
>
> In comment() function of Motives controller i have:
> 
> if (!empty($this->data)) {
>if($this->Motive->Comment->save($this->data))
>{
>$this->Session->setFlash(__('Posted!', true));
>   $this-
> >redirect(array('controller'=>'motives','action'=>'view/'.$this-
> >data['Comment']['motive_id'].''));
>}
>else
>{
>$this->Session->setFlash(__('Error!', true));
>
>}
> }
> 
>
> I also added validation to my comment model:
> *
>var $validate = array(
>'author' =>
> array('rule'=>VALID_NOT_EMPTY,'message'=>'Blank
> field!'),
>'text' =>
> array('rule'=>VALID_NOT_EMPTY,'message'=>'Blank field!')
>);
> *
>
> and there seems to be a problem. If I leave an empty author field it
> will not throw a validation error?
>
> I think this has something to do with putting comment() function in
> motives_controller and than expecting comment model validation to do
> the job?!?!
>
> How can I make my validation work so it redirects back to the form and
> throws an error next to the field that was left empty etc.?
>
> thnx
>

- You have used incorrect model name in $form->create(), please use Comment
instead of Motive and then you don't need to prefix Comment model in any of
the $form->input()

-- 
Amit

http://amitrb.wordpress.com/
http://coppermine-gallery.net/
http://cheesecake-photoblog.org/
http://www.sanisoft.com/blog/author/amitbadkas

--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
"CakePHP" group.
To post to this group, send email to cake-php@googlegroups.com
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
-~--~~~~--~~--~--~---



Making comments on motives

2008-09-11 Thread luigi7up

Hello everyone,

I have two models

MOTIVE  var $hasMany = array('Comment');
COMMENT var $belongsTp=array('Motive');

I want to make comments on motives so I added comment() function into
Motive controller and in views/motive/view.php I added following form:

echo $form->create('Motive',array('action' => 'comment'));
echo $form->hidden('Comment.motive_id',array('value'=>
$motive['Motive']['id']));
echo $form->input('Comment.author');
echo $form->input('Comment.text',array('type'=>'textarea'));
echo $form->end('Send');


In comment() function of Motives controller i have:

if (!empty($this->data)) {
if($this->Motive->Comment->save($this->data))
{
$this->Session->setFlash(__('Posted!', true));
   $this-
>redirect(array('controller'=>'motives','action'=>'view/'.$this-
>data['Comment']['motive_id'].''));
}
else
{
$this->Session->setFlash(__('Error!', true));

}
}


I also added validation to my comment model:
*
var $validate = array(
'author' => 
array('rule'=>VALID_NOT_EMPTY,'message'=>'Blank
field!'),
'text' => 
array('rule'=>VALID_NOT_EMPTY,'message'=>'Blank field!')
);
*

and there seems to be a problem. If I leave an empty author field it
will not throw a validation error?

I think this has something to do with putting comment() function in
motives_controller and than expecting comment model validation to do
the job?!?!

How can I make my validation work so it redirects back to the form and
throws an error next to the field that was left empty etc.?

thnx
--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
"CakePHP" group.
To post to this group, send email to cake-php@googlegroups.com
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
-~--~~~~--~~--~--~---