6CS028 Workshop - Web Frameworks

From mi-linux
Jump to navigationJump to search

Main Page >> Advanced Web Development >> Workbook >> Week 02

Codeigniter

Please install Codeigniter and work through the first part of the tutorial:

Installing Codeigniter

You can install either using Composer, or manually:

Either way, you will then need to set the correct file permissions via Putty, as follow:

chmod 755 ci4-composer/ -R
chmod 777 ci4-composer/writable/ -R

You will also need to update a couple of config files (located in app/Config).

In App.php, populate the base URL with the URL to the folder where you installed CodeIgniter, for example for mine I have put:

public $baseURL = 'https://mi-linux.wlv.ac.uk/~in9352/ci4/public/';
  • in9352 should be replaced with your student number
  • ci4 is the name of the folder in which you installed the framework
  • public has to be there.

You also need to populate your MySQL connection details in the Database.php file:

        'username' => '',
        'password' => '',
        'database' => '',

Tutorial part 1 - Static pages

Then please work through part 1 of the tutorial:

Take your time, read the instructions carefully, and ask questions in the workshops if you get stuck.

IMPORTANT: Remember that every time you create a new file or folder on the server, you need to set the permissions via Filezilla or Putty, or else you will get "Permission denied" errors.

Here is mine, to give you an idea of what it should look like once completed: https://mi-linux.wlv.ac.uk/~in9352/ci4/public/index.php/pages/view/home

Further information

How to include external files (images, css files, js files) on my pages

First make sure your base URL is populated in your config file, as explained above:

public $baseURL = 'https://mi-linux.wlv.ac.uk/~in9352/ci4/public/';

Then upload your files in your "codeigniter/public" folder, or in suitable sub-folders (codeigniter/public/images, codeigniter/public/css and codeigniter/public/js). Do NOT upload the files into your codeigniter/app folder or any of its sub folders.

In the example below I have uploaded an image file here:

  • ci4/public/images/funny-cats.jpg

Important: Remember file permissions!

Then in my view, I used the base_url() helper:

<img src="<?=base_url('images/funny-cats.jpg')?>" alt="Funny cat" / width=300>

The same would work with CSS files, JavaScript files etc.

Hiding "index.php" using URL rewriting

Create a .htaccess file in your CodeIgniter root folder, and paste the following rules inside it:

RewriteEngine on
RewriteBase /~in9352/codeigniter3/
RewriteCond $1 !^(index\.php|images|robots\.txt)
RewriteCond %{REQUEST_URI} !\.(css|gif|ico|jpg|js|png|swf|txt)$
RewriteRule ^(.*)$ index.php/$1 [L]

Note: replace "in9352" by your student number.

Working example here: http://mi-linux.wlv.ac.uk/~in9352/codeigniter3/news/index