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

From mi-linux
Jump to navigationJump to search
(Created page with "Main Page >> Advanced Web Development >> Workbook >> Week 02 == Installing Codeigniter == First, install CodeIgniter, using Composer, or...")
 
 
(9 intermediate revisions by the same user not shown)
Line 1: Line 1:
 
[[Main Page]] >> [[6CS028|Advanced Web Development]] >> [[6CS028 - Workbook|Workbook]] >> Week 02
 
[[Main Page]] >> [[6CS028|Advanced Web Development]] >> [[6CS028 - Workbook|Workbook]] >> Week 02
  
== Installing Codeigniter ==
+
== Installing a PHP Web Framework ==
First, install CodeIgniter, using Composer, or manually:
+
First, decide which PHP framework you would like to use.
* [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:
+
I recommend either:
<pre>
+
* [https://codeigniter.com/ https://codeigniter.com/]
chmod 755 ci4-composer/ -R
+
* [https://laravel.com/ https://laravel.com/]
chmod 777 ci4-composer/writable/ -R
 
</pre>
 
  
You will also need to update a couple of config files (located in '''app/Config''').
+
=== CodeIgniter ===
  
In '''App.php''', populate the base URL with the URL to the folder where you installed CodeIgniter, for example for mine I have put:
+
This week, go through the following steps of the tutorial:
<pre>
+
* [https://codeigniter.com/user_guide/installation/index.html Installation]
public $baseURL = 'https://mi-linux.wlv.ac.uk/~in9352/ci4/public/';
+
* [https://codeigniter.com/user_guide/tutorial/static_pages.html Static Pages]
</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:
+
Then read the following concepts, to consolidate your understanding of the above:
<pre>
+
* [https://codeigniter.com/user_guide/concepts/index.html CodeIgniter4 Overview]
        'username' => '',
+
* [https://codeigniter.com/user_guide/general/index.html General Topics]
        'password' => '',
+
* [https://codeigniter.com/user_guide/incoming/index.html Controllers and Routing]
        'database' => '',
+
* [https://codeigniter.com/user_guide/outgoing/index.html Building Responses]
</pre>
 
  
== Tutorial part 1 - Static pages==
+
=== Laravel ===
Then please work through part 1 of the tutorial:
 
* [https://codeigniter.com/user_guide/tutorial/static_pages.html Tutorial part 1 - Static pages]
 
  
Take your time, read the instructions carefully, and ask questions in the workshops if you get stuck.
+
This week, read the following sections of the documentation:
 +
* [https://laravel.com/docs/10.x/lifecycle Read the Architecture Concepts]
 +
* [https://laravel.com/docs/10.x/routing The Basics]
  
'''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.'''
+
And work through the Bootcamp tutorial:
 
+
* [https://bootcamp.laravel.com/inertia/installation Installation]
Here is mine, to give you an idea of what it should look like once completed:
+
* [https://bootcamp.laravel.com/inertia/creating-chirps Creating Chirps]
[https://mi-linux.wlv.ac.uk/~in9352/ci4/public/index.php/pages/view/home https://mi-linux.wlv.ac.uk/~in9352/ci4/public/index.php/pages/view/home]
+
* [https://bootcamp.laravel.com/inertia/showing-chirps Showing Chirps]
 
 
== 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:
 
 
 
<pre>
 
public $baseURL = 'https://mi-linux.wlv.ac.uk/~in9352/ci4/public/';
 
</pre>
 
 
 
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:
 
<pre>
 
<img src="<?=base_url('images/funny-cats.jpg')?>" alt="Funny cat" width=300>
 
</pre>
 
 
 
The result: [https://mi-linux.wlv.ac.uk/~in9352/ci4/public/index.php/pages/view/home https://mi-linux.wlv.ac.uk/~in9352/ci4/public/index.php/pages/view/home]
 
 
 
Note: The same would work with CSS files, JavaScript files etc.
 
 
 
=== Hiding "index.php" using URL rewriting ===
 
 
 
Edit the .htaccess file located in the public folder, and look inside the IfModule mod_rewrite.c block.
 
 
 
Populate the RewriteBase value with your base URL, like this:
 
 
 
<pre>
 
RewriteBase /~in9352/ci4/public/
 
</pre>
 
 
 
Then add the following lines at the end of the block (right before the /IfModule):
 
<pre>
 
RewriteCond $1 !^(index\.php|images|robots\.txt)
 
RewriteCond %{REQUEST_URI} !\.(css|gif|ico|jpg|js|png|swf|txt)$
 
RewriteRule ^(.*)$ index.php/$1 [L]
 
</pre>
 
 
 
Working example here:
 
* With index.php: [https://mi-linux.wlv.ac.uk/~in9352/ci4/public/index.php/pages/view/home https://mi-linux.wlv.ac.uk/~in9352/ci4/public/index.php/pages/view/home]
 
* Without index.php: [https://mi-linux.wlv.ac.uk/~in9352/ci4/public/pages/view/home https://mi-linux.wlv.ac.uk/~in9352/ci4/public/pages/view/home]
 
 
 
Both work (the second one is mapped to the first one behind the scenes).
 

Latest revision as of 12:44, 17 January 2024

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

Installing a PHP Web Framework

First, decide which PHP framework you would like to use.

I recommend either:

CodeIgniter

This week, go through the following steps of the tutorial:

Then read the following concepts, to consolidate your understanding of the above:

Laravel

This week, read the following sections of the documentation:

And work through the Bootcamp tutorial: