Even if it is possible, your approach is wrong according to MVC approach. A controller should not be aware of another controller. If you need to get some data from somewhere try using library or model instead of a controller, or you can implement get_latest()
method in the Home_Controller
Laravel - calling a page fragment from another controller (in a bundle)
题
I'm not sure if I'm going about things completely wrong here. But essentially what I want to be able to do is call a function within one of my bundles from my main application controller, is this kind of behaviour possible in Laravel.
The actual situation is that I have my home controller in /application/controllers/home.php which looks like this:
class Home_Controller extends Base_Controller {
public function action_index()
{
$blog = ?;
return View::make('common.html_template')->with($blog, 'blog');
}
}
I have also built a blog bundle with a controller in /bundles/blog/controllers/home.php which looks like this:
class Blog_Home_Controller extends Base_Controller {
public function get_latest()
{
//bit of code here
}
}
Is it possible to load the contents of get_latest to my $blog variable as a page fragment, or am I approaching this incorrectly.
解决方案
不隶属于 StackOverflow