Skip to content

Instantly share code, notes, and snippets.

@cilf
Created April 29, 2013 18:51
Show Gist options
  • Save cilf/5483788 to your computer and use it in GitHub Desktop.
Save cilf/5483788 to your computer and use it in GitHub Desktop.

Nette PHP Framework

Why would you even consider looking into $this PHP framework?

Because there's no other like Nette!


Have a look at this

Two-way routing

You start working on a project. Even in these early stages you should know how the URLs going to look like because you simply need to put something in that href.

Not with Nette!

Nette lets you use links in templates as if they were pointing to methods in Presenters(Controllers). Such as: routing

And later on when you get the idea of your project structure you define all the URLs with simple routing configuration: routing

You're asking what does that 'two-way' approach mean? Well it creates the URLs by the routing definition as well as matches them from incoming requests.

All smooth in one place. That's the Nette way!


Latte templating system

Ugly piece of code from our team project generating list of people and their friendship status:

templates

Would look with Latte (Nette templating system that is also working standalone!) like:

templates

Couple things to notice:

Syntax highlighting and more with Nette NetBeans plugin.

N-attributes give you the power of controlling HTML elements with ease.
Look at line 1 - if the user is not logged in the paragraph is to be shown!
Line 4 says give me the list of people and iterate for each of them create a new <p>.

Line 5 lets you see how easily you can print escaped strings. That is indeed the most useful Macro.
Our escaping is a fancy girl! It uses Context-Aware Escaping - escapes differently in HTML, JS, XML, CSS contexts. Safety first!
Wanna see other example of macro? Look at all those {if}s. And there's much more(official documentation)

What is that $person|heShe|capitalize you're asking?. Let me introduce you to Helpers!
That's basically a function that takes the left operand as a parameter. Capitalize is predefined, heShe prints either "he" or "she" depending on the sex of the $person!
You should definitely have a look at other predefined helpers(official documentation).

No performance issues here! All templates are translated into raw PHP and saved in files.

Still having doubts?


Look at these Debugging Tools

Nette provides a developer with handy Debug bar.

Debug bar also allows developer to show dumped variables, SQL statements queried to database and much more.

When an error or exception occurs, Nette contains excellent debuggin tool that allows developer to ses the whole stack trace as well as function arguments and enviromental properties.


Creating forms with ease!

Following code snippet generates HTML5 valid code as well as javascript client validation

form

Lines 10 and 12 show you how easily you can set up validation rules.
XSS and CSRF threats are avoided. More on forms in official documentation


It has everything you need.

Just to mention:

  • MVC design pattern
  • Dependency Injection
  • Namespaces
  • Database layer & ORM
  • Unit-testing tools
  • Sending Emails
  • Localization
  • User Authentication & Authorization
Please visit official documentation for more on these.


Do you want to see more source codes?

See examples on GitHub or have a look into sandbox project.
That is the skeleton you can download and kick off your project with.

Keep exploring

There's a brand new QuickStart tutorial that walks you thru your first application!


NOW would be a good time to install this puppy!

Install using Composer

The modern way of installing PHP libraries is thru Composer. Composer also let's the developer to manage dependencies. Find Nette on Packagist.

When you have Composer running on your machine, creating new Nette project is as simple as typing following in a command line:

$ composer create-project nette/sandbox your-project-name

Download .zip and unpack

You can also download the latest version as a .zip file. Unpack it and start using it.

If you feel adventurous here's .zip dev version. Or get it from straight from GitHub!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment