Using the output of another action in the current action

In my application I have a 'person' controller

The action 'search' returns a list of people.

This action is used in an ajax call to display the list of people.

The action 'show' displays data for one person.

But I also want the list of people (from the 'search' action) to be displayed.

How can I use the action 'search' in the action 'show' to render this list of people into the layout?

Is there an elegant way of doing this (not calling an action from a view)?

Having a function (which would not be an action) to return the lst of people and use it in both actions ?

like

where getPeople returns an array of people

or did I get you wrong ?

Quote

You code should be

getPeople() may be better put in the model than in the controller

Thanx for thinking about the problem.

There is still a minor issue: the 'search' action already uses a view, hence the result is an html snippet. It is that snippet which I would also like to use when rendering the complete layout.

You are right, I could have a function in the controller to generate this html snippet, but I think it does not belong there, since controllers pass data to views but should not contain/generate html.

While writing about this I am realizing that a widget might be the best solution.

@will : thanks for correctin

@sluderitz :

have a look at renderPartial (controller method) this may be what you are looking for