EN | CS | Login | Register

(this page is translated by Google; We're working hard on a human translation)

Recommended directory structure

Warning! This section requires documentation review! Information contained herein, therefore, please take note of caution! Are outdated and may not even be correct. Working hard to correct ...

 app /
    . Htaccess (deny from all)
    bootstrap.php
    config.ini
    models /
    presenters /
        DefaultPresenter.php
        AdminModule /
            DefaultPresenter.php (Admin: Default Presenter)
    temp / (Must Be writtable)
    templates /
        @ Layout.phtml
        Default / (Default presenter)
            default.phtml (Default: default view)
        AdminModule /
            Default / (Admin: Default Presenter)
                @ Layout.phtml (Admin: Default layout presenter)
                default.phtml (Admin: Default: default view)

DOCUMENT_ROOT /
    . Htaccess (see below)
    index.php

libs /
    . Htaccess (deny from all)
    dibi /
    Net /
    Texy / 

If the web application working team, but one soloist, may be preferable to store templates and presenter together. I do not think a single directory, for example, but in a subdirectory templates in the folder where is located the presenter. The difference between this and the default storage is most evident in the use of modules:

Store separately

 presenters /
    FrontModule /
        HomepagePresenter.php
    AdminModule /
        AuthPresenter.php

templates /
    FrontModule /
        @ Layout.phtml
        Homepage.default.phtml
    AdminModule /
        @ Layout.phtml
        ... 

Store together

 presenters /
    FrontModule /
        HomepagePresenter.php
        templates /
            @ Layout.phtml
            Homepage.default.phtml
    AdminModule /
        AuthPresenter.php
        templates /
            ... 

The entire module is then together in one subdirectory, including classes and templates.

If you prefer this method, set the environment variable templatesDir the same value as presentersDir :

 Environment::setVariable( 'templatesDir' , '%appDir%/presenters' ); 

// nebo v souboru config.ini:
// variable.templatesDir = "%appDir%/presenters"

Nette already inserted itself into the path of a directory /templates/ .

. Htaccess

 # configure PHP php_flag magic_quotes_gpc off php_flag register_globals off # mod_rewrite RewriteEngine On #RewriteBase / # front controller RewriteCond %{REQUEST_FILENAME} !-f RewriteCond %{REQUEST_FILENAME} !-d RewriteRule !\.(pdf|js|ico|gif|jpg|png|css|rar|zip|tar\.gz)$ index.php [L] 

index.php

 <?php 

// absolute filesystem path to the web root
define ( 'WWW_DIR' , dirname (__FILE__));

// absolute filesystem path to the application root
define ( 'APP_DIR' , WWW_DIR . '/../app' );

// load bootstrap file
require APP_DIR . '/bootstrap.php' ;

Nette is maintained in a single order for the path to the directories. Directories, whether in the constant, variable, environment variables, etc. do not include right-sided stroke. There is no need to call rtrim($dir, '/') . '/file.php' or fear that they would replicate slash - just follow the convention.

 define ( 'ANY_DIR' , dirname (__FILE__)); 

require ANY_DIR . '/file.php' ;

An exception is the Cache FileStorage , but this is not a directory, but the path prefix.

Exceptions are also ways baseUri & basePath , which always ends with a slash (so you can write templates <link rel="stylesheet" type="text/css" media="screen" href="{$baseUri}css/style.css"> )

bootstrap.php

 <?php 

/**
* Load Nette
*/

require_once dirname (__FILE__) . '/../libs/Nette/loader.php' ;

/**
* Configure application
*/

Environment::loadConfig();

/**
* Prepare & setup
*/

Debug::enable();

$application = Environment::getApplication();
$router = $application ->getRouter();

$router [] = new Route( 'index.php' , array (
'presenter' => 'Default' ,
'view' => 'default' ,
), Route::ONE_WAY);

$router [] = new Route( '<presenter>/<view>/<id>' , array (
'presenter' => 'Default' ,
'view' => 'default' ,
'id' => NULL ,
));

/**
* Run!
*/

$application = Environment::getApplication();
$application ->run();

config.ini

 [common] set.date-timezone = "Europe/Prague" set.iconv-internal_encoding = "%encoding%" set.mbstring-internal_encoding = "%encoding%" ; Production site configuration data [production < common] set.include_path = "%appDir%/libs;%modelsDir%/;%presentersDir%/" ; Staging site configuration data inherits from production and ; overrides values as necessary [development < production] 

DefaultPresenter.php

 class DefaultPresenter extends Presenter 
{
public function renderDefault()
{
$this ->template->title = "Hello" ;
}


public function renderHello( $param )
{
// $param should be 123 after click
}
}

@ Layout.phtml

 <html> 
<head>
<meta http-equiv= "Content-Type" content= "text/html;charset=utf-8" / >
<title> <?php echo htmlSpecialChars ( $title ) ?> </title>
</head>

<body>
<h1> <?php echo htmlSpecialChars ( $title ) ?> </h1>

<div id= "content" >
<?php $content ->render() ?>
</div>
</body>
</html>

default.phtml

 <p><a  href= " <?php echo $presenter -> link ( 'hello' , 123 ) ?> " > Hello World! </a></p> 

Login to submit a comment