OK, I have been playing with this.
My projects controller is this:
##########################
<?php
class ProjectsController extends AppController {
var $name = 'Projects';
var $layout = 'frontend';
var $helpers = array('Html', 'Form', 'Javascript', 'Ajax' );
var $scaffold;
function add()
{
if (!empty($this->params['data']))
{
if ($this->Project->save($this->params['data']))
{
$this->set('tasks',
$this->requestAction('/tasks/index')); // the
view I would like to grab belongs to the Tasks object/controller
$this->render('tasks', 'ajax');
}
else
{
// do nothing
}
}
}
}
?>
But i get the following error:
##########################
You are seeing this error because the view for
ProjectsController::tasks() could not be found.
Cake is looking for a view of the current object which is Projects.
Any ideas?
On Feb 13, 11:08 pm, "Dat Chu" <[EMAIL PROTECTED]> wrote:
> Renderring a view of a different Controller is the same as rendering a
> view of the same controller. (Using AJAX helper).
>
> [EMAIL PROTECTED], my first thought when I see your approach is: it violates
> MVC.
> However, upon further look I think it actually make sense since there
> is no use in duplicating view code, UsersController does what it knows
> best: controlling users. Thus, forcing MVC => retrieving user list
> from User model then display it is actually violating encapsulation in
> OOP.
>
> On Feb 13, 4:48 pm, "[EMAIL PROTECTED]" <[EMAIL PROTECTED]> wrote:
>
> > I see. I wonder if requestAction could help you there?
> > The cake manual page seems to infer that it might do what you want.
>
> > Here's an excerpt fromhttp://manual.cakephp.org/chapter/controllers
>
> > If you have an often used element in your application that is not
> > static, you might want to use requestAction() to inject it into your
> > views. Let's say that rather than just passing the data from
> > UsersController::getUserList, we actually wanted to render that
> > action's view (which might consist of a table), inside another
> > controller. This saves us from duplicating view code.
> > class ProgramsController extends AppController
> > {
> > function viewAll()
> > {
> > $this->set('userTable', $this->requestAction('/users/
> > getUserList', array('return')));
>
> > // Now, we can echo out $userTable in this action's view to
> > // see the rendered view that is also available at /users/
> > getUserList.
> > }
>
> > }
>
> > Please note that actions called using requestAction() are rendered
> > using an empty layout - this way you don't have to worry about layouts
> > getting rendered inside of layouts.
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups "Cake
PHP" 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
-~----------~----~----~----~------~----~------~--~---