mirror of
https://github.com/sigmasternchen/php-doc-en
synced 2025-03-15 16:38:54 +00:00
update docs
git-svn-id: https://svn.php.net/repository/phpdoc/en/trunk@319898 c90b9560-bf6c-de11-be94-00142212c4b1
This commit is contained in:
parent
a8090711fb
commit
a6eeefbc0a
12 changed files with 224 additions and 15 deletions
|
@ -12,7 +12,17 @@
|
|||
<section xml:id="yaf-route-simple.intro">
|
||||
&reftitle.intro;
|
||||
<para>
|
||||
|
||||
<classname>Yaf_Route_Simple</classname> will match the query string, and
|
||||
find the route info.
|
||||
</para>
|
||||
<para>
|
||||
all you need to do is tell <classname>Yaf_Route_Simple</classname> what key in the $_GET is
|
||||
module, what key is controller, and what key is action.
|
||||
</para>
|
||||
<para>
|
||||
<methodname>Yaf_Route_Simple::route</methodname> will always return TRUE,
|
||||
so it is important put <classname>Yaf_Route_Simple</classname> in the front of the Route stack,
|
||||
otherwise all the other routes will not be called.
|
||||
</para>
|
||||
</section>
|
||||
<!-- }}} -->
|
||||
|
|
|
@ -12,7 +12,12 @@
|
|||
<section xml:id="yaf-route-static.intro">
|
||||
&reftitle.intro;
|
||||
<para>
|
||||
|
||||
Defaultly, <classname>Yaf_Router</classname> only have a
|
||||
<classname>Yaf_Route_Static</classname> as its default route.
|
||||
</para>
|
||||
<para>
|
||||
And <classname>Yaf_Route_Static</classname> is designed to handle the
|
||||
80% requirement.
|
||||
</para>
|
||||
</section>
|
||||
<!-- }}} -->
|
||||
|
|
|
@ -4,7 +4,7 @@
|
|||
<refentry xml:id="yaf-action-abstract.execute" xmlns="http://docbook.org/ns/docbook" xmlns:xlink="http://www.w3.org/1999/xlink">
|
||||
<refnamediv>
|
||||
<refname>Yaf_Action_Abstract::execute</refname>
|
||||
<refpurpose>entry point method</refpurpose>
|
||||
<refpurpose>Execute the action</refpurpose>
|
||||
</refnamediv>
|
||||
|
||||
<refsect1 role="description">
|
||||
|
|
|
@ -83,7 +83,7 @@ $config = array(
|
|||
),
|
||||
);
|
||||
|
||||
/** Ap_Application */
|
||||
/** Yaf_Application */
|
||||
$application = new Yaf_Application($config);
|
||||
$application->bootstrap()->run();
|
||||
?>
|
||||
|
|
|
@ -47,7 +47,7 @@ $config = array(
|
|||
),
|
||||
);
|
||||
|
||||
/** Ap_Application */
|
||||
/** Yaf_Application */
|
||||
$application = new Yaf_Application($config);
|
||||
print_r($application->environ());
|
||||
?>
|
||||
|
|
|
@ -68,7 +68,7 @@ $config = array(
|
|||
),
|
||||
);
|
||||
|
||||
/** Ap_Application */
|
||||
/** Yaf_Application */
|
||||
$application = new Yaf_Application($config);
|
||||
$application->execute("main", $argc, $argv);
|
||||
?>
|
||||
|
|
|
@ -46,7 +46,7 @@ $config = array(
|
|||
),
|
||||
);
|
||||
|
||||
/** Ap_Application */
|
||||
/** Yaf_Application */
|
||||
$application = new Yaf_Application($config);
|
||||
print_r($application->getConfig());
|
||||
?>
|
||||
|
|
|
@ -46,7 +46,7 @@ $config = array(
|
|||
),
|
||||
);
|
||||
|
||||
/** Ap_Application */
|
||||
/** Yaf_Application */
|
||||
$application = new Yaf_Application($config);
|
||||
print_r($application->getDispatcher());
|
||||
?>
|
||||
|
|
|
@ -47,7 +47,7 @@ $config = array(
|
|||
),
|
||||
);
|
||||
|
||||
/** Ap_Application */
|
||||
/** Yaf_Application */
|
||||
$application = new Yaf_Application($config);
|
||||
print_r($application->getModules());
|
||||
?>
|
||||
|
|
|
@ -14,7 +14,14 @@
|
|||
<methodparam choice="opt"><type>bool</type><parameter>flag</parameter></methodparam>
|
||||
</methodsynopsis>
|
||||
<para>
|
||||
|
||||
While the application.dispatcher.throwException is On(you can also calling
|
||||
to <methodname>Yaf_Dispatcher::throwException(TRUE)</methodname> to enable it), Yaf will throw Exception whe
|
||||
error occurrs instead of trigger error.
|
||||
</para>
|
||||
<para>
|
||||
then if you enable <methodname>Yaf_Dispatcher::catchException</methodname>(also can enabled by set
|
||||
application.dispatcher.catchException), all Un-caught Exceptions will be
|
||||
caught by ErrorController::error if you have defined one.
|
||||
</para>
|
||||
|
||||
&warn.undocumented.func;
|
||||
|
@ -28,7 +35,7 @@
|
|||
<term><parameter>flag</parameter></term>
|
||||
<listitem>
|
||||
<para>
|
||||
|
||||
|
||||
</para>
|
||||
</listitem>
|
||||
</varlistentry>
|
||||
|
@ -42,6 +49,53 @@
|
|||
</para>
|
||||
</refsect1>
|
||||
|
||||
<refsect1 role="examples">
|
||||
&reftitle.examples;
|
||||
<example>
|
||||
<title><function>Yaf_Dispatcher::catchException</function>example</title>
|
||||
<programlisting role="php">
|
||||
<![CDATA[
|
||||
/* if you defined a ErrorController like following */
|
||||
<?php
|
||||
class ErrorController extends Yaf_Controller_Abstract {
|
||||
/**
|
||||
* you can also call to Yaf_Request_Abstract::getException to get the
|
||||
* un-caught exception.
|
||||
*/
|
||||
public function error($exception) {
|
||||
/* error occurs */
|
||||
switch ($exception->getCode()) {
|
||||
case YAF_ERR_NOTFOUND_MODULE:
|
||||
case YAF_ERR_NOTFOUND_CONTROLLER:
|
||||
case YAF_ERR_NOTFOUND_ACTION:
|
||||
case YAF_ERR_NOTFOUND_VIEW:
|
||||
echo 404, ":", $exception->getMessage();
|
||||
break;
|
||||
default :
|
||||
$message = $exception->getMessage();
|
||||
echo 0, ":", $exception->getMessage();
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
?>
|
||||
]]>
|
||||
</programlisting>
|
||||
&example.outputs.similar;
|
||||
<screen>
|
||||
<![CDATA[
|
||||
/* now if some error occur, assuming access a non-exists controller(or you can throw a exception yourself): */
|
||||
404:Could not find controller script **/application/controllers/No-exists-controller.php
|
||||
]]>
|
||||
</screen>
|
||||
</example>
|
||||
</refsect1>
|
||||
<refsect1 role="seealso">
|
||||
&reftitle.seealso;
|
||||
<simplelist>
|
||||
<member><methodname>Yaf_Dispatcher::throwException</methodname></member>
|
||||
</simplelist>
|
||||
</refsect1>
|
||||
|
||||
</refentry>
|
||||
|
||||
|
|
|
@ -4,7 +4,7 @@
|
|||
<refentry xml:id="yaf-router.addconfig" xmlns="http://docbook.org/ns/docbook" xmlns:xlink="http://www.w3.org/1999/xlink">
|
||||
<refnamediv>
|
||||
<refname>Yaf_Router::addConfig</refname>
|
||||
<refpurpose>The addConfig purpose</refpurpose>
|
||||
<refpurpose>Add config-defined routes into Router</refpurpose>
|
||||
</refnamediv>
|
||||
|
||||
<refsect1 role="description">
|
||||
|
@ -14,7 +14,8 @@
|
|||
<methodparam><type>Yaf_Config_Abstract</type><parameter>config</parameter></methodparam>
|
||||
</methodsynopsis>
|
||||
<para>
|
||||
|
||||
Add Routes defined in application.ini into
|
||||
<classname>Yaf_Router</classname>'s route stack
|
||||
</para>
|
||||
|
||||
&warn.undocumented.func;
|
||||
|
@ -33,6 +34,76 @@
|
|||
</para>
|
||||
</refsect1>
|
||||
|
||||
<refsect1 role="examples">
|
||||
&reftitle.examples;
|
||||
<example>
|
||||
<title><function>application.ini</function>example</title>
|
||||
<programlisting role="ini">
|
||||
<![CDATA[
|
||||
;the order is very important, the prior one will be called first
|
||||
|
||||
;a rewrite route match request /product/*/*
|
||||
routes.route_name.type="rewrite"
|
||||
routes.route_name.match="/product/:name/:value"
|
||||
routes.route_name.route.controller=product
|
||||
routes.route_name.route.action=info
|
||||
|
||||
;a regex route match request /list/*/*
|
||||
routes.route_name1.type="regex"
|
||||
routes.route_name1.match="#^list/([^/]*)/([^/]*)#"
|
||||
routes.route_name1.route.controller=Index
|
||||
routes.route_name1.route.action=action
|
||||
routes.route_name1.map.1=name
|
||||
routes.route_name1.map.2=value
|
||||
|
||||
;a simple router match /**?r=PATH_INFO
|
||||
routes.route_name3.type="supervar"
|
||||
routes.route_name3.varname=r
|
||||
|
||||
;a simple route match /**?c=controller&a=action&m=module
|
||||
routes.route_name2.type="simple"
|
||||
routes.route_name2.controller=c
|
||||
routes.route_name2.module=m
|
||||
routes.route_name2.action=a
|
||||
]]>
|
||||
</programlisting>
|
||||
</example>
|
||||
<example>
|
||||
<title><function>Yaf_Dispatcher::autoConfig</function>example</title>
|
||||
<programlisting role="php">
|
||||
<![CDATA[
|
||||
<?php
|
||||
class Bootstrap extends Yaf_Bootstrap_Abstract{
|
||||
public function _initConfig() {
|
||||
$config = Yaf_Application::app()->getConfig();
|
||||
Yaf_Registry::set("config", $config);
|
||||
}
|
||||
|
||||
public function _initRoute(Yaf_Dispatcher $dispatcher) {
|
||||
$router = $dispatcher->getRouter();
|
||||
/**
|
||||
* we can add some pre-defined routes in application.ini
|
||||
*/
|
||||
$router->addConfig(Yaf_Registry::get("config")->routes);
|
||||
}
|
||||
?>
|
||||
]]>
|
||||
</programlisting>
|
||||
</example>
|
||||
</refsect1>
|
||||
|
||||
<refsect1 role="seealso">
|
||||
&reftitle.seealso;
|
||||
<simplelist>
|
||||
<member><methodname>Yaf_Router::addRoute</methodname></member>
|
||||
<member><classname>Yaf_Route_Static</classname></member>
|
||||
<member><classname>Yaf_Route_Supervar</classname></member>
|
||||
<member><classname>Yaf_Route_Simple</classname></member>
|
||||
<member><classname>Yaf_Route_Regex</classname></member>
|
||||
<member><classname>Yaf_Route_Rewrite</classname></member>
|
||||
<member><classname>Yaf_Route_Map</classname></member>
|
||||
</simplelist>
|
||||
</refsect1>
|
||||
|
||||
</refentry>
|
||||
|
||||
|
|
|
@ -4,7 +4,7 @@
|
|||
<refentry xml:id="yaf-router.addroute" xmlns="http://docbook.org/ns/docbook" xmlns:xlink="http://www.w3.org/1999/xlink">
|
||||
<refnamediv>
|
||||
<refname>Yaf_Router::addRoute</refname>
|
||||
<refpurpose>The addRoute purpose</refpurpose>
|
||||
<refpurpose>Add new Route into Router</refpurpose>
|
||||
</refnamediv>
|
||||
|
||||
<refsect1 role="description">
|
||||
|
@ -15,7 +15,13 @@
|
|||
<methodparam><type>Yaf_Route_Abstract</type><parameter>route</parameter></methodparam>
|
||||
</methodsynopsis>
|
||||
<para>
|
||||
|
||||
defaultly, Yaf_Router using a <classname>Yaf_Route_Static</classname> as its defualt route. you
|
||||
can add new routes into Router's route stack by calling this method.
|
||||
</para>
|
||||
<para>
|
||||
the newer route will be called before the older(route stack), and if the newer router return
|
||||
TRUE, the router process will be end. otherwise, the older one will be
|
||||
called.
|
||||
</para>
|
||||
|
||||
&warn.undocumented.func;
|
||||
|
@ -34,6 +40,69 @@
|
|||
</para>
|
||||
</refsect1>
|
||||
|
||||
<refsect1 role="examples">
|
||||
&reftitle.examples;
|
||||
<example>
|
||||
<title><function>Yaf_Dispatcher::autoRender</function>example</title>
|
||||
<programlisting role="php">
|
||||
<![CDATA[
|
||||
<?php
|
||||
class Bootstrap extends Yaf_Bootstrap_Abstract{
|
||||
public function _initConfig() {
|
||||
$config = Yaf_Application::app()->getConfig();
|
||||
Yaf_Registry::set("config", $config);
|
||||
}
|
||||
|
||||
public function _initRoute(Yaf_Dispatcher $dispatcher) {
|
||||
$router = $dispatcher->getRouter();
|
||||
/**
|
||||
* we can add some pre-defined routes in application.ini
|
||||
*/
|
||||
$router->addConfig(Yaf_Registry::get("config")->routes);
|
||||
/**
|
||||
* add a Rewrite route, then for a request uri:
|
||||
* http://***/product/list/22/foo
|
||||
* will be matched by this route, and result:
|
||||
*
|
||||
* [module] =>
|
||||
* [controller] => product
|
||||
* [action] => info
|
||||
* [method] => GET
|
||||
* [params:protected] => Array
|
||||
* (
|
||||
* [id] => 22
|
||||
* [name] => foo
|
||||
* )
|
||||
*
|
||||
*/
|
||||
$route = new Yaf_Route_Rewrite(
|
||||
"/product/list/:id/:name",
|
||||
array(
|
||||
"controller" => "product",
|
||||
"action" => "info",
|
||||
)
|
||||
);
|
||||
|
||||
$router->addRoute('dummy', $route);
|
||||
}
|
||||
?>
|
||||
]]>
|
||||
</programlisting>
|
||||
</example>
|
||||
</refsect1>
|
||||
|
||||
<refsect1 role="seealso">
|
||||
&reftitle.seealso;
|
||||
<simplelist>
|
||||
<member><methodname>Yaf_Router::addConfig</methodname></member>
|
||||
<member><classname>Yaf_Route_Static</classname></member>
|
||||
<member><classname>Yaf_Route_Supervar</classname></member>
|
||||
<member><classname>Yaf_Route_Simple</classname></member>
|
||||
<member><classname>Yaf_Route_Regex</classname></member>
|
||||
<member><classname>Yaf_Route_Rewrite</classname></member>
|
||||
<member><classname>Yaf_Route_Map</classname></member>
|
||||
</simplelist>
|
||||
</refsect1>
|
||||
|
||||
</refentry>
|
||||
|
||||
|
|
Loading…
Reference in a new issue