Difference between revisions of "Workshop - week 01"

From mi-linux
Jump to navigationJump to search
Line 1: Line 1:
 
[[Main Page]] >> [[Web Frameworks]] >> [[Web Frameworks - Workbook]] >> Workshop - week 01
 
[[Main Page]] >> [[Web Frameworks]] >> [[Web Frameworks - Workbook]] >> Workshop - week 01
  
===PHP Info===
+
===1. PHP Info===
  
 
One thing that is not mentioned in the Quick Start, which is often a good idea to do when you begin working on a new PHP server for the first time is uploading a [http://uk2.php.net/phpinfo PHP Info] test file.
 
One thing that is not mentioned in the Quick Start, which is often a good idea to do when you begin working on a new PHP server for the first time is uploading a [http://uk2.php.net/phpinfo PHP Info] test file.
  
 
+
<pre>
 
<?php
 
<?php
 
 
// Shows all information, defaults to INFO_ALL
 
// Shows all information, defaults to INFO_ALL
 
 
phpinfo();
 
phpinfo();
 
 
?>
 
?>
 
+
</pre>
 
Browse to the page using your web broswer, and hopefully you should get a page outlining the various configurations on the server. If all appears well with the PHP info file, we can move on.
 
Browse to the page using your web broswer, and hopefully you should get a page outlining the various configurations on the server. If all appears well with the PHP info file, we can move on.
  
Line 24: Line 21:
 
Using either an FTP client ([http://filezilla-project.org/download.php FileZilla], WS-FTP, etc), or using a Shell prompt through [http://www.chiark.greenend.org.uk/~sgtatham/putty/download.html putty], set up the folder structure [http://framework.zend.com/docs/quickstart/set-up-the-project-structure outlined here.]
 
Using either an FTP client ([http://filezilla-project.org/download.php FileZilla], WS-FTP, etc), or using a Shell prompt through [http://www.chiark.greenend.org.uk/~sgtatham/putty/download.html putty], set up the folder structure [http://framework.zend.com/docs/quickstart/set-up-the-project-structure outlined here.]
  
===Setting Up .htaccess===
+
===2. Setting Up .htaccess===
  
Following the instructions outlined [http://framework.zend.com/docs/quickstart/create-a-rewrite-rule here], set up the .htaccess file, and copy it to the QuickStart/public/ folder.  
+
Following the instructions outlined [http://framework.zend.com/docs/quickstart/create-a-rewrite-rule here], set up the .htaccess file, and copy it to the QuickStart/public/ folder. There is a mistake on the page - you need to change this line from the tutorial.
  
Hint: When all the files are in place, page requests that would normally result in a 404 error should be redirected to the "Hello, Zend Framework!" page. For example, http://mi-linux.wlv.ac.uk/~0454543/QuickStart/public/notAPage should redirect correctly. If this is not working properly for you, you may need to change the final line of the rewrite  rule.
+
<pre>
 
 
As an example:
 
<div>
 
 
# public/.htaccess
 
# public/.htaccess
  
Line 39: Line 33:
 
RewriteCond %{REQUEST_FILENAME} -d
 
RewriteCond %{REQUEST_FILENAME} -d
 
RewriteRule ^.*$ - [NC,L]
 
RewriteRule ^.*$ - [NC,L]
'''RewriteRule ^.*$ /index.php [NC,L]'''
+
RewriteRule ^.*$ /index.php [NC,L]
</div>
+
</pre>
 
Would become:
 
Would become:
<div>
+
<pre>
 
RewriteEngine On
 
RewriteEngine On
 
RewriteCond %{REQUEST_FILENAME} -s [OR]
 
RewriteCond %{REQUEST_FILENAME} -s [OR]
Line 48: Line 42:
 
RewriteCond %{REQUEST_FILENAME} -d
 
RewriteCond %{REQUEST_FILENAME} -d
 
RewriteRule ^.*$ - [NC,L]
 
RewriteRule ^.*$ - [NC,L]
'''RewriteRule ^.*$ /~in9301/Zend/public/index.php [NC,L]'''
+
RewriteRule ^.*$ /~<YourStudentNumber>/QucikStart/public/index.php [NC,L]
</div>
+
</pre>
 +
 
 +
===3. Bootstrap File===
 +
 
 +
Set up QuickStart/public/index.php as outlined [http://framework.zend.com/docs/quickstart/create-a-bootstrap-file here]. Then set up application/bootstrap.php.
 +
 
 +
Here there's a second mistake that we need to fix:
 +
 
 +
<pre>
 +
$frontController->setControllerDirectory(APPLICATION_PATH . '/controllers');
 +
</pre>
 +
Would become:
 +
<pre>
 +
$frontController->setControllerDirectory(APPLICATION_PATH . '/controllers');
 +
$frontController->setBaseUrl('/~<YourStudentNumber>/QuickStart/public');
 +
$frontController->setParam('useDefaultControllerAlways', true);
 +
</pre>
 +
 
 +
What we are changing here is we're saying "This is not using the root folder of the server; instead, we are using a sub-directory. As our accounts on mi-linux are set up as sub-directories, this is important. The final line of code is telling the front controller to use the default controller (Our IndexController) if a Controller we haven't got is requested. This means that if a user goes to a page we haven't set up, they will see the index view instead.
 +
 
 +
===Setting Up Our Default Controller and View===
 +
 
 +
Next we need to set up our [http://framework.zend.com/docs/quickstart/create-an-action-controller-and-view default controller and view]. As we are using the Zend Framework defaults, the controller class only requires skeleton code.
 +
 
 +
===Error Controller and View===
 +
 
 +
Because of the change we made by making all requests return the default view, essentially we remove the need for the ErrorHandler that is handling EXCEPTION_NO_CONTROLLER. However, it is good practice to set up the respective error handlers, and so we will continue to follow the tutorial.
 +
 
 +
===Creating the Layout===

Revision as of 04:35, 25 January 2009

Main Page >> Web Frameworks >> Web Frameworks - Workbook >> Workshop - week 01

1. PHP Info

One thing that is not mentioned in the Quick Start, which is often a good idea to do when you begin working on a new PHP server for the first time is uploading a PHP Info test file.

<?php
// Shows all information, defaults to INFO_ALL
phpinfo();
?>

Browse to the page using your web broswer, and hopefully you should get a page outlining the various configurations on the server. If all appears well with the PHP info file, we can move on.

Quick Start Zend Framework

We are going to be following the Zend Framework Quickstart tutorial to ensure we can get Zend to work properly from our University area.

Following how to set up a project structure, we need to create a directory structure in our personal space.

Using either an FTP client (FileZilla, WS-FTP, etc), or using a Shell prompt through putty, set up the folder structure outlined here.

2. Setting Up .htaccess

Following the instructions outlined here, set up the .htaccess file, and copy it to the QuickStart/public/ folder. There is a mistake on the page - you need to change this line from the tutorial.

# public/.htaccess

RewriteEngine On
RewriteCond %{REQUEST_FILENAME} -s [OR]
RewriteCond %{REQUEST_FILENAME} -l [OR]
RewriteCond %{REQUEST_FILENAME} -d
RewriteRule ^.*$ - [NC,L]
RewriteRule ^.*$ /index.php [NC,L]

Would become:

RewriteEngine On
RewriteCond %{REQUEST_FILENAME} -s [OR]
RewriteCond %{REQUEST_FILENAME} -l [OR]
RewriteCond %{REQUEST_FILENAME} -d
RewriteRule ^.*$ - [NC,L]
RewriteRule ^.*$ /~<YourStudentNumber>/QucikStart/public/index.php [NC,L]

3. Bootstrap File

Set up QuickStart/public/index.php as outlined here. Then set up application/bootstrap.php.

Here there's a second mistake that we need to fix:

$frontController->setControllerDirectory(APPLICATION_PATH . '/controllers');

Would become:

$frontController->setControllerDirectory(APPLICATION_PATH . '/controllers');
$frontController->setBaseUrl('/~<YourStudentNumber>/QuickStart/public');
$frontController->setParam('useDefaultControllerAlways', true);

What we are changing here is we're saying "This is not using the root folder of the server; instead, we are using a sub-directory. As our accounts on mi-linux are set up as sub-directories, this is important. The final line of code is telling the front controller to use the default controller (Our IndexController) if a Controller we haven't got is requested. This means that if a user goes to a page we haven't set up, they will see the index view instead.

Setting Up Our Default Controller and View

Next we need to set up our default controller and view. As we are using the Zend Framework defaults, the controller class only requires skeleton code.

Error Controller and View

Because of the change we made by making all requests return the default view, essentially we remove the need for the ErrorHandler that is handling EXCEPTION_NO_CONTROLLER. However, it is good practice to set up the respective error handlers, and so we will continue to follow the tutorial.

Creating the Layout