2011-09-01 02:22:00 +00:00
<?xml version="1.0" encoding="utf-8"?>
<!-- $Revision$ -->
2012-09-08 04:11:03 +00:00
<chapter xml:id= "yaf.tutorials" xmlns= "http://docbook.org/ns/docbook" xmlns:xlink= "http://www.w3.org/1999/xlink" >
2011-09-01 02:22:00 +00:00
&reftitle.examples;
2012-09-08 03:53:39 +00:00
<section role= "examples" >
<example >
<title > A classic Application directory layout</title>
<screen >
2011-09-01 11:12:59 +00:00
< ![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
]]>
2012-09-08 03:53:39 +00:00
</screen>
</example>
</section>
<section role= "examples" >
2011-09-01 11:12:59 +00:00
<example >
<title > Entry</title>
<para > index.php in the top directory is the only way in of the application, you should rewrite all request to it(you can use .htaccess in Apache+php_mod) </para>
<programlisting role= "php" >
2011-09-01 02:22:00 +00:00
< ![CDATA[
< ?php
2011-09-01 11:12:59 +00:00
define("APPLICATION_PATH", dirname(__FILE__));
2011-09-01 02:22:00 +00:00
2011-09-01 11:12:59 +00:00
$app = new Yaf_Application(APPLICATION_PATH . "/conf/application.ini");
$app->bootstrap() //call bootstrap methods defined in Bootstrap.php
->run();
2012-01-10 02:37:08 +00:00
?>
2011-09-01 02:22:00 +00:00
]]>
2011-09-01 11:12:59 +00:00
</programlisting>
</example>
2012-09-08 03:53:39 +00:00
</section>
2011-09-01 11:12:59 +00:00
2012-09-08 03:53:39 +00:00
<section role= "examples" >
2011-09-01 11:12:59 +00:00
<example >
<title > Rewrite rule</title>
2011-09-01 02:22:00 +00:00
<screen >
< ![CDATA[
2011-09-01 11:12:59 +00:00
#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",
)
}
2011-09-01 02:22:00 +00:00
]]>
</screen>
</example>
2012-09-08 03:53:39 +00:00
</section>
2011-09-01 11:12:59 +00:00
2012-09-08 03:53:39 +00:00
<section role= "examples" >
2011-09-01 11:12:59 +00:00
<example >
<title > Application config</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>
2012-09-08 03:53:39 +00:00
</section>
2011-09-01 11:12:59 +00:00
2012-09-08 03:53:39 +00:00
<section role= "examples" >
2011-09-01 11:12:59 +00:00
<example >
<title > Default controller</title>
<programlisting role= "php" >
< ![CDATA[
< ?php
class IndexController extends Yaf_Controller_Abstract {
/* default action */
public function indexAction() {
$this->view->word = "hello world";
}
}
?>
]]>
</programlisting>
</example>
2012-09-08 03:53:39 +00:00
</section>
2011-09-01 11:12:59 +00:00
2012-09-08 03:53:39 +00:00
<section role= "examples" >
2011-09-01 11:12:59 +00:00
<example >
<title > Default view template</title>
<programlisting role= "php" >
< ![CDATA[
<html >
<head >
<title > Hello World</title>
</head>
<body >
<?php echo $word;?>
</body>
2012-08-07 14:45:39 +00:00
</html>
2011-09-01 11:12:59 +00:00
]]>
</programlisting>
</example>
2012-09-08 03:53:39 +00:00
</section>
2011-09-01 11:12:59 +00:00
2012-09-08 03:53:39 +00:00
<section role= "examples" >
2011-09-01 11:12:59 +00:00
<example >
<title > Run the Applicatioin</title>
&example.outputs.similar;
<screen >
< ![CDATA[
<html >
<head >
<title > Hello World</title>
</head>
<body >
hello world
</body>
2012-08-07 14:45:39 +00:00
</html>
2011-09-01 11:12:59 +00:00
]]>
</screen>
2012-09-07 16:40:32 +00:00
<note >
<para >
you can also generate above example by use Yaf codes generator, which
could be found here yaf@github.
</para>
</note>
2011-09-01 11:12:59 +00:00
</example>
2012-09-08 03:53:39 +00:00
</section>
2012-09-07 16:40:32 +00:00
2011-09-01 02:22:00 +00:00
</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
-->