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

From mi-linux
Jump to navigationJump to search
 
(149 intermediate revisions by 2 users not shown)
Line 1: Line 1:
[[Main Page]] >> [[6CC001|Advanced Web Technologies]] >> [[6CC001 - Workbook|Workbook]] >> Week 02
+
[[Main Page]] >> [[6CS028|Advanced Web Development]] >> [[6CS028 - Workbook|Workbook]] >> Week 03
  
Consider using a PHP framework for your assessment. Here are some popular ones:
+
== PHP Web Frameworks and databases ==
  
==Summary of findings==
+
=== CodeIgniter ===
  
*'''<span style="color:#00C600">CodeIgniter</span>''': Works well. Possibly the most simple choice.
+
This week, go through the following steps of the tutorial:
*'''Yii''': Works well. A bit more difficult to set-up than CodeIgniter, but the scaffolding option will save you a lot of time!
+
* [https://codeigniter.com/user_guide/tutorial/news_section.html News Section]
*'''CakePHP''': Works, but issues around caching, possibly because of the version of PHP installed on the server
+
* [https://codeigniter.com/user_guide/tutorial/create_news_items.html Create News Items]
*'''Symfony''': Warning about version of PHP being too old. I didn't go any further.
 
*'''Akelos''': Not tested yet.
 
*'''Zend Framework''': NOT WORKING :(
 
  
==Command line==
+
Then read the following sections of the documentation, to consolidate the above:
 +
* [https://codeigniter.com/user_guide/database/index.html Working With Databases]
  
Some of the frameworks expect you to type commands, using the command line. Don't let it put you off, unless you know absolutely NOTHING about Linux commands.
+
=== Laravel ===
  
From Windows simply start "Putty", installed in the all the labs, and [http://www.chiark.greenend.org.uk/~sgtatham/putty/ free to download] from home.
+
This week, read the following sections of the documentation:
 +
* [https://laravel.com/docs/10.x/database Database]
  
When starting Putty simply type "mi-linux.wlv.ac.uk" in the "host name" box, and press "enter". Then log in using your normal details.
+
And work through the remaining sections of the Bootcamp tutorial:
 
+
* [https://bootcamp.laravel.com/inertia/editing-chirps Editing Chirps]
==CodeIgniter ==
+
* [https://bootcamp.laravel.com/inertia/deleting-chirps Deleting Chirps]
 
+
* [https://bootcamp.laravel.com/inertia/notifications-and-events Notifications & Events]
I tested version 2.1.3
 
 
 
*[http://codeigniter.com/ CodeIgniter homepage]
 
*[http://ellislab.com/codeigniter/user-guide/tutorial/static_pages.html Getting started tutorial]
 
 
 
Nothing too complicated in the tutorial above, however I would recommend that you skip the "Routing" section for now, as it make the format of the URL more confusing. Stick to the standard format for now:
 
 
 
<pre>
 
[your-site-url]index.php/pages/view
 
</pre>
 
 
 
So far example:
 
 
 
<pre>
 
http://mi-linux.wlv.ac.uk/~in9352/codeigniter/index.php/pages/view
 
</pre>
 
 
 
Go straight to the "News section" exercise, which will teach you about database access... much more important!
 
 
 
==Yii==
 
 
 
I tested version 1.1.13
 
 
 
*[http://www.yiiframework.com/ Yii homepage]
 
*[http://www.yiiframework.com/doc/guide/1.1/en/quickstart.installation Getting started tutorial]
 
 
 
Nothing too difficult here. Ignore the "Apache and Nginx configurations" step for now and go straight to the "Creating First Yii Application" step.
 
 
 
When browsing to your newly created application you might get the odd error message telling you to make certain folders writable.
 
 
 
'''Mysql Database'''
 
 
 
By default Yii is set up to access an SQLite database. If you want to use Mysql you will need to edit the protected/config/main.php file, uncomment the following block and add your usual Mysql connection details:
 
 
 
<pre>
 
'db'=>array(
 
'connectionString' => 'mysql:host=localhost;dbname=XXX',
 
'emulatePrepare' => true,
 
'username' => 'XXX',
 
'password' => 'XXX',
 
'charset' => 'utf8',
 
),
 
</pre>
 
 
 
===Gii===
 
 
 
Gii is a new tool that allows you to generate code from the database (aka Scaffolding in the lecture slides). You enable it by uncommenting the following block in the protected/config/main.php file.
 
 
 
<pre>
 
'gii'=>array(
 
'class'=>'system.gii.GiiModule',
 
'password'=>'1234',
 
// If removed, Gii defaults to localhost only. Edit carefully to taste.
 
'ipFilters'=>array('134.220.251.99','::1'),
 
),
 
</pre>
 
 
 
Note: you need to specify your own password. Also I've had to put my IP address in the last field, or else the page was telling me I wasn't allowed in! On Windows you can get your IP address by opening a command line window and typing the command "ipconfig".
 
 
 
Other than that this seems to work quite well :) Obviously Gii can only create the php file if you make the folders writable (e.g. to generate a model class, you need to make the protected/models folder writable!)
 
 
 
==CakePHP==
 
 
 
I tested version 2.3.0
 
 
 
*[http://cakephp.org/ CakePHP homepage]
 
*[http://book.cakephp.org/2.0/en/getting-started.html Getting started tutorial]
 
 
 
===mod_rewrite===
 
 
 
Note that because of the way mod_rewrite is set up on the server you need to '''add a RewriteBase line''' in the '''existing''' .htaccess file, as follow:
 
 
 
<pre>
 
<IfModule mod_rewrite.c>
 
  RewriteEngine on
 
  RewriteBase /~0123456/cake
 
  RewriteRule    ^$ app/webroot/    [L]
 
  RewriteRule    (.*) app/webroot/$1 [L]
 
</IfModule>
 
</pre>
 
 
 
IMPORTANT: Replace "0123456" with your student number and "cake" by the folder in which you have uploaded the framework.
 
 
 
Alternatively you could NOT use mod_rewrite, the tutorial above tells you how (see "A Note on mod_rewrite" section)
 
 
 
===Cache===
 
 
 
If you are getting the following error message:
 
 
 
''Warning: _cake_core_ cache was unable to write 'cake_dev_en-gb' to File cache in /studhome/staff/acad/in9352/public_html/cake/lib/Cake/Cache/Cache.php on line 309''
 
 
 
You need to make the "app/tmp" folder (and all its sub-folders) '''writable''' by all in order to solve this.
 
 
 
If you are still getting cache errors/warnings after this, it might be because the version of PHP running on the server is too old, and caching doesn't work (we have 5.2.4 and the documentation says it should be 5.2.8 or more). You could always disable the cache in the Config/core.php file. Simply '''remove''' the following blocs located at the bottom of the file.
 
 
 
<pre>
 
/**
 
* Configure the cache used for general framework caching.  Path information,
 
* object listings, and translation cache files are stored with this configuration.
 
*/
 
Cache::config('_cake_core_', array(
 
'engine' => $engine,
 
'prefix' => $prefix . 'cake_core_',
 
'path' => CACHE . 'persistent' . DS,
 
'serialize' => ($engine === 'File'),
 
'duration' => $duration
 
));
 
 
 
/**
 
* Configure the cache for model and datasource caches.  This cache configuration
 
* is used to store schema descriptions, and table listings in connections.
 
*/
 
Cache::config('_cake_model_', array(
 
'engine' => $engine,
 
'prefix' => $prefix . 'cake_model_',
 
'path' => CACHE . 'models' . DS,
 
'serialize' => ($engine === 'File'),
 
'duration' => $duration
 
));
 
</pre>
 
 
 
Not ideal though :/
 
 
 
==Symfony==
 
 
 
I tested version 2.1.7
 
 
 
*[http://symfony.com/ Symfony homepage]
 
*[http://symfony.com/doc/current/book/installation.html Getting started tutorial]
 
 
 
I get this right away:
 
 
 
<pre>
 
ERROR
 
PHP version must be at least 5.3.3 (5.2.4-2ubuntu5.26 installed)
 
Install PHP 5.3.3 or newer (installed version is 5.2.4-2ubuntu5.26)
 
</pre>
 
 
 
There might be ways around it, but frankly it is not very encouraging. I have logged a call with IT Services to get PHP updated... Wait and see :)
 
 
 
==Akelos==
 
 
 
I tested version 1.0.1
 
 
 
*[http://www.akelos.org/ Akelos homepage]
 
*[http://www.akelos.org/docs/tutorials Getting started tutorial]
 
 
 
==Zend Framework==
 
 
 
I tested version 2.1.1
 
 
 
*[http://framework.zend.com/ Zend Framework homepage]
 
*[http://zf2.readthedocs.org/en/latest/user-guide/overview.html Getting started tutorial]
 
 
 
'''IMPORTANT''': So far I have not managed to successfully install Zend on mi-linux :(
 

Latest revision as of 12:44, 17 January 2024

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

PHP Web Frameworks and databases

CodeIgniter

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

Then read the following sections of the documentation, to consolidate the above:

Laravel

This week, read the following sections of the documentation:

And work through the remaining sections of the Bootcamp tutorial: