6CS028 Workshop - Web Frameworks

From mi-linux
Revision as of 12:59, 8 February 2013 by In9352 (talk | contribs)
Jump to navigationJump to search

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

Consider using a PHP framework for your assessment. Here are some popular ones:

Summary of findings

  • CodeIgniter: Works well. Possibly the most simple choice.
  • Yii: Works well. A bit more difficult to set-up than CodeIgniter, but the scaffolding option will save you a lot of time!
  • CakePHP: Works, but issues around caching, possibly because of the version of PHP installed on the server
  • 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

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.

From Windows simply start "Putty", installed in the all the labs, and free to download from home.

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.

CodeIgniter

I tested version 2.1.3

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:

[your-site-url]index.php/pages/view

So far example:

http://mi-linux.wlv.ac.uk/~in9352/codeigniter/index.php/pages/view

Go straight to the "News section" exercise, which will teach you about database access... much more important!

Yii

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:

'db'=>array(
	'connectionString' => 'mysql:host=localhost;dbname=XXX',
	'emulatePrepare' => true,
	'username' => 'XXX',
	'password' => 'XXX',
	'charset' => 'utf8',
),

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.

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

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

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:

<IfModule mod_rewrite.c>
   RewriteEngine on
   RewriteBase /~0123456/cake
   RewriteRule    ^$ app/webroot/    [L]
   RewriteRule    (.*) app/webroot/$1 [L]
</IfModule>

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.

/**
 * 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
));

Not ideal though :/

Symfony

I get this right away:

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)

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

Zend Framework

IMPORTANT: So far I have not managed to successfully install Zend on mi-linux :(