Files
archived-doc-pt-br/reference/yaf/tutorials.xml
2024-12-05 10:01:12 -03:00

170 lines
3.5 KiB
XML

<?xml version="1.0" encoding="utf-8"?>
<!-- EN-Revision: 198f577cb09d61622267f7480b7ec180c7d714da Maintainer: leonardolara Status: ready -->
<chapter xml:id="yaf.tutorials" xmlns="http://docbook.org/ns/docbook" xmlns:xlink="http://www.w3.org/1999/xlink">
&reftitle.examples;
<example>
<title>Um layout clássico de diretório de aplicação</title>
<screen>
<![CDATA[
- index.php
- .htaccess
+ conf
|- application.ini // configuração da aplicação
- application/
- Bootstrap.php
+ controllers
- Index.php // controlador padrão
+ views
|+ index
- index.phtml // modelo de visualização para a ação padrão
+ modules
- library
- models
- plugins
]]>
</screen>
</example>
<example>
<title>Entrada</title>
<para>index.php no diretório superior é a única entrada da aplicação, todas as requisições devem ser reescritas para chamá-lo. (Pode ser usado .htaccess no Apache + php_mod) </para>
<programlisting role="php">
<![CDATA[
<?php
define("APPLICATION_PATH", dirname(__FILE__));
$app = new Yaf_Application(APPLICATION_PATH . "/conf/application.ini");
$app->bootstrap() // chama métodos de bootstrap definidos no Bootstrap.php
->run();
?>
]]>
</programlisting>
</example>
<example>
<title>Regra de reescrita</title>
<screen>
<![CDATA[
#para Apache (.htaccess)
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule .* index.php
#para 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;
}
}
#para lighttpd
$HTTP["host"] =~ "(www.)?domain.com$" {
url.rewrite = (
"^/(.+)/?$" => "/index.php/$1",
)
}
]]>
</screen>
</example>
<example>
<title>Configuração de aplicação</title>
<programlisting role="ini">
<![CDATA[
[yaf]
;APPLICATION_PATH é a constante definida no index.php
application.directory=APPLICATION_PATH "/application/"
;seção "product" herda da seção "yaf"
[product:yaf]
foo=bar
]]>
</programlisting>
</example>
<example>
<title>Controlador padrão</title>
<programlisting role="php">
<![CDATA[
<?php
class IndexController extends Yaf_Controller_Abstract {
/* ação padrão */
public function indexAction() {
$this->_view->word = "Olá mundo";
// ou
// $this->getView()->word = "Olá mundo";
}
}
?>
]]>
</programlisting>
</example>
<example>
<title>Modelo de visualização padrão</title>
<programlisting role="php">
<![CDATA[
<html>
<head>
<title>Olá mundo</title>
</head>
<body>
<?php echo $word;?>
</body>
</html>
]]>
</programlisting>
</example>
<example>
<title>Executando a aplicação</title>
&example.outputs.similar;
<screen>
<![CDATA[
<html>
<head>
<title>Olá mundo</title>
</head>
<body>
Olá mundo
</body>
</html>
]]>
</screen>
<note>
<para>
O exemplo abaixo também pode ser gerado usando o gerador de códigos Yaf, que
pode ser encontrado em yaf@github.
</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
-->