The first thing needed I think is to re-adjust the function a bit.
Although not mandatory, it should be something like the function
depicted below for a public method that will process only ajax
requests:
function your_function() {
$this->layout = 'ajax';
if ( $this->RequestHandler->isAjax() ) {
// Your logic
}
} // End of your_function()
- To dynamically bind models, you will very likely employ the use of
"bindModel".
- For functionality that you want to be common across all controllers
you could use or create a component.
I hope that helps.
Regards,
Alfredo
On Fri, Mar 13, 2009 at 9:58 AM, hasentopf
<[email protected]> wrote:
>
> Hi Cake-Friends.
>
> I wrote an Action to handle an Ajax-Request:
> function admin_ajax_state() {
> if($this->params['form']['ajax']) {
> $id = $this->params['form']['id'];
> $teaser = $this->Teaser->read('state', $id);
> $teaser = (bool) $teaser['Teaser']['state'];
> $teaser ? $teaser_val = 0 : $teaser_val = 1;
> $this->Teaser->saveField('state', $teaser_val);
> $this->set('msg', $teaser_val);
> }
> $this->layout = null;
> $this->viewPath = 'pages';
> $this->render('ajax_response');
> }
>
> I will need this action in different controllers, but with the same
> functionality. That sounds like DRY, or?!
> Is there a possibility to generalize this action? How can I make the
> related Model dynamically?
> e.g. $this->$DynamicModel->saveField(...);
>
> Best Mathias
> >
>
--~--~---------~--~----~------------~-------~--~----~
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
-~----------~----~----~----~------~----~------~--~---