Laravel Classroom image

Anil  Bist / Professional / 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
2
3 // application/controllers/account.php
4 class Account_Controller extends Base_Controller
5 {
6
7 public function action_index()
8 {
9 echo "This is the profile page.";
10 }
11
12 public function action_login()
13 {
14 echo "This is the login form.";
15 }
16
17 public function action_logout()
18 {
19 echo "This is the logout action.";
20 }
21
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 :

 
 
 
image
Anil  Bist

Skills    Laravel

Qualifications :- High School - SLV, College/University - Graphic Era Deemed Univ University,
Location :-Dehradun,Dehradun,Uttarakhand,India
Description:-

I started my Professional Journey in 2006 with one of the Web Development Company in Bangalore and my 1st framework was "Ruby on Rail" as Web development and delivered around 5+ Projects using this platform. Then came another dimension as JEE/Sturst framework, Gradually I realized that I want to build something on my own and give my passion and energy on creating something different a
Explore

 

  Students (0)