Laravel Classroom image

Prashant  Nigam / Student / Web Technology

To post your Question Join Classroom
Lesson Topics's No:-  |1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9|Last
Lessons:-Using Controllers

Using Controllers
In this chapter we will be creating a simple multi page website to demonstrate the workings of
Laravel’s routing system, without delving into anything too complicated.
As I mentioned in the previous chapter, there are two options available to route web requests
to your code, Controllers and Routes. In this chapter we will be using Controllers since anyone
joining us from other frameworks will be more familiar with them.
3.1 Routing Controllers
So let’s start by taking a look at a Controller :
1 <?php
3 // application/controllers/account.php
4 class Account_Controller extends Base_Controller
5 {
7 public function action_index()
8 {
9 echo "This is the profile page.";
10 }
12 public function action_login()
13 {
14 echo "This is the login form.";
15 }
17 public function action_logout()
18 {
19 echo "This is the logout action.";
20 }
22 }
A Controller is a PHP Class that represents a section of your website, or web application. Its
Methods or ‘Actions’ represent an individual page, or an end-point of a HTTP request.
In the above example our Account Controller represents our users section of the web site, a
profile page, a login page, and a logout page. Note that the Controller names are appended with
_Controller and that action names are prefixed with action_. Controllers must extend the
Base_Controller, Controller or another Controller class.
Our controller is created in the application/controllers directory as a lower-case file matching
the controller name. The Controller above would be saved at :


Prashant  Nigam

Skills    Laravel

Qualifications :-
Location :-,,,

  Students (0)