Re: Use the dreaded requestAction()... or use something else?

2009-02-03 Thread RichardAtHome

Request action isn't *that* bad ;-)

In this case request action should be fine as you wont be calling it
very often (as opposed to say from in an element that is displayed on
every page).

That said, Graham's suggestion is a better solution.

Note, to get the best performance from requestAction you should use
the following syntax:

$this->requestAction(array("controller"=>"sites", "action"=>"add"));


On Feb 2, 12:14 pm, Turgs  wrote:
> Hello all
>
> What's an appropriate use of requestAction()?
>
> I have 3 controllers:
>    * UsersController
>    * SiteController
>    * SitePagesController
>
> Within the add() function of UsersController, I want to (a) create a
> new user (b) create a new site for that user with (c) one new page for
> that site.
>
> What's the best way to do this?
>
> I was thinking of:
>
> ##
>
> if ($this->User->save($this->data))
> {
>    # create site
>    $this->requestAction('/sites/add');
>
>    # add a page (homepage) for this site
>    $this->requestAction('/sitepages/add');
>
>    # Login the user and redirect to the dashboard
>    // login code here
>    $this->Session->setFlash(SOTF_MSG_USER_WELCOME);
>    $this->redirect(array('controller' => 'users' ,'action' =>
> 'dashboard'));
>
> }
>
> ##
>
> While the code for this looks clean, what I've read seems to indicate
> this isn't such a good idea due to performance issues.
>
> What else would I do?
>
> Thanks
> Turgs
--~--~-~--~~~---~--~~
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: Use the dreaded requestAction()... or use something else?

2009-02-02 Thread Rodrigo Rodrigues Moyle
You try to use saveAll?
On Mon, Feb 2, 2009 at 10:16 AM, Graham Weldon wrote:

>
>
> If some association exists between these objects, you can do something
> like:
>
> $this->User->save($this->data);
> $this->User->Site->save(array('Site' => array(
> 'user_id' => $this->User->id,
> // --- any other data
> )));
> $this->User->Site->SitePage->save(array('SitePage' => array(
> 'site_id' => $this->User->Site->id,
> // --- any other data
> )));
>
>
> Tada!
> Associationes from User to Site, and Site to SitePages need to exist for
> that to work.
>
> Cheers,
> Graham
>
>
>
>
> On Mon, 2 Feb 2009 04:14:48 -0800 (PST), Turgs  wrote:
> > Hello all
> >
> > What's an appropriate use of requestAction()?
> >
> > I have 3 controllers:
> >* UsersController
> >* SiteController
> >* SitePagesController
> >
> > Within the add() function of UsersController, I want to (a) create a
> > new user (b) create a new site for that user with (c) one new page for
> > that site.
> >
> > What's the best way to do this?
> >
> > I was thinking of:
> >
> > ##
> >
> > if ($this->User->save($this->data))
> > {
> ># create site
> >$this->requestAction('/sites/add');
> >
> ># add a page (homepage) for this site
> >$this->requestAction('/sitepages/add');
> >
> ># Login the user and redirect to the dashboard
> >// login code here
> >$this->Session->setFlash(SOTF_MSG_USER_WELCOME);
> >$this->redirect(array('controller' => 'users' ,'action' =>
> > 'dashboard'));
> > }
> >
> > ##
> >
> > While the code for this looks clean, what I've read seems to indicate
> > this isn't such a good idea due to performance issues.
> >
> > What else would I do?
> >
> > Thanks
> > Turgs
> >
> --
> Cheers,
>
> Graham Weldon
> w. http://grahamweldon.com
> e. gra...@grahamweldon.com
> p. +61 407 017 293
>
> >
>

--~--~-~--~~~---~--~~
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: Use the dreaded requestAction()... or use something else?

2009-02-02 Thread Graham Weldon


If some association exists between these objects, you can do something
like:

$this->User->save($this->data);
$this->User->Site->save(array('Site' => array(
 'user_id' => $this->User->id,
 // --- any other data
)));
$this->User->Site->SitePage->save(array('SitePage' => array(
 'site_id' => $this->User->Site->id,
 // --- any other data
)));


Tada!
Associationes from User to Site, and Site to SitePages need to exist for
that to work.

Cheers,
Graham




On Mon, 2 Feb 2009 04:14:48 -0800 (PST), Turgs  wrote:
> Hello all
> 
> What's an appropriate use of requestAction()?
> 
> I have 3 controllers:
>* UsersController
>* SiteController
>* SitePagesController
> 
> Within the add() function of UsersController, I want to (a) create a
> new user (b) create a new site for that user with (c) one new page for
> that site.
> 
> What's the best way to do this?
> 
> I was thinking of:
> 
> ##
> 
> if ($this->User->save($this->data))
> {
># create site
>$this->requestAction('/sites/add');
> 
># add a page (homepage) for this site
>$this->requestAction('/sitepages/add');
> 
># Login the user and redirect to the dashboard
>// login code here
>$this->Session->setFlash(SOTF_MSG_USER_WELCOME);
>$this->redirect(array('controller' => 'users' ,'action' =>
> 'dashboard'));
> }
> 
> ##
> 
> While the code for this looks clean, what I've read seems to indicate
> this isn't such a good idea due to performance issues.
> 
> What else would I do?
> 
> Thanks
> Turgs
> 
-- 
Cheers,

Graham Weldon
w. http://grahamweldon.com
e. gra...@grahamweldon.com
p. +61 407 017 293

--~--~-~--~~~---~--~~
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
-~--~~~~--~~--~--~---



Use the dreaded requestAction()... or use something else?

2009-02-02 Thread Turgs

Hello all

What's an appropriate use of requestAction()?

I have 3 controllers:
   * UsersController
   * SiteController
   * SitePagesController

Within the add() function of UsersController, I want to (a) create a
new user (b) create a new site for that user with (c) one new page for
that site.

What's the best way to do this?

I was thinking of:

##

if ($this->User->save($this->data))
{
   # create site
   $this->requestAction('/sites/add');

   # add a page (homepage) for this site
   $this->requestAction('/sitepages/add');

   # Login the user and redirect to the dashboard
   // login code here
   $this->Session->setFlash(SOTF_MSG_USER_WELCOME);
   $this->redirect(array('controller' => 'users' ,'action' =>
'dashboard'));
}

##

While the code for this looks clean, what I've read seems to indicate
this isn't such a good idea due to performance issues.

What else would I do?

Thanks
Turgs
--~--~-~--~~~---~--~~
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
-~--~~~~--~~--~--~---