matuuz
matuuz

Reputation: 135

Laravel connection between controller, views and routes

i'm new to laravel and i'm trying to figure out how to link views and urls.. i have this HomeController.php:

class HomeController extends BaseController {

    protected $layout = 'layouts.master';

    public function index(){

        $this->layout->title = 'Web Title';
        $this->layout->content = View::make('home');

    }

}

it has a layouts.master (views/layouts/master.blade.php) with this content:

<!doctype html>
<html>
<head>
    <meta charset="UTF-8">
    <title>{{ title }}</title>
    <link type="text/css" rel="stylesheet" href="{{URL::asset('css/styles.css')}}" />
</head>
<body>
    <div class="wrapper">
        <div class="header">

        </div>
        <div class="sidebar">
            asdasd
        </div>
        <div class="mainContent">
            @yield('content')
        </div><!--mainContent End-->
    </div>
</body>
</html>

this is home.blade.php inside root "views" folder

@section('content')
    <div class="userSearchInfo">
        <div class="userPhoto"></div>
        <div class="userData">
            <div class="userName">
                Name
            </div>
        </div>
    </div>
@stop

and finally routes.php, i think here's the problem, i don't understand if it's ok or not, it varies from website to website, i don't really know what i should use, laravel api is not good at all, no information about this

Route::get('/', 'HomeController@index');

Hope you can help, thanks.

Upvotes: 3

Views: 3519

Answers (1)

The Alpha
The Alpha

Reputation: 146191

In your routes.php file you declare the URLs you application responds to, for example, you have following route declaration in your routes.php file:

Route::get('/', 'HomeController@index');

It tells the framework that, whenever a request to landing page is made, the index method of HomeController controller should be invoked.

So, a route is used to register a URL in your application and on the request of that URL the action registered with that route will be taken. In your example, / is the URL for landing/home page and action you have registered for that URL is 'HomeController@index', it means index method will be executed from the HomeController.

Enable, debug mode by setting debug => true from app/config/app.php file so you can track the errors because after enabling the debug mode, you'll get informative error details. Also, Laravel is the best place to learn the basic about the framework, so read the documentation properly.

Upvotes: 4

Related Questions