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
|
You can start a new project. The following text will be project in
|
||||||
/var/www/project.
|
/var/www/project.
|
||||||
You must add a .htaccess file with :
|
You must add a .htaccess file with :
|
||||||
Options -Indexes
|
Options -Indexes
|
||||||
<IfModule mod_rewrite.c>
|
<IfModule mod_rewrite.c>
|
||||||
RewriteEngine on
|
RewriteEngine on
|
||||||
# if your app is in a subfolder
|
# if your app is in a subfolder
|
||||||
# RewriteBase /my_app/
|
# RewriteBase /my_app/
|
||||||
# test string is a valid files
|
# test string is a valid files
|
||||||
RewriteCond %{SCRIPT_FILENAME} !-f
|
RewriteCond %{SCRIPT_FILENAME} !-f
|
||||||
# test string is a valid directory
|
# test string is a valid directory
|
||||||
RewriteCond %{SCRIPT_FILENAME} !-d
|
RewriteCond %{SCRIPT_FILENAME} !-d
|
||||||
RewriteRule ^(.*)$ index.php?uri=/$1 [NC,L,QSA]
|
RewriteRule ^(.*)$ index.php?uri=/$1 [NC,L,QSA]
|
||||||
# with QSA flag (query string append),
|
# with QSA flag (query string append),
|
||||||
# forces the rewrite engine to append a query string part of the
|
# forces the rewrite engine to append a query string part of the
|
||||||
# substitution string to the existing string, instead of replacing it.
|
# substitution string to the existing string, instead of replacing it.
|
||||||
</IfModule>
|
</IfModule>
|
||||||
|
|
||||||
# Allow to see a /.html file without having a Forbidden due to Apache conf
|
# Allow to see a /.html file without having a Forbidden due to Apache conf
|
||||||
<FilesMatch "^\.html">
|
<FilesMatch "^\.html">
|
||||||
Satisfy Any
|
Satisfy Any
|
||||||
Allow from all
|
Allow from all
|
||||||
</FilesMatch>
|
</FilesMatch>
|
||||||
|
|
||||||
Then start a index.php in the same directory. That's it, the project is started.
|
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.
|
result of their work to the caller.
|
||||||
|
|
||||||
Example :
|
Example :
|
||||||
<?php
|
<?php
|
||||||
class blog
|
class blog
|
||||||
{
|
|
||||||
public function get ($articleid = FALSE)
|
|
||||||
{
|
{
|
||||||
if ($articleid === "5" || $articleid === FALSE)
|
public function get ($articleid = FALSE)
|
||||||
return array ("5"=>"Article very important");
|
{
|
||||||
throw new Exception (_("Article not found"), 404);
|
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.
|
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".
|
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 :
|
This is the routing. You need to add the routes in your index.php file with :
|
||||||
require_once ("domframework/route.php");
|
require_once ("domframework/route.php");
|
||||||
$route = new route ();
|
$route = new route ();
|
||||||
$route->get ("home", function () { echo "YESY"; });
|
$route->get ("home", function () { echo "YESY"; });
|
||||||
$route->post ("home", function () { echo "YESY"; });
|
$route->post ("home", function () { echo "YESY"; });
|
||||||
$route->put ("home", function () { echo "YESY"; });
|
$route->put ("home", function () { echo "YESY"; });
|
||||||
$route->delete ("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
|
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
|
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.
|
The routes are read sequentially. The first which match the class/method wins.
|
||||||
You should carrefully order the rules.
|
You should carrefully order the rules.
|
||||||
Add the debug on routing with
|
Add the debug on routing with
|
||||||
$route->debug=TRUE;
|
$route->debug=TRUE;
|
||||||
to help to see the matches.
|
to help to see the matches.
|
||||||
|
|
||||||
We can use some variables to be passed to the called function :
|
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
|
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 :
|
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.
|
json, xml.
|
||||||
The allowed extensions are puts in the routingCollection in the position you
|
The allowed extensions are puts in the routingCollection in the position you
|
||||||
want by adding them between parenthesis. Example :
|
want by adding them between parenthesis. Example :
|
||||||
require_once ("domframework/route.php");
|
require_once ("domframework/route.php");
|
||||||
$route = new route ();
|
$route = new route ();
|
||||||
$res = $route->routingCollection (array (
|
$res = $route->routingCollection (array (
|
||||||
"{page}" => array ("class", "method", "{parameter}"),
|
"{page}" => array ("class", "method", "{parameter}"),
|
||||||
));
|
));
|
||||||
print_r ($res);
|
print_r ($res);
|
||||||
|
|
||||||
It can be used by the renderer system (generally run by controller) :
|
It can be used by the renderer system (generally run by controller) :
|
||||||
$renderer = new renderer ();
|
$renderer = new renderer ();
|
||||||
$renderer->result = $res;
|
$renderer->result = $res;
|
||||||
$renderer->output = "html";
|
$renderer->output = "html";
|
||||||
$renderer->run ();
|
$renderer->run ();
|
||||||
|
|
||||||
In controllers, the renderer can be called too. There is a flash method. The
|
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
|
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
|
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
|
DomFramework the capability to debug the application. You can activate the debug
|
||||||
by putting 1 in the associated method. Example :
|
by putting 1 in the associated method. Example :
|
||||||
$route = new route ();
|
$route = new route ();
|
||||||
$route->debug = 1;
|
$route->debug = 1;
|
||||||
|
|
||||||
The screen will display the actions to help the debug :
|
The screen will display the actions to help the debug :
|
||||||
==== DEBUG : ROUTING START ====
|
==== DEBUG : ROUTING START ====
|
||||||
blog/5 ?? blog/{page} => blog->get({page}) : FOUND : URL === REGEX : Call blog()->get(5)
|
blog/5 ?? blog/{page} => blog->get({page}) : FOUND : URL === REGEX : Call blog()->get(5)
|
||||||
==== DEBUG : ROUTING END ====
|
==== DEBUG : ROUTING END ====
|
||||||
|
|
||||||
XX. CLI usage
|
XX. CLI usage
|
||||||
-------------
|
-------------
|
||||||
@@ -174,16 +174,16 @@ XX. Modular application
|
|||||||
-----------------------
|
-----------------------
|
||||||
THe DomFramework can be used on modular applications. Each application (or
|
THe DomFramework can be used on modular applications. Each application (or
|
||||||
module) will have a complete autonomy. The structure will be :
|
module) will have a complete autonomy. The structure will be :
|
||||||
/Project/
|
/Project/
|
||||||
/Project/module1/
|
/Project/module1/
|
||||||
/Project/module2/
|
/Project/module2/
|
||||||
[/Project/domframework/ is optional]
|
[/Project/domframework/ is optional]
|
||||||
/ ... /
|
/ ... /
|
||||||
|
|
||||||
Only one instance of DomFramework is needed. It can be put outside the project.
|
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 :
|
In this mode, the routing must be adapted to use the modular mode :
|
||||||
$route = new route ();
|
$route = new route ();
|
||||||
$route->module = TRUE;
|
$route->module = TRUE;
|
||||||
If you use the route redirect method, think to change the last parameter to
|
If you use the route redirect method, think to change the last parameter to
|
||||||
TRUE.
|
TRUE.
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user