|
|
(81 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 === |
| | | |
− | *CodeIgniter: Possibly the easiest one the learn first (flexible, no command line)
| + | This week, go through the following steps of the tutorial: |
− | *Yii: A bit more tricky as you need to run a few commands (to create an app, to use scaffolding)
| + | * [https://codeigniter.com/user_guide/tutorial/news_section.html News Section] |
− | *CakePHP: Quite simple to install (no command line required), but might be a bit more difficult to learn (I can't get mod rewrite to work at the moment) | + | * [https://codeigniter.com/user_guide/tutorial/create_news_items.html Create News Items] |
− | *Symfony: WORK IN PROGRESS | |
| | | |
− | ==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] |
− | ===Useful commands===
| + | * [https://bootcamp.laravel.com/inertia/deleting-chirps Deleting Chirps] |
− | | + | * [https://bootcamp.laravel.com/inertia/notifications-and-events Notifications & Events] |
− | To make a whole folder + sub-folders readable and executable by all:
| |
− | <pre>
| |
− | chmod 755 codeigniter/ -R
| |
− | </pre>
| |
− | | |
− | To remove a whole folder (WARNING - CANNOT BE UNDONE)
| |
− | <pre>
| |
− | rm codeigniter/ -R
| |
− | </pre>
| |
− | | |
− | ==CodeIgniter ==
| |
− | | |
− | I tested version 2.1.4:
| |
− | *[http://ellislab.com/codeigniter Framework's homepage]
| |
− | | |
− | First install CodeIgniter using this tutorial:
| |
− | *[http://ellislab.com/codeigniter/user-guide/installation/index.html Installation Instructions]
| |
− | | |
− | If successfully installed you should see this page:
| |
− | *[http://mi-linux.wlv.ac.uk/~in9352/codeigniter/ http://mi-linux.wlv.ac.uk/~in9352/codeigniter/]
| |
− | | |
− | Note: replace "in9352" with your student number and "codeigniter" with the folder name in which you have installed the framework.
| |
− | | |
− | Then work through the first few tutorials:
| |
− | *[http://ellislab.com/codeigniter/user-guide/tutorial/static_pages.html Static pages]
| |
− | *[http://ellislab.com/codeigniter/user-guide/tutorial/news_section.html News section]
| |
− | *[http://ellislab.com/codeigniter/user-guide/tutorial/create_news_items.html Create news items]
| |
− | | |
− | Nothing too complicated in the tutorials 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/controller/method
| |
− | </pre>
| |
− | | |
− | So far example:
| |
− | | |
− | <pre>
| |
− | http://mi-linux.wlv.ac.uk/~in9352/codeigniter/index.php/pages/view
| |
− | </pre>
| |
− | | |
− | ===Link to external CSS, JS, Images etc===
| |
− | | |
− | Make sure your base URL is populated in your config.php file, so for example for me:
| |
− | | |
− | <pre>
| |
− | $config['base_url']='http://mi-linux.wlv.ac.uk/~in9352/codeigniter/';
| |
− | </pre>
| |
− | | |
− | And then in your view use the URL helper:
| |
− | | |
− | <pre>
| |
− | <?$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 2 Tutorial</h1>
| |
− | <p>
| |
− | <img src="<?=base_url("funnycat.jpg")?>">
| |
− | </p>
| |
− | </pre>
| |
− | | |
− | ==Yii==
| |
− | | |
− | I tested version 1.1.14:
| |
− | *[http://www.yiiframework.com/ Yii homepage] | |
− | | |
− | Note: you may want to download the .zip archive from the [http://www.yiiframework.com/download/ downloads] section, it's easier to work with on Windows.
| |
− | | |
− | You can start here:
| |
− | *[http://www.yiiframework.com/doc/guide/1.1/en/quickstart.installation Getting started tutorial] | |
− | | |
− | Ignore the "Apache and Nginx configurations" step for now and go straight to the "Creating First Yii Application" step.
| |
− | | |
− | '''Create first app'''
| |
− | | |
− | The tutorial tells you to create your first project by running the following command (see above for more on how to run commands):
| |
− | | |
− | <pre>
| |
− | % YiiRoot/framework/yiic webapp WebRoot/myapp
| |
− | </pre>
| |
− | | |
− | The above worked for me, but one student tells me he is getting a "permission denied" error, which might mean you are not allowed to run bash commands. Not to worry, the script above also comes as a PHP script, so you can run this instead:
| |
− | | |
− | <pre>
| |
− | php YiiRoot/framework/yiic.php webapp WebRoot/myapp
| |
− | </pre>
| |
− | | |
− | Obviously in both cases you need to specify the paths as per your folders.
| |
− | | |
− | When browsing to your newly created application you might get the odd error message telling you to make certain folders writable (e.g. myapp/protected/runtime)
| |
− | | |
− | '''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 files 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.4.5
| |
− | | |
− | *[http://cakephp.org/ CakePHP homepage]
| |
− | *[http://book.cakephp.org/2.0/en/getting-started.html Getting started tutorial]
| |
− | | |
− | ===mod_rewrite===
| |
− | | |
− | IMPORTANT: I can't get MOD REWRITE to work at the moment, so my clean URL doesn't work:
| |
− | *[http://mi-linux.wlv.ac.uk/~in9352/cakephp/posts/index http://mi-linux.wlv.ac.uk/~in9352/cakephp/posts/index] | |
− | | |
− | Instead I have to use the full URL, which is not great:
| |
− | *[http://mi-linux.wlv.ac.uk/~in9352/cakephp/app/webroot/index.php/posts/index http://mi-linux.wlv.ac.uk/~in9352/cakephp/app/webroot/index.php/posts/index]
| |
− | | |
− | I'll update you if I get it working :)
| |
− | | |
− | ===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.
| |
− | | |
− | ===PHP markers===
| |
− | | |
− | Don't forget the <?php markers at the beginning of your Conrtoller and Model files, they are omitted in the tutorial.
| |
− | | |
− | ==Symfony==
| |
− | | |
− | I tested version 2.4.1:
| |
− | *[http://symfony.com/ Framework's homepage]
| |
− | *[http://symfony.com/doc/current/quick_tour/the_big_picture.html Quick tour]
| |
− | | |
− | Note: download the zip version of Symfony Standard.
| |
− | | |
− | TO BE CONTINUED...
| |
− | | |
− | ==Zend Framework==
| |
− | | |
− | '''IMPORTANT''': So far I have not managed to successfully install Zend on mi-linux :(
| |