Ordinarily, I'd suggest you dump the requestAction() calls and put the
logic in your model and call it from there. But you need to paginate,
so it has to be in the controller. In that case, you could put the
pagination logic in ProfilesController. As for the shout_to() method,
you could probably put that in the model.
public $uses = array('Profile', 'Shout');
public paginate = array(
'Shout' => array(
'fields' => array(
'Shout.id',
'Shout.created',
'Shout.body',
'Shout.is_hidden',
'Shout.is_deleted',
'Shout.is_deleted_by_shouter',
'Shout.from_profile_id',
'FromProfile.nickname',
),
'contain' => array(
'FromProfile',
),
'conditions' => array('Shout.profile_id' => $profileId),
'order' => 'created DESC',
'limit' => 1
)
);
function view($id = null) {
if (!$id) {
$this->Session->setFlash(__('Invalid Profile.',
true));
$this->redirect(array('action'=>'index'));
}
$this->set('profile', $this->Profile->read(null, $id));
$this->set('shouts', $this->paginate('Shout'));
$this->set('shoutbox', $this->Shout->shout_to($id));
}
On Mon, Oct 5, 2009 at 2:05 PM, [email protected]
<[email protected]> wrote:
>
> Hello,
>
> I have a ProfilesController that got an action "view" and a
> ShoutsController that got the actions "index" and "shouts"
>
>
> // In ProfilesController
>
> function view($id = null) {
> if (!$id) {
> $this->Session->setFlash(__('Invalid Profile.', true));
> $this->redirect(array('action'=>'index'));
> }
> $this->set('profile', $this->Profile->read(null, $id));
> $this->set('shouts', $this->requestAction(
> array('controller' => 'shouts', 'action' => 'index'),
> array('return', 'pass' => array($id))));
> $this->set('shoutbox', $this->requestAction(
> array('controller' => 'shouts', 'action' =>
> 'shout_to'),
> array('return', 'pass' => array($id))));
> }
>
>
> // in ShoutsController
>
> function index($profileId = null) {
> $this->Shouts->recursive = 0;
> $this->paginate = array(
> 'fields' => array(
> 'Shout.id',
> 'Shout.created',
> 'Shout.body',
> 'Shout.is_hidden',
> 'Shout.is_deleted',
> 'Shout.is_deleted_by_shouter',
> 'Shout.from_profile_id',
> 'FromProfile.nickname',
> ),
> 'contain' => array(
> 'FromProfile',
> ),
> 'conditions' => array('Shout.profile_id' =>
> $profileId),
> 'order' => 'created DESC',
> 'limit' => 1,
> );
> $this->set('shouts', $this->paginate());
> }
>
> function shout_to($toProfileId = null) {
> if ($toProfileId != null and !empty($this->data)) {
> $this->Shout->create();
> $this->Shout->set(array(
> 'user_id' => $this->Auth->user('id'),
> 'profile_id' => $toProfileId,
> 'from_profile_id' =>
> $this->Shout->Profile->getAuthedId($this-
>>Auth->user())));
> if ($this->Shout->save($this->data, true,
> array('user_id', 'profile_id',
> 'from_profile_id', 'body'))) {
> $this->Session->setFlash(__('The Shout has
> been saved', true));
> } else {
> $this->Session->setFlash(__('The Shout could
> not be saved. Please,
> try again.', true));
> }
> }
> if (isset($this->data['Shout']['has_shouted'])) {
> $this->redirect(array('controller' => 'profiles',
> 'action' =>
> 'view', $toProfileId));
> }
> }
>
> Now I have a question about passing forth and back information between
> the "parent calling action" ProfilesController::view() and the
> requested Actions.
>
> Everything works for me but on the shoutbox requestAction:
> - No form errors / validation errors displayed
> - Entered form data not inserted on validation error
>
> And on the shouts requestAction
> - pagination options: <?=$form->create('Shout', array('action' =>
> 'shout_to', 'url' => $this->passedArgs))?>
> Which logically is not added to behind as params to /profiles/view/5
>
> Any ideas on either of these issues?
>
> King regards
> Jonas Hartmann
> >
>
--~--~---------~--~----~------------~-------~--~----~
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
-~----------~----~----~----~------~----~------~--~---