USAGE is now in markdown
git-svn-id: https://svn.fournier38.fr/svn/ProgSVN/trunk@1291 bf3deb0d-5f1a-0410-827f-c0cc1f45334c
This commit is contained in:
114
docs/USAGE
114
docs/USAGE
@@ -18,26 +18,26 @@ a global system directory.
|
||||
You can start a new project. The following text will be project in
|
||||
/var/www/project.
|
||||
You must add a .htaccess file with :
|
||||
Options -Indexes
|
||||
<IfModule mod_rewrite.c>
|
||||
RewriteEngine on
|
||||
# if your app is in a subfolder
|
||||
# RewriteBase /my_app/
|
||||
# test string is a valid files
|
||||
RewriteCond %{SCRIPT_FILENAME} !-f
|
||||
# test string is a valid directory
|
||||
RewriteCond %{SCRIPT_FILENAME} !-d
|
||||
RewriteRule ^(.*)$ index.php?uri=/$1 [NC,L,QSA]
|
||||
# with QSA flag (query string append),
|
||||
# forces the rewrite engine to append a query string part of the
|
||||
# substitution string to the existing string, instead of replacing it.
|
||||
</IfModule>
|
||||
Options -Indexes
|
||||
<IfModule mod_rewrite.c>
|
||||
RewriteEngine on
|
||||
# if your app is in a subfolder
|
||||
# RewriteBase /my_app/
|
||||
# test string is a valid files
|
||||
RewriteCond %{SCRIPT_FILENAME} !-f
|
||||
# test string is a valid directory
|
||||
RewriteCond %{SCRIPT_FILENAME} !-d
|
||||
RewriteRule ^(.*)$ index.php?uri=/$1 [NC,L,QSA]
|
||||
# with QSA flag (query string append),
|
||||
# forces the rewrite engine to append a query string part of the
|
||||
# substitution string to the existing string, instead of replacing it.
|
||||
</IfModule>
|
||||
|
||||
# Allow to see a /.html file without having a Forbidden due to Apache conf
|
||||
<FilesMatch "^\.html">
|
||||
Satisfy Any
|
||||
Allow from all
|
||||
</FilesMatch>
|
||||
# Allow to see a /.html file without having a Forbidden due to Apache conf
|
||||
<FilesMatch "^\.html">
|
||||
Satisfy Any
|
||||
Allow from all
|
||||
</FilesMatch>
|
||||
|
||||
Then start a index.php in the same directory. That's it, the project is started.
|
||||
|
||||
@@ -64,16 +64,16 @@ The controllers shouldn't write directly to stdout. They should return the
|
||||
result of their work to the caller.
|
||||
|
||||
Example :
|
||||
<?php
|
||||
class blog
|
||||
{
|
||||
public function get ($articleid = FALSE)
|
||||
<?php
|
||||
class blog
|
||||
{
|
||||
if ($articleid === "5" || $articleid === FALSE)
|
||||
return array ("5"=>"Article very important");
|
||||
throw new Exception (_("Article not found"), 404);
|
||||
public function get ($articleid = FALSE)
|
||||
{
|
||||
if ($articleid === "5" || $articleid === FALSE)
|
||||
return array ("5"=>"Article very important");
|
||||
throw new Exception (_("Article not found"), 404);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
The errors can be returned with an Exception.
|
||||
|
||||
@@ -84,12 +84,12 @@ You can do a beautiful URL with DomFramework http://localhost/project/blog/page
|
||||
you will allow the class "blog" to be launch with the parameter "page".
|
||||
|
||||
This is the routing. You need to add the routes in your index.php file with :
|
||||
require_once ("domframework/route.php");
|
||||
$route = new route ();
|
||||
$route->get ("home", function () { echo "YESY"; });
|
||||
$route->post ("home", function () { echo "YESY"; });
|
||||
$route->put ("home", function () { echo "YESY"; });
|
||||
$route->delete ("home", function () { echo "YESY"; });
|
||||
require_once ("domframework/route.php");
|
||||
$route = new route ();
|
||||
$route->get ("home", function () { echo "YESY"; });
|
||||
$route->post ("home", function () { echo "YESY"; });
|
||||
$route->put ("home", function () { echo "YESY"; });
|
||||
$route->delete ("home", function () { echo "YESY"; });
|
||||
|
||||
The definition match on the HTTP method (GET,POST,PUT or DELETE). It can be
|
||||
surcharged by using the _METHOD variable in POST method, with the wanted method
|
||||
@@ -97,11 +97,11 @@ to use.
|
||||
The routes are read sequentially. The first which match the class/method wins.
|
||||
You should carrefully order the rules.
|
||||
Add the debug on routing with
|
||||
$route->debug=TRUE;
|
||||
$route->debug=TRUE;
|
||||
to help to see the matches.
|
||||
|
||||
We can use some variables to be passed to the called function :
|
||||
$route->get ("home3/{plo}/{str}", function ($str, $plo) {echo "$str $plo";});
|
||||
$route->get ("home3/{plo}/{str}", function ($str, $plo) {echo "$str $plo";});
|
||||
|
||||
There is a special action named "redirect" in the "route" class. It provide the
|
||||
capability to re-route the Web browser to another page. Put in action :
|
||||
@@ -117,18 +117,18 @@ routing to be displayed. It can be displayed in a lot of formats : HTML, csv,
|
||||
json, xml.
|
||||
The allowed extensions are puts in the routingCollection in the position you
|
||||
want by adding them between parenthesis. Example :
|
||||
require_once ("domframework/route.php");
|
||||
$route = new route ();
|
||||
$res = $route->routingCollection (array (
|
||||
"{page}" => array ("class", "method", "{parameter}"),
|
||||
));
|
||||
print_r ($res);
|
||||
require_once ("domframework/route.php");
|
||||
$route = new route ();
|
||||
$res = $route->routingCollection (array (
|
||||
"{page}" => array ("class", "method", "{parameter}"),
|
||||
));
|
||||
print_r ($res);
|
||||
|
||||
It can be used by the renderer system (generally run by controller) :
|
||||
$renderer = new renderer ();
|
||||
$renderer->result = $res;
|
||||
$renderer->output = "html";
|
||||
$renderer->run ();
|
||||
$renderer = new renderer ();
|
||||
$renderer->result = $res;
|
||||
$renderer->output = "html";
|
||||
$renderer->run ();
|
||||
|
||||
In controllers, the renderer can be called too. There is a flash method. The
|
||||
flash messages will be displayed on next page, in case of HTML page. In CLI, it
|
||||
@@ -150,13 +150,13 @@ replacement attibute.
|
||||
When creating a routingCollection, a lot of errors can be done. There is in
|
||||
DomFramework the capability to debug the application. You can activate the debug
|
||||
by putting 1 in the associated method. Example :
|
||||
$route = new route ();
|
||||
$route->debug = 1;
|
||||
$route = new route ();
|
||||
$route->debug = 1;
|
||||
|
||||
The screen will display the actions to help the debug :
|
||||
==== DEBUG : ROUTING START ====
|
||||
blog/5 ?? blog/{page} => blog->get({page}) : FOUND : URL === REGEX : Call blog()->get(5)
|
||||
==== DEBUG : ROUTING END ====
|
||||
==== DEBUG : ROUTING START ====
|
||||
blog/5 ?? blog/{page} => blog->get({page}) : FOUND : URL === REGEX : Call blog()->get(5)
|
||||
==== DEBUG : ROUTING END ====
|
||||
|
||||
XX. CLI usage
|
||||
-------------
|
||||
@@ -174,16 +174,16 @@ XX. Modular application
|
||||
-----------------------
|
||||
THe DomFramework can be used on modular applications. Each application (or
|
||||
module) will have a complete autonomy. The structure will be :
|
||||
/Project/
|
||||
/Project/module1/
|
||||
/Project/module2/
|
||||
[/Project/domframework/ is optional]
|
||||
/ ... /
|
||||
/Project/
|
||||
/Project/module1/
|
||||
/Project/module2/
|
||||
[/Project/domframework/ is optional]
|
||||
/ ... /
|
||||
|
||||
Only one instance of DomFramework is needed. It can be put outside the project.
|
||||
In this mode, the routing must be adapted to use the modular mode :
|
||||
$route = new route ();
|
||||
$route->module = TRUE;
|
||||
$route = new route ();
|
||||
$route->module = TRUE;
|
||||
If you use the route redirect method, think to change the last parameter to
|
||||
TRUE.
|
||||
|
||||
|
||||
Reference in New Issue
Block a user