Re: Simple question from a newbie seeking help from the gods

2009-10-19 Thread WebbedIT

> ... and by answering I am not implying I am a God of any kind ;)

More a demi-god :P
--~--~-~--~~~---~--~~
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 
cake-php+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/cake-php?hl=en
-~--~~~~--~~--~--~---



Re: Simple question from a newbie seeking help from the gods

2009-10-19 Thread Martin Westin

No, you still need a controller action... but that action does not
need to do more than call the model in this case... well, and format
response data for the view and things like that. The point was that
you mentioned calling one controller from another... that was the main
reason behind pushing this simple functionality down into the model.



On Oct 18, 10:42 am, Will Poillion  wrote:
> Thanks Martin!
>
> So i can put the method in the model class, but how would I call it
> within a view?
>
> This is the link I have that calls the ingredients function to remove
> it from the group. If I put the method in the model, I can't call it
> directly like I'm doing below can I?
>
> Right now this works, but I'm open to a better way:
>
> link(__('Remove', true),
>                             array('controller'=>'ingredients',
>                                      'action'=>'removeFromGroup',
>                                      $ingredient['id'],
>                                      $ingredientGroup
> ['IngredientGroup']['id']),
>                            null, sprintf(__('Are you sure you want to
> remove \'%s\' from this group?', true), $ingredient['name'])); ?>
>
> Can I just put
>
> $this->IngredientGroup->Ingredient->removeFromGroup( $ingredient
> ['id'], $ingredientGroup['IngredientGroup']['id'])
>
> directly in the view somehow? That seems to go away from the MVC
> methodology.
>
> Thanks again!
>
> Will
> On Oct 17, 10:27 am, Martin Westin  wrote:
>
>
>
> > First the quickfix... hopefully.
>
> > This will try to save a PHP-null value.
> > $this->data['ingredient_group_id'] = null;
>
> > Instead try to save an SQL-null value.
> > $this->data['ingredient_group_id'] = 'null';
>
> > Or even just a zero if the above doesn't work.
> > $this->data['ingredient_group_id'] = '0';
>
> > Now for a suggestion. For saving a single field Cake models have a
> > special function... called saveField no less :)
>
> > $this->Ingredient->id = $id; // this line if very very important
> > $successful = $this->Ingredient->saveField
> > ('ingredient_group_id','null'); // or 0
>
> > And finally another suggestion. You don't have to call a method in one
> > controller from another for this... Better to put the whole
> > "removeFromGroup()" method into the Model and call it from wherever.
> > You know you can call a model like: $this->IngredientGroup->Ingredient
> > right?
>
> > ... and by answering I am not implying I am a God of any kind ;)
>
> > /Martin
>
> > On Oct 17, 7:56 am, Will Poillion  wrote:
>
> > > Just trying to update a single field within a function called from its
> > > associated model:
>
> > > I'm calling 'removeFromGroup' in Ingredients controller from my
> > > IngredientGroups controller.
>
> > > I basically want to remove the ingredient from the group, so set the
> > > ingredient_group_id to null.
>
> > >         function removeFromGroup($id = null, $group_id = null) {
> > >                 if (!$id) {
> > >                         $this->Session->setFlash(__('Invalid id for 
> > > Ingredient', true));
> > >                         $this->redirect(array('controller'=> 
> > > 'IngredientGroups',
> > > 'action'=>'view', $group_id));
> > >                 }
>
> > >                 $this->data = $this->Ingredient->read(null, $id);
>
> > >                 $this->data['ingredient_group_id'] = null;
> > >                 $this->Ingredient->save($this->data);
> > >                 $this->redirect(array('controller'=> 'IngredientGroups',
> > > 'action'=>'view', $group_id));
>
> > >         }
>
> > > There's my function. It just won't save the ingredient_group_id to
> > > null. Not sure what I'm doing wrong. Thanks!
--~--~-~--~~~---~--~~
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 
cake-php+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/cake-php?hl=en
-~--~~~~--~~--~--~---



Re: Simple question from a newbie seeking help from the gods

2009-10-18 Thread Will Poillion

Thanks Martin!

So i can put the method in the model class, but how would I call it
within a view?

This is the link I have that calls the ingredients function to remove
it from the group. If I put the method in the model, I can't call it
directly like I'm doing below can I?

Right now this works, but I'm open to a better way:

link(__('Remove', true),
array('controller'=>'ingredients',
 'action'=>'removeFromGroup',
 $ingredient['id'],
 $ingredientGroup
['IngredientGroup']['id']),
   null, sprintf(__('Are you sure you want to
remove \'%s\' from this group?', true), $ingredient['name'])); ?>

Can I just put

$this->IngredientGroup->Ingredient->removeFromGroup( $ingredient
['id'], $ingredientGroup['IngredientGroup']['id'])

directly in the view somehow? That seems to go away from the MVC
methodology.

Thanks again!

Will
On Oct 17, 10:27 am, Martin Westin  wrote:
> First the quickfix... hopefully.
>
> This will try to save a PHP-null value.
> $this->data['ingredient_group_id'] = null;
>
> Instead try to save an SQL-null value.
> $this->data['ingredient_group_id'] = 'null';
>
> Or even just a zero if the above doesn't work.
> $this->data['ingredient_group_id'] = '0';
>
> Now for a suggestion. For saving a single field Cake models have a
> special function... called saveField no less :)
>
> $this->Ingredient->id = $id; // this line if very very important
> $successful = $this->Ingredient->saveField
> ('ingredient_group_id','null'); // or 0
>
> And finally another suggestion. You don't have to call a method in one
> controller from another for this... Better to put the whole
> "removeFromGroup()" method into the Model and call it from wherever.
> You know you can call a model like: $this->IngredientGroup->Ingredient
> right?
>
> ... and by answering I am not implying I am a God of any kind ;)
>
> /Martin
>
> On Oct 17, 7:56 am, Will Poillion  wrote:
>
> > Just trying to update a single field within a function called from its
> > associated model:
>
> > I'm calling 'removeFromGroup' in Ingredients controller from my
> > IngredientGroups controller.
>
> > I basically want to remove the ingredient from the group, so set the
> > ingredient_group_id to null.
>
> >         function removeFromGroup($id = null, $group_id = null) {
> >                 if (!$id) {
> >                         $this->Session->setFlash(__('Invalid id for 
> > Ingredient', true));
> >                         $this->redirect(array('controller'=> 
> > 'IngredientGroups',
> > 'action'=>'view', $group_id));
> >                 }
>
> >                 $this->data = $this->Ingredient->read(null, $id);
>
> >                 $this->data['ingredient_group_id'] = null;
> >                 $this->Ingredient->save($this->data);
> >                 $this->redirect(array('controller'=> 'IngredientGroups',
> > 'action'=>'view', $group_id));
>
> >         }
>
> > There's my function. It just won't save the ingredient_group_id to
> > null. Not sure what I'm doing wrong. Thanks!
--~--~-~--~~~---~--~~
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 
cake-php+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/cake-php?hl=en
-~--~~~~--~~--~--~---



Re: Simple question from a newbie seeking help from the gods

2009-10-17 Thread Martin Westin

First the quickfix... hopefully.

This will try to save a PHP-null value.
$this->data['ingredient_group_id'] = null;

Instead try to save an SQL-null value.
$this->data['ingredient_group_id'] = 'null';

Or even just a zero if the above doesn't work.
$this->data['ingredient_group_id'] = '0';


Now for a suggestion. For saving a single field Cake models have a
special function... called saveField no less :)

$this->Ingredient->id = $id; // this line if very very important
$successful = $this->Ingredient->saveField
('ingredient_group_id','null'); // or 0


And finally another suggestion. You don't have to call a method in one
controller from another for this... Better to put the whole
"removeFromGroup()" method into the Model and call it from wherever.
You know you can call a model like: $this->IngredientGroup->Ingredient
right?

... and by answering I am not implying I am a God of any kind ;)

/Martin



On Oct 17, 7:56 am, Will Poillion  wrote:
> Just trying to update a single field within a function called from its
> associated model:
>
> I'm calling 'removeFromGroup' in Ingredients controller from my
> IngredientGroups controller.
>
> I basically want to remove the ingredient from the group, so set the
> ingredient_group_id to null.
>
>         function removeFromGroup($id = null, $group_id = null) {
>                 if (!$id) {
>                         $this->Session->setFlash(__('Invalid id for 
> Ingredient', true));
>                         $this->redirect(array('controller'=> 
> 'IngredientGroups',
> 'action'=>'view', $group_id));
>                 }
>
>                 $this->data = $this->Ingredient->read(null, $id);
>
>                 $this->data['ingredient_group_id'] = null;
>                 $this->Ingredient->save($this->data);
>                 $this->redirect(array('controller'=> 'IngredientGroups',
> 'action'=>'view', $group_id));
>
>         }
>
> There's my function. It just won't save the ingredient_group_id to
> null. Not sure what I'm doing wrong. Thanks!
--~--~-~--~~~---~--~~
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 
cake-php+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/cake-php?hl=en
-~--~~~~--~~--~--~---



Simple question from a newbie seeking help from the gods

2009-10-17 Thread Will Poillion

Just trying to update a single field within a function called from its
associated model:

I'm calling 'removeFromGroup' in Ingredients controller from my
IngredientGroups controller.

I basically want to remove the ingredient from the group, so set the
ingredient_group_id to null.

function removeFromGroup($id = null, $group_id = null) {
if (!$id) {
$this->Session->setFlash(__('Invalid id for 
Ingredient', true));
$this->redirect(array('controller'=> 'IngredientGroups',
'action'=>'view', $group_id));
}

$this->data = $this->Ingredient->read(null, $id);

$this->data['ingredient_group_id'] = null;
$this->Ingredient->save($this->data);
$this->redirect(array('controller'=> 'IngredientGroups',
'action'=>'view', $group_id));

}

There's my function. It just won't save the ingredient_group_id to
null. Not sure what I'm doing wrong. Thanks!


--~--~-~--~~~---~--~~
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 
cake-php+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/cake-php?hl=en
-~--~~~~--~~--~--~---