Reputation: 9351
**Route**
Route::get('admin', function()
{
return View::make('theme-admin.main');
});
**Controller**
class Admin_Controller extends Base_Controller {
public function action_index()
{
echo __FUNCTION__;
}
If I forward request to controller, then I have to define View::make
in every function in controller. If I don't forward it, action function
doesn't work.
Should I just forward requests to controller and use View::make
inside action functions or there are better alternatives?
Upvotes: 1
Views: 12646
Reputation: 10029
you can call the controller function like this
$app = app();
$controller = $app->make('App\Http\Controllers\EntryController');
return $controller->callAction('getEntry', $parameters = array());
or you can simply dispatch the request to another controller url
$request = \Request::create(route("entryPiont"), 'POST', array()));
return \Route::dispatch($request);
Upvotes: 0
Reputation: 21272
Actually isn't necessary to define View::make
in every function of your controllers.
You can, for example, execute an action and then redirect to another action, that could View::make
.
Let's say you want to create an user and then show its profile, in a RESTful way. You could do:
# POST /users
public function user_create()
{
$user = User::create(...);
// after you have created the user, redirect to its profile
return Redirect::to_action('users@show', array($user->id));
// you don't render a view here!
}
# GET /users/1
public function get_show($id)
{
return View::make('user.show');
}
Upvotes: 1