Skip to content
Search
  • ServicesPage
  • Our workPage
  • BlogPage
  • AI solutionsPage
  • Contact usPage
All articles

Create a Static page with CodeIgniter

Masum · · 1 min read · CodeIgniter

Lets start by creating a file at application/controllers/pages.php with the following code.

Create a Static page with CodeIgniter

Now create a folder into views with the name ‘templates’ which will contain the common parts of your template file.

Create a Static page with CodeIgniter

Create two file into ‘templates’ with names ‘header.php and footer.php’ and add the following codes.

Header.php

Create a Static page with CodeIgniter

Footer.php

Create another folder into view with the name ‘pages’ which will contain only body part of pages. For example you want to create a page name ‘home.php’. Only body Body part will be written in this page.

Create a Static page with CodeIgniter

Inside this folder create a page name ‘home.php’ and write a welcome message as below.

Create a Static page with CodeIgniter

Now edit application/controllers/pages.php page as below –

Create a Static page with CodeIgniter

Now open up a browser and type in http://localhost/CodeIgniter/index.php/pages/view. Hopefully you will see your home page –

Create a Static page with CodeIgniter

Now let me break down why the URL will be like this http://localhost/CodeIgniter/index.php/pages/view

  • http://localhost/ [ your localhost ]
  • CodeIgniter/ [ your CodeIgniter folder name ]
  • index.php/ [ by default from CodeIgniter ]
  • pages/ [ your Controller name ]
  • view [ your class name]

If you want some controller to load automatically then follow the steps below

Open “routes.php”, this is located in “/application/config/” relative to your root directory of CodeIgniter, for us, that would be “C:wampwwwCodeIgniterapplicationconfig”

Create a Static page with CodeIgniter

On line 41, you will notice:

code
$route['default_controller'] = "welcome";

It should be:

code
$route['default_controller'] = "pages/view";
Create a Static page with CodeIgniter

Now visit http://localhost/CodeIgniter/ and that will display your home.php page.

More to read

Have a project in mind?

Tell us what you need. We get back to you as soon as possible.

Start a project