### Access Welcome Page Source: https://doc.nette.org/en/quickstart After project creation, access the default welcome page via your web server. This confirms the installation and basic setup are working correctly. ```http http://localhost/nette-blog/www/ ``` -------------------------------- ### Basic RobotLoader Installation Source: https://doc.nette.org/en/robot-loader Include RobotLoader as a standalone file and initialize it. This is the simplest way to get started with automatic class loading. ```php require '/path/to/RobotLoader.php'; $loader = new Nette\Loaders\RobotLoader; // ... ``` -------------------------------- ### Service Setup with Property Assignment and Array Push Source: https://doc.nette.org/en/dependency-injection/services Demonstrates setting properties and adding elements to arrays during service setup. ```neon services: foo: create: Foo setup: - $value = 123 - '$onClick[]' = [@bar, clickHandler] ``` -------------------------------- ### Service Creation with Setup Method Calls Source: https://doc.nette.org/en/dependency-injection/services Defines a service with a 'create' method and subsequent 'setup' method calls for configuration. ```neon services: database: create: PDO(%dsn%, %user%, %password%) setup: - setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION) ``` -------------------------------- ### PHP Configuration File Example Source: https://doc.nette.org/en/dependency-injection/configuration Example of a PHP file that returns a configuration array. This can be included in the main NEON configuration. ```php [ 'main' => [ 'dsn' => 'sqlite::memory:' ] ] ]; ``` -------------------------------- ### PHP Equivalent of Service Setup with Method Calls Source: https://doc.nette.org/en/dependency-injection/services Illustrates the PHP code generated for the NEON service definition with setup method calls. ```php public function createServiceDatabase(): PDO { $service = new PDO('...', '...', '...'); $service->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION); return $service; } ``` -------------------------------- ### Install Nette Application Source: https://doc.nette.org/en/application/3.x Install the Nette Application library using Composer. This command fetches and installs the necessary package. ```bash composer require nette/application ``` -------------------------------- ### Install Nette Tokenizer Source: https://doc.nette.org/en/tokenizer Use Composer to install the Nette Tokenizer library. ```bash composer require nette/tokenizer ``` -------------------------------- ### Install Nette Schema Source: https://doc.nette.org/en/schema Install the Nette Schema library using Composer. ```bash composer require nette/schema ``` -------------------------------- ### Install Nette Caching Source: https://doc.nette.org/en/caching Install the nette/caching package using Composer. ```bash composer require nette/caching ``` -------------------------------- ### PHP Equivalent of Service Setup with Property Assignment Source: https://doc.nette.org/en/dependency-injection/services Shows the PHP code for setting properties and pushing to arrays as defined in the NEON setup. ```php public function createServiceFoo(): Foo { $service = new Foo; $service->value = 123; $service->onClick[] = $this->getService('bar')->clickHandler(...); return $service; } ``` -------------------------------- ### Install Nette Finder Source: https://doc.nette.org/en/utils/finder/3.x Install the Nette Finder component using Composer. This is the first step before using the Finder class in your project. ```bash composer require nette/finder ``` -------------------------------- ### Install and Initialize netteForms via npm Source: https://doc.nette.org/en/forms/validation/3.x Install the nette-forms package using npm and initialize it on page load. ```javascript import netteForms from 'nette-forms'; netteForms.initOnLoad(); ``` -------------------------------- ### Install Nette DI using Composer Source: https://doc.nette.org/en/dependency-injection/nette-container Installs the Nette DI library into your project using Composer. ```bash composer require nette/di ``` -------------------------------- ### Example Article Class Source: https://doc.nette.org/en/dependency-injection/factory A simple Article class demonstrating a constructor that accepts dependencies. ```php class Article { public function __construct( private Nette\Database\Connection $db, ) { } } ``` -------------------------------- ### Advanced Definition with Setup Method Calls Source: https://doc.nette.org/en/dependency-injection/factory Configure arguments for methods other than the constructor using the 'setup' section, referencing factory method parameters. ```neon services: articleFactory: implement: ArticleFactory setup: - setAuthorId($authorId) ``` -------------------------------- ### Service Setup with Static and Other Service Method Calls Source: https://doc.nette.org/en/dependency-injection/services Configures service setup by invoking static methods or methods of other services, using '@self' to reference the current service. ```neon services: foo: create: Foo setup: - My\Helpers::initializeFoo(@self) - @anotherService::setFoo(@self) ``` -------------------------------- ### NEON Configuration with Comments Source: https://doc.nette.org/en/neon/format A complete NEON configuration example including comments for better understanding. ```neon # my web application config php: date.timezone: Europe/Prague zlib.output_compression: true # use gzip database: driver: mysql username: root password: password123 users: - Dave - Kryten - Rimmer ``` -------------------------------- ### Install nette/bootstrap Package Source: https://doc.nette.org/en/bootstrap Install the Nette bootstrap package using Composer. This is the first step to enable configuration file loading. ```bash composer require nette/bootstrap ``` -------------------------------- ### Expression Language Usage in Service Definition and Setup Source: https://doc.nette.org/en/dependency-injection/services Shows how expression language can be used in service creation arguments and setup method arguments. ```neon parameters: ipAddress: @http.request::getRemoteAddress() services: database: create: DatabaseFactory::create( @anotherService::getDsn() ) setup: - initialize( ::getenv('DB_USER') ) ``` -------------------------------- ### Install Nette SafeStream Source: https://doc.nette.org/en/safe-stream Install the Nette SafeStream package using Composer. ```bash composer require nette/safe-stream ``` -------------------------------- ### Install Nette NEON Package Source: https://doc.nette.org/en/neon Install the Nette NEON package using Composer. ```bash composer require nette/neon ``` -------------------------------- ### Install Nette Utils Source: https://doc.nette.org/en/utils/html-elements Installs the Nette Utils package using Composer. This is a prerequisite for using the Nette\Utils\Html class. ```bash composer require nette/utils ``` -------------------------------- ### Install Nette Mail Source: https://doc.nette.org/en/mail/3.x Install the Nette Mail library using Composer. This is the first step before using any of its features. ```bash composer require nette/mail ``` -------------------------------- ### PHP Equivalent of Service Setup with Static/Other Service Calls Source: https://doc.nette.org/en/dependency-injection/services Provides the PHP code generated for invoking static methods and methods of other services during setup. ```php public function createServiceFoo(): Foo { $service = new Foo; My\Helpers::initializeFoo($service); $this->getService('anotherService')->setFoo($service); return $service; } ``` -------------------------------- ### Install vite-plugin-mkcert Source: https://doc.nette.org/en/assets/vite Install the vite-plugin-mkcert package as a development dependency to enable automatic certificate generation for HTTPS development. ```bash npm install -D vite-plugin-mkcert ``` -------------------------------- ### Composer Installation Source: https://doc.nette.org/en/assets Shows the command to install the Nette Assets library using Composer. It requires PHP 8.1 or higher. ```bash composer require nette/assets ``` -------------------------------- ### Define MultiFactory Interface Source: https://doc.nette.org/en/dependency-injection/factory An interface for a multifactory can contain multiple methods named 'create()' and 'get()'. This example defines methods to create an Article and get a PDO service. ```php interface MultiFactory { function createArticle(): Article; function getDb(): PDO; } ``` -------------------------------- ### Get Database Reflection Source: https://doc.nette.org/en/database/reflection/3.x Obtain the reflection object from the database connection instance to start introspecting the database structure. ```php $reflection = $database->getReflection(); ``` -------------------------------- ### Container Get Components Example Source: https://doc.nette.org/en/component-model Returns an array of all direct child components of the container. The array keys are the names of the components. ```php getComponents(); ``` -------------------------------- ### Configuring a Parameter in neon Source: https://doc.nette.org/en/dependency-injection/faq Example of defining and using a parameter in the neon configuration file. ```neon parameters: myParameter: Some value services: - MyClass(%myParameter%) ``` -------------------------------- ### Get Database Reflection Object Source: https://doc.nette.org/en/database/reflection Obtain the reflection object from the database connection instance to start introspecting the database structure. ```php $reflection = $database->getReflection(); ``` -------------------------------- ### Include Composer Autoloader Source: https://doc.nette.org/en/best-practices/composer Include the generated 'vendor/autoload.php' file to automatically load all installed Composer packages and start using their classes. ```php require __DIR__ . '/vendor/autoload.php'; $db = new Nette\Database\Connection('sqlite::memory:'); ``` -------------------------------- ### Dependency Injection Example Source: https://doc.nette.org/en/utils/filesystem Demonstrates using the FileSystem class non-statically via dependency injection, allowing for easier testing with mocks. ```php class AnyClassUsingFileSystem { public function __construct( private FileSystem $fileSystem, ) { } public function readConfig(): string { return $this->fileSystem->read(/* ... */); } // ... } ``` -------------------------------- ### ArticleRepository Class for Autowiring Source: https://doc.nette.org/en/dependency-injection/autowiring Example class definition with type-hinted constructor arguments for autowiring. ```php namespace Model; class ArticleRepository { public function __construct(\\PDO $db, \\Nette\\Caching\\Storage $storage) {} } ``` -------------------------------- ### Container Get Component Tree Example Source: https://doc.nette.org/en/component-model Retrieves the entire component hierarchy as a flat, indexed array. The traversal is performed in a depth-first manner. ```php getComponentTree(); ``` -------------------------------- ### Container Get Component Example Source: https://doc.nette.org/en/component-model Retrieves a direct child component by its name. If the component does not exist, it attempts to create it using a component factory method. ```php getComponent('someName'); ``` -------------------------------- ### Order Facade Example Source: https://doc.nette.org/en/application/directory-structure/3.x Facades represent the main entry point into a specific domain. They orchestrate multiple services to implement complete use-cases. ```php class OrderFacade { public function createOrder(Cart $cart): Order { // validation // order creation // email sending // writing to statistics } } ``` -------------------------------- ### Get Table Selection Source: https://doc.nette.org/en/database/explorer Starts working with the Explorer by calling the `table()` method on a Nette\Database\Explorer object. This returns a Selection object representing an SQL query. ```php $books = $explorer->table('book'); // 'book' is the table name ``` -------------------------------- ### Using a Simple DI Container Source: https://doc.nette.org/en/dependency-injection/container Demonstrates how to instantiate and use a hardcoded DI container to retrieve services. The container abstracts the creation and dependency resolution process. ```php $container = new Container; $controller = $container->createUserController(); ``` -------------------------------- ### Using Multiple Entry Points in Templates Source: https://doc.nette.org/en/assets/vite Demonstrates how to include different entry points in Nette templates for public pages and the admin panel. ```latte {* In public pages *} {asset 'app.js'} {* In admin panel *} {asset 'admin.js'} ``` -------------------------------- ### Define PDOAccessor Interface Source: https://doc.nette.org/en/dependency-injection/factory An interface for an accessor must have exactly one method named 'get' and declare the return type. This example defines an accessor for a PDO service. ```php interface PDOAccessor { function get(): PDO; } ``` -------------------------------- ### Basic RobotLoader Setup Source: https://doc.nette.org/en/robot-loader/3.x Configure and run RobotLoader by specifying directories to index and a temporary directory for caching. This enables automatic class loading. ```php $loader = new Nette\Loaders\RobotLoader; // directories to be indexed by RobotLoader (including subdirectories) $loader->addDirectory(__DIR__ . '/app'); $loader->addDirectory(__DIR__ . '/libs'); // use 'temp' directory for cache $loader->setTempDirectory(__DIR__ . '/temp'); $loader->register(); // Run the RobotLoader ``` -------------------------------- ### Require Specific Package Version Source: https://doc.nette.org/en/best-practices/composer Use 'composer require' to update package constraints in composer.json and install the latest compatible version. For example, to allow version 4.1. ```bash composer require nette/database ``` -------------------------------- ### Create Custom RESTful Methods Attribute Source: https://doc.nette.org/en/best-practices/attribute-requires Create a custom attribute to allow access via all standard HTTP methods used in REST APIs. This example defines #[RestMethods] for GET, POST, PUT, PATCH, and DELETE. ```php enableTracy(__DIR__ . '/../log'); $configurator->setTempDirectory(__DIR__ . '/../temp'); // create DI container based on configuration in config.neon $configurator->addConfig(__DIR__ . '/../app/config.neon'); $container = $configurator->createContainer(); // set up routing $router = new Nette\Application\Routers\RouteList; $container->addService('router', $router); // route for URL https://example.com/ $router->addRoute('', function ($presenter, Nette\Http\Request $httpRequest) { // detect browser language and redirect to URL /en or /de etc. $supportedLangs = ['en', 'de', 'cs']; $lang = $httpRequest->detectLanguage($supportedLangs) ?: reset($supportedLangs); $presenter->redirectUrl("/$lang"); }); // route for URL https://example.com/cs or https://example.com/en $router->addRoute('', function ($presenter, string $lang) { // display the appropriate template, for example ../templates/en.latte $template = $presenter->createTemplate() ->setFile(__DIR__ . '/../templates/' . $lang . '.latte'); return $template; }); // run the application! $container->getByType(Nette\Application\Application::class)->run(); ``` -------------------------------- ### Get GET Request Parameters Source: https://doc.nette.org/en/http/request/3.x Retrieves all GET parameters or a specific parameter by its key. Returns null if the parameter does not exist. ```php $all = $httpRequest->getQuery(); // array of all URL parameters $id = $httpRequest->getQuery('id'); // returns GET parameter 'id' (or null) ``` -------------------------------- ### Example Entry Point in assets/app.js Source: https://doc.nette.org/en/assets/vite Defines the main JavaScript file for an application, importing styles and other modules, and initializing Nette Forms and Naja. ```javascript // Import styles import './style.css' // Import JavaScript modules import netteForms from 'nette-forms'; import naja from 'naja'; // Initialize your application netteForms.initOnLoad(); naja.initialize(); ``` -------------------------------- ### Install Nette PhpGenerator using Composer Source: https://doc.nette.org/en/php-generator/3.x Install the Nette PhpGenerator package using Composer. This command downloads and installs the library into your project. ```bash composer require nette/php-generator ``` -------------------------------- ### Install Nette Forms using Composer Source: https://doc.nette.org/en/forms/3.x This command installs the Nette Forms package using Composer. Ensure you have Composer installed and configured for your project. ```bash composer require nette/forms ``` -------------------------------- ### Product Presenter Example Source: https://doc.nette.org/en/application/how-it-works/3.x A basic Nette presenter class that injects a repository and defines a render method to fetch product data for a template. ```php class ProductPresenter extends Nette\Application\UI\Presenter { public function __construct( private ProductRepository $repository, ) { } public function renderShow(int $id): void { // obtain data from the model and pass it to the template $this->template->product = $this->repository->getProduct($id); } } ``` -------------------------------- ### Set, Get, and Remove Session Variables Source: https://doc.nette.org/en/http/sessions/3.x Manage variables within a session section using set(), get(), and remove() methods. 'get()' returns null if the variable does not exist. ```php // writing a variable $section->set('userName', 'john'); // reading a variable, returns null if it doesn't exist echo $section->get('userName'); // removing a variable $section->remove('userName'); ``` -------------------------------- ### Article Usage Source: https://doc.nette.org/en/dependency-injection/introduction Demonstrates how to instantiate and use the basic Article class. ```php $article = new Article; $article->title = '10 Things You Need to Know About Losing Weight'; $article->content = 'Every year millions of people in ...'; $article->save(); ``` -------------------------------- ### index.php for Web Applications Source: https://doc.nette.org/en/application/bootstrapping/3.x The `index.php` file in the `www/` directory initializes the Nette application by creating a Bootstrap instance, booting the web application, and running the Nette\Application\Application service. ```PHP $bootstrap = new App\Bootstrap; // Initialize the environment + create a DI container $container = $bootstrap->bootWebApplication(); // DI container creates a Nette\Application\Application object $application = $container->getByType(Nette\Application\Application::class); // Start the Nette application and process the incoming request $application->run(); ``` -------------------------------- ### Bootstrapping Test and Console Environments Source: https://doc.nette.org/en/application/bootstrapping/3.x Initialize the environment for unit tests using Tester\Environment::setup() or prepare for console applications by disabling debug mode and setting up the container. ```php public function bootTestEnvironment(): Nette\DI\Container { Tester\Environment::setup(); // Nette Tester initialization $this->setupContainer(); return $this->configurator->createContainer(); } public function bootConsoleApplication(): Nette\DI\Container { $this->configurator->setDebugMode(false); $this->initializeEnvironment(); $this->setupContainer(); return $this->configurator->createContainer(); } ``` -------------------------------- ### Service Creation via Static Method Source: https://doc.nette.org/en/dependency-injection/services Defines a service ('database') by invoking a static method 'create' from the 'DatabaseFactory' class. ```neon services: database: DatabaseFactory::create() ``` -------------------------------- ### Install RobotLoader with Composer Source: https://doc.nette.org/en/robot-loader/3.x Install the RobotLoader package using Composer. This is the standard method for adding it to your project. ```bash composer require nette/robot-loader ``` -------------------------------- ### Install Nette Code Checker Locally Source: https://doc.nette.org/en/code-checker Install Code Checker as a project dependency using Composer. ```bash composer create-project nette/code-checker ``` -------------------------------- ### Starting Vite Development Server Source: https://doc.nette.org/en/assets/vite Command to run the Vite development server using npm. ```bash npm run dev ``` -------------------------------- ### Install TypeScript Source: https://doc.nette.org/en/assets/vite Install the TypeScript package as a development dependency to enable full TypeScript support in your project. ```bash npm install -D typescript ``` -------------------------------- ### Install nette/security with Composer Source: https://doc.nette.org/en/security/3.x Install the nette/security package using Composer. This command adds the package as a dependency to your project. ```bash composer require nette/security ``` -------------------------------- ### Nette Framework Presentation Layer - Simple Blog Structure Source: https://doc.nette.org/en/application/directory-structure/3.x Provides an example of organizing the 'app/Presentation' directory for a simpler project, such as a blog. ```text **app/Presentation/** ├── **Front/** ← website frontend │ ├── **Home/** │ └── **Post/** ├── **Admin/** ← administration │ ├── **Dashboard/** │ └── **Posts/** ├── **Error/** └── **Export/** ← RSS, sitemaps, etc. ``` -------------------------------- ### Get HTTP Method Source: https://doc.nette.org/en/http/request/3.x Returns the HTTP method used for the current request (e.g., GET, POST, HEAD, PUT). ```php $httpRequest->getMethod(); // GET, POST, HEAD, PUT ``` -------------------------------- ### Initialize Configurator and Set Temp Directory Source: https://doc.nette.org/en/bootstrap Create an instance of Nette\Bootstrap\Configurator and specify a temporary directory for caching the generated DI container. Ensure this directory has write permissions on Linux/macOS. ```php $configurator = new Nette\Bootstrap\Configurator; $configurator->setTempDirectory(__DIR__ . '/temp'); ``` -------------------------------- ### Create a Class with Properties and Methods Source: https://doc.nette.org/en/php-generator Demonstrates creating a class with final, extends, implements, comments, and properties. The generated code can be output directly using echo. ```php $class = new Nette\PhpGenerator\ClassType('Demo'); $class ->setFinal() ->setExtends(ParentClass::class) ->addImplement(Countable::class) ->addComment("Class description.\nSecond line\n") ->addComment('@property-read Nette\Forms\Form $form'); // generate code simply by typecasting to string or using echo: echo $class; ``` ```php /** * Class description * Second line * * @property-read Nette\Forms\Form $form */ final class Demo extends ParentClass implements Countable { } ``` -------------------------------- ### Create Interface and Trait Source: https://doc.nette.org/en/php-generator/3.x Demonstrates the static methods for creating interface and trait definitions. ```php $interface = Nette\PhpGenerator\ClassType::interface('MyInterface'); $trait = Nette\PhpGenerator\ClassType::trait('MyTrait'); ``` -------------------------------- ### Install Nette HTTP with Composer Source: https://doc.nette.org/en/http/3.x Install the nette/http package using Composer. This is the standard method for adding the package to your PHP project. ```bash composer require nette/http ``` -------------------------------- ### Vite Configuration Example Source: https://doc.nette.org/en/assets/vite This snippet shows a complete Vite configuration object. It includes settings for the root directory, public directory, build output, development server, CSS handling, and plugin integration. ```javascript export default defineConfig({ // Root directory containing source assets root: 'assets', // Folder whose contents are copied to output directory as-is // Default: 'public' (relative to 'root') publicDir: 'public', build: { // Where to put compiled files (relative to 'root') outDir: '../www/assets', // Empty output directory before building? // Useful to remove old files from previous builds emptyOutDir: true, // Subdirectory within outDir for generated chunks and assets // This helps organize the output structure assetsDir: 'static', rollupOptions: { // Entry point(s) - can be a single file or array of files // Each entry point becomes a separate bundle input: [ 'app.js', // main application 'admin.js', // admin panel ], }, }, server: { // Host to bind the dev server to // Use '0.0.0.0' to expose to network host: 'localhost', // Port for the dev server port: 5173, // CORS configuration for cross-origin requests cors: { origin: 'http://myapp.local', }, }, css: { // Enable CSS source maps in development devSourcemap: true, }, plugins: [ nette(), ], }); ``` -------------------------------- ### Valid and Invalid Asset Loading Examples Source: https://doc.nette.org/en/assets/vite Illustrates correct and incorrect ways to use the {asset} macro, highlighting which files can be loaded directly. ```latte {* ✓ This works - it's an entry point *} {asset 'app.js'} {* ✓ This works - it's in assets/public/ *} {asset 'favicon.ico'} {* ✗ This won't work - random file in assets/ *} {asset 'components/button.js'} ``` -------------------------------- ### Install nette/phpstan-rules via Composer Source: https://doc.nette.org/en/best-practices/phpstan-rules Install the extension package using Composer. This is the standard method for adding development tools to your project. ```bash composer require --dev nette/phpstan-rules ``` -------------------------------- ### Simplified Class Constructor with Property Promotion in PHP Source: https://doc.nette.org/en/introduction-to-object-oriented-programming Illustrates a concise way to define a class property and initialize it via the constructor using PHP's constructor property promotion feature. ```php class Person { function __construct( private $age = 20, ) { } } ``` -------------------------------- ### Install Naja Library via npm Source: https://doc.nette.org/en/application/ajax/3.x Install the Naja library using npm for use with modern JavaScript build tools. ```bash npm install naja ``` -------------------------------- ### Dependency Injection for Initialization Source: https://doc.nette.org/en/dependency-injection/global-state This code demonstrates how to properly initialize objects by explicitly passing dependencies. It shows creating a DB instance and then passing it to the PaymentGateway constructor. ```php $db = new DB('mysql:', 'user', 'password'); $gateway = new PaymentGateway($db, /* ... */); ``` -------------------------------- ### Install and Import netteForms via npm Source: https://doc.nette.org/en/forms/validation Install the nette-forms package using npm and import it into your JavaScript project to enable form validation. ```javascript npm install nette-forms ``` ```javascript import netteForms from 'nette-forms'; netteForms.initOnLoad(); ``` -------------------------------- ### Logger Usage Source: https://doc.nette.org/en/dependency-injection/introduction Demonstrates how to instantiate and use the basic Logger class. ```php $logger = new Logger; $logger->log('Temperature is 23 °C'); $logger->log('Temperature is 10 °C'); ``` -------------------------------- ### Install Specific Development Version Source: https://doc.nette.org/en/best-practices/composer Install a specific development version of a package. This command allows you to target a precise pre-release or development branch. ```bash composer require nette/utils:4.0.x-dev ``` -------------------------------- ### Create Router and HTTP Request Directly Source: https://doc.nette.org/en/application/routing/3.x Shows how to instantiate the router and HTTP request objects directly without relying on a DI container. ```php $router = App\Core\RouterFactory::createRouter(); $httpRequest = (new Nette\Http\RequestFactory)->fromGlobals(); ``` -------------------------------- ### Using Latte Engine in Nette 2.2 Source: https://doc.nette.org/en/migrations/to-2-2 Demonstrates how to instantiate and configure the standalone Latte engine, including setting cache directories, adding filters, and handling template compilation. This replaces the previous Nette\Templating integration. ```php $latte = new Latte\Engine; // not the Nette\Latte\Engine $latte->setTempDirectory('/path/to/cache'); $latte->addFilter('money', function ($val) { return /* ... */; }); // addFilter() replaced registerHelper() from previous releases $latte->onCompile[] = function ($latte) { $latte->addMacro(/* ... */); // if you want add your own macros, see http://goo.gl/d5A1u2 }; $latte->render('template.latte', $parameters); // or $html = $latte->renderToString('template.latte', $parameters); ``` -------------------------------- ### Basic Service Definition with Constructor Arguments Source: https://doc.nette.org/en/dependency-injection/services Defines a service named 'database' and passes arguments to its constructor. ```neon services: database: PDO('mysql:host=127.0.0.1;dbname=test', root, secret) ``` -------------------------------- ### Create and Render an Image Element Source: https://doc.nette.org/en/utils/html-elements Demonstrates creating an element and setting its 'src' attribute. The element is then rendered to its HTML string representation. ```php $el = Html::el('img'); $el->src = 'image.jpg'; echo $el; ``` -------------------------------- ### Running PHP Executable Source: https://doc.nette.org/en/utils/process Shows how to run the PHP executable itself, for example, to check its version, using `runExecutable` and the `PHP_BINARY` constant. ```php $process = Process::runExecutable(PHP_BINARY, ['-v']); ``` -------------------------------- ### Session AutoStart Options Source: https://doc.nette.org/en/http/configuration/3.x Control when the session starts using 'always', 'smart', or 'never' options. 'smart' starts the session only if it exists or is accessed. ```yaml session: autoStart: always ``` ```yaml session: autoStart: smart ``` ```yaml session: autoStart: never ``` -------------------------------- ### Expression Language: Object Creation and Method Calls Source: https://doc.nette.org/en/dependency-injection/services Shows how to create objects, call static methods, and invoke PHP functions using the expression language. ```neon # create object DateTime() # call static method Collator::create(%locale%) # call PHP function ::getenv(DB_USER) ``` -------------------------------- ### Force Install Development Version with Alias Source: https://doc.nette.org/en/best-practices/composer Force Composer to install a development version while aliasing it to an older stable version. This is a workaround for dependency conflicts. ```bash composer require nette/utils "4.0.x-dev as 3.1.6" ``` -------------------------------- ### Install PHPStan for Nette Source: https://doc.nette.org/en/best-practices/editors-and-tools Install the PHPStan tool with Nette support using Composer. This is the first step to enabling static analysis for your Nette projects. ```bash composer require --dev phpstan/phpstan-nette ``` -------------------------------- ### open Source: https://doc.nette.org/en/utils/filesystem Opens a file and returns a resource handle, similar to PHP's native `fopen()`. ```APIDOC ## open ### Description Opens a file and returns a resource handle. The `$mode` parameter works the same as the native `fopen()` function. Throws a `Nette\IOException` on error. ### Method `open(string $path, string $mode): resource` ### Parameters * **$path** (string) - The path to the file. * **$mode** (string) - The mode in which to open the file (e.g., 'r', 'w', 'a'). ### Request Example ```php use Nette\Utils\FileSystem; $res = FileSystem::open('/path/to/file', 'r'); ``` ``` -------------------------------- ### Get Reference to Array Item Source: https://doc.nette.org/en/utils/arrays/3.x Gets a reference to a specific item within an array. If the item does not exist, a new one is created with a null value. ```php $valueRef = & Arrays::getRef($array, 'foo'); ``` -------------------------------- ### Get Database Connection from Container Source: https://doc.nette.org/en/bootstrap Retrieve a database connection object from the DI container. You can get it by its type or by a specific name if multiple connections are defined. ```php $db = $container->getByType(Nette\Database\Connection::class); // or $explorer = $container->getByType(Nette\Database\Explorer::class); // or when creating multiple connections $db = $container->getByName('database.main.connection'); ``` -------------------------------- ### Manual Explorer Creation Source: https://doc.nette.org/en/database/guide Manually create Nette\Database\Explorer instance if not using Nette DI container. Requires connection, structure, conventions, and cache storage. ```php // database connection $connection = new Nette\Database\Connection('mysql:host=127.0.0.1;dbname=mydatabase', 'user', 'password'); // cache storage, implements Nette\Caching\Storage, e.g.: $storage = new Nette\Caching\Storages\FileStorage('/path/to/temp/dir'); // handles database structure reflection $structure = new Nette\Database\Structure($connection, $storage); // defines rules for mapping table names, columns, and foreign keys $conventions = new Nette\Database\Conventions\DiscoveredConventions($structure); $explorer = new Nette\Database\Explorer($connection, $structure, $conventions, $storage); ```