Codeigniter Controller
Codeigniter Controller |
A controller is a simple class file. As the name suggests, it controls the whole application by URI.
How to Install Codeigniter
codeigniter configuration Route:
In CI code will run without routes.php. routes.php are use to customise the url/routes like if you have url like
example.com/pages/about_us
where "pages" is your controller and "about_us" is method in that controller, if you want to show url without controller like example.com/about_us, then you need to use routes.php in this way
$route['about_us'] = ['pages/about_us'];
Configuration Route:
Go to Codeigniter/application/config/ and open routes.php
now Find out
without Route Your URL will Look like that : http://localhost/codeigniter/index.php/welcome
$route['default_controller'] = 'welcome';
Affter Rote URl Your URL will look like: http://localhost/codeigniter
Here 'welcome' is our Conroller Name..
You can Load Controller Function by Replacing welcome..
1.Creating Controller:
Go to Your Codeigniter/application/controllers and create welcome.php file
<?php defined('BASEPATH') OR exit('No direct script access allowed'); class Welcome extends CI_Controller { public function index() { $this->load->view('welcome_user'); } public function about(){ echo "This is About Page"; } public function author(){ echo "This is Author Page"; } }
Note: Welcome is Class name and The class name must start with uppercase letter but we need to write lowercase letter when we call that controller by URI. index,about and author is Method of Welcome.
$this->load->view('welcome_message');Here we call view to load welcome_user.php page from Codeigniter/application/view/
2.Creating View:
go to Codeigniter/application/view/ and create welcome_user.php
<html> <head> <title>Codeigniter Controller Examples-- http://codenair.com</title> </head> <h1>Welcome to Codeigniter Lession</h1> </html>3.Calling a Controller:
The above controller can be called by URI as follows −
- http://localhost/codeigniter/
- http://localhost/codeigniter/index.php/welcome/about
- http://localhost/codeigniter/index.php/welcome/author
Result:
No comments:
Post a Comment
Thank You for Your Comment
Note: Only a member of this blog may post a comment.