mirror of
https://github.com/php/doc-zh.git
synced 2026-03-24 23:22:14 +01:00
171 lines
3.4 KiB
XML
171 lines
3.4 KiB
XML
<?xml version="1.0" encoding="utf-8"?>
|
||
<!-- $Revision$ -->
|
||
<!-- EN-Revision: 198f577cb09d61622267f7480b7ec180c7d714da Maintainer: Carbyn Wu Status: ready -->
|
||
<!-- CREDITS: mowangjuanzi -->
|
||
<chapter xml:id="yaf.tutorials" xmlns="http://docbook.org/ns/docbook" xmlns:xlink="http://www.w3.org/1999/xlink">
|
||
&reftitle.examples;
|
||
|
||
<example>
|
||
<title>一个典型的应用目录结构</title>
|
||
<screen>
|
||
<![CDATA[
|
||
- index.php
|
||
- .htaccess
|
||
+ conf
|
||
|- application.ini //application config
|
||
- application/
|
||
- Bootstrap.php
|
||
+ controllers
|
||
- Index.php //default controller
|
||
+ views
|
||
|+ index
|
||
- index.phtml //view template for default action
|
||
+ modules
|
||
- library
|
||
- models
|
||
- plugins
|
||
]]>
|
||
</screen>
|
||
</example>
|
||
|
||
<example>
|
||
<title>入口文件</title>
|
||
<para>顶层目录下的 index.php 是整个应用的唯一入口,应该把所有请求都重定向到这个文件(在 Apache + php_mod 模式下可以使用 .htaccess)。</para>
|
||
<programlisting role="php">
|
||
<![CDATA[
|
||
<?php
|
||
define("APPLICATION_PATH", dirname(__FILE__));
|
||
|
||
$app = new Yaf_Application(APPLICATION_PATH . "/conf/application.ini");
|
||
$app->bootstrap() //call bootstrap methods defined in Bootstrap.php
|
||
->run();
|
||
?>
|
||
]]>
|
||
</programlisting>
|
||
</example>
|
||
|
||
<example>
|
||
<title>重写规则</title>
|
||
<screen>
|
||
<![CDATA[
|
||
#for apache (.htaccess)
|
||
RewriteEngine On
|
||
RewriteCond %{REQUEST_FILENAME} !-f
|
||
RewriteRule .* index.php
|
||
|
||
#for nginx
|
||
server {
|
||
listen ****;
|
||
server_name domain.com;
|
||
root document_root;
|
||
index index.php index.html index.htm;
|
||
|
||
if (!-e $request_filename) {
|
||
rewrite ^/(.*) /index.php$1 last;
|
||
}
|
||
}
|
||
|
||
#for lighttpd
|
||
$HTTP["host"] =~ "(www.)?domain.com$" {
|
||
url.rewrite = (
|
||
"^/(.+)/?$" => "/index.php/$1",
|
||
)
|
||
}
|
||
]]>
|
||
</screen>
|
||
</example>
|
||
|
||
<example>
|
||
<title>应用配置文件</title>
|
||
<programlisting role="ini">
|
||
<![CDATA[
|
||
[yaf]
|
||
;APPLICATION_PATH is the constant defined in index.php
|
||
application.directory=APPLICATION_PATH "/application/"
|
||
|
||
;product section inherit from yaf section
|
||
[product:yaf]
|
||
foo=bar
|
||
]]>
|
||
</programlisting>
|
||
</example>
|
||
|
||
<example>
|
||
<title>默认控制器</title>
|
||
<programlisting role="php">
|
||
<![CDATA[
|
||
<?php
|
||
class IndexController extends Yaf_Controller_Abstract {
|
||
/* default action */
|
||
public function indexAction() {
|
||
$this->_view->word = "hello world";
|
||
//or
|
||
// $this->getView()->word = "hello world";
|
||
}
|
||
}
|
||
?>
|
||
]]>
|
||
</programlisting>
|
||
</example>
|
||
|
||
<example>
|
||
<title>默认视图文件</title>
|
||
<programlisting role="php">
|
||
<![CDATA[
|
||
<html>
|
||
<head>
|
||
<title>Hello World</title>
|
||
</head>
|
||
<body>
|
||
<?php echo $word;?>
|
||
</body>
|
||
</html>
|
||
]]>
|
||
</programlisting>
|
||
</example>
|
||
|
||
<example>
|
||
<title>运行应用</title>
|
||
&example.outputs.similar;
|
||
<screen>
|
||
<![CDATA[
|
||
<html>
|
||
<head>
|
||
<title>Hello World</title>
|
||
</head>
|
||
<body>
|
||
hello world
|
||
</body>
|
||
</html>
|
||
]]>
|
||
</screen>
|
||
<note>
|
||
<para>
|
||
在 yaf@github 上有 Yaf 代码生成器,你也可以用它来生成上面的例子。
|
||
</para>
|
||
</note>
|
||
</example>
|
||
|
||
</chapter>
|
||
|
||
<!-- Keep this comment at the end of the file
|
||
Local variables:
|
||
mode: sgml
|
||
sgml-omittag:t
|
||
sgml-shorttag:t
|
||
sgml-minimize-attributes:nil
|
||
sgml-always-quote-attributes:t
|
||
sgml-indent-step:1
|
||
sgml-indent-data:t
|
||
indent-tabs-mode:nil
|
||
sgml-parent-document:nil
|
||
sgml-default-dtd-file:"~/.phpdoc/manual.ced"
|
||
sgml-exposed-tags:nil
|
||
sgml-local-catalogs:nil
|
||
sgml-local-ecat-files:nil
|
||
End:
|
||
vim600: syn=xml fen fdm=syntax fdl=2 si
|
||
vim: et tw=78 syn=sgml
|
||
vi: ts=1 sw=1
|
||
-->
|