How Codeigniter works
How Codeigniter works is the one of the query which arises in the mind of every individual who is new to CI. Following are the steps which will help you to clarify such sort of questions.
- Start WAMP/XAMPP/LAMP server.
- Run your Codeigniter page/folder.
- Click on application -> controller -> welcome.php
- Here we can load function, views from the controller.
- Set Base path
- SYNTAX: defined(“BASEPATH”). OR exit(“no direct script access allowed”);
This line is used as session for the security. It will restrict the user from directly accessing the page.
How to create new method in page?
To create a new method , create a new function.
public function myindex()
echo “my Index”;
To run this method, write the following in the address bar:
Existing or New View in CI
Here is the view named welcome_message
- welcome_message is the view of welcome on index.php function.
- If you want to make changes in welcome_message or any other existing view then make changes in the code of that particular view.
If there is no index function and user also doesn’t mention any function/controller then it will gives us an error of 404 i.e page not found.
Syntax to load another view in the new function
where ‘myindex_view‘ is the name of new view
How to control new controller?
- click on controller -> create -> save as with name ‘My_controller.php’
class My_controller extends CI_Controller
public function index()
echo “This is my new controller”;
To use this , write following:
How to remove INDEX.PHP from url?
goto config -> config.php -> $config[‘base_url’]=””;
- remove existing url from this base_url .
- write your own url in this space.