Difference between revisions of "6CS028 Workshop - Web Frameworks"

From mi-linux
Jump to navigationJump to search
Line 6: Line 6:
 
* [https://codeigniter.com/user_guide/installation/index.html Installing CodeIgniter]
 
* [https://codeigniter.com/user_guide/installation/index.html Installing CodeIgniter]
 
* [https://codeigniter.com/user_guide/tutorial/static_pages.html Tutorial part 1 - Static pages]
 
* [https://codeigniter.com/user_guide/tutorial/static_pages.html Tutorial part 1 - Static pages]
 +
 +
== Installing Codeigniter ==
 +
You can install either using Composer, or manually:
 +
* [https://codeigniter.com/user_guide/installation/installing_composer.html Composer Installation]
 +
* [https://codeigniter.com/user_guide/installation/installing_manual.html Manual Installation]
 +
 +
Either way, you will then need to set the correct file permissions via Putty, as follow:
 +
<pre>
 +
chmod 755 ci4-composer/ -R
 +
chmod 777 ci4-composer/writable/ -R
 +
</pre>
 +
 +
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:
 +
<pre>
 +
public $baseURL = 'https://mi-linux.wlv.ac.uk/~in9352/ci4/public/';
 +
</pre>
 +
* 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:
 +
<pre>
 +
        'username' => '',
 +
        'password' => '',
 +
        'database' => '',
 +
</pre>
  
 
=== How to include external files (images, css files, js files) on my pages ===
 
=== How to include external files (images, css files, js files) on my pages ===

Revision as of 14:42, 21 January 2022

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' => '',

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

First make sure your base URL is populated in your config.php file, so for example for me:

$config['base_url']='http://mi-linux.wlv.ac.uk/~in9352/codeigniter3/';

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

In the example below I have uploaded an image and a CSS file at the following locations:

  • codeigniter3/css/style.css
  • codeigniter3/funnycat.jpg

Finally use the "Base URL" helper in your view:

<?php $this->load->helper('url');?>
<html>
<head>
   <title><?php echo $title ?> - CodeIgniter 2 Tutorial</title>
   <link rel="stylesheet" type="text/css" href="<?=base_url("css/style.css")?>">
</head>
<body>
   <h1>CodeIgniter Tutorial</h1>
<p>
<img src="<?=base_url("funnycat.jpg")?>">
</p>  

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