Skip to content

Instantly share code, notes, and snippets.

View vojtech-dobes's full-sized avatar

Vojtěch Dobeš vojtech-dobes

View GitHub Profile
@vojtech-dobes
vojtech-dobes / Questions.php
Created February 8, 2011 21:42
Nette AJAX example (requires jQuery & jquery.nette.js)
<?php
use Nette\Application\AppForm;
use Nette\Application\Control;
use Nette\Environment;
class Questions extends Control
{
const YES = 'yes';
@vojtech-dobes
vojtech-dobes / feanorm.many-to-many-example.php
Created March 5, 2011 19:58
Articles and categories used in example have many-to-many relation
<?php
# low-level
$feanorm->relate($article)->to($category)->on('categories');
$feanorm->unrelate($article)->to($category)->on('categories');
// The clause 'on' shouldn't be neccessary when only one relation between entities is present.
# practical api
@vojtech-dobes
vojtech-dobes / uimacros.example.latte
Created March 23, 2011 20:45
First draft for UI abstraction - UiMacros for Nette Framework
{*
* All ui:* macros should support basic HTML attributes as modificators,
* because in fact they are only abstractions of common HTML elements
* compatible with proper unobtrusive javascript service.
*}
{*
* Basic link
* 'href' attribute is automatically evaluated as 'n:href'
*}
@vojtech-dobes
vojtech-dobes / a_mysql-select.sql
Created July 28, 2011 15:03
Fetch the user: MySql vs CouchDB
SELECT `*` FROM `users` WHERE `username` = "john@doe.com" AND `password` = "xxx"
@vojtech-dobes
vojtech-dobes / ComponentFactory.php
Created August 3, 2011 15:39
Login Form as service (behavior via event callbacks)
<?php
namespace Clevispace;
use Nette\DI;
class ComponentFactory extends DI\Container
{
@vojtech-dobes
vojtech-dobes / example.latte
Created September 10, 2011 00:37
Latte helpers for HTML 5 data-attributes
{* with helper *}
<div id="with-data" data-example="{[a => b]|data}"></div>
{* with macro *}
<div id="with-data" n:data="example, [a => b]"></div>
<script>
var data = parseDataJson($('#with-data'), 'example');
// => data == {a: 'b'}
</script>
@vojtech-dobes
vojtech-dobes / gist:1297934
Created October 19, 2011 10:36
Fix for snippets rendered via Multiplier (unnecessary since 2.0.1 I guess)
<?php
// Nette/Latte/Macros/UIMacros - after line 507
$httpParams = $control->getPresenter()->getContext()->httpRequest->getQuery();
foreach ($control->getComponents(FALSE, 'Nette\Application\UI\Multiplier') as $multiplier) {
foreach ($httpParams as $param => $signal) {
if ($param == 'do' && Strings::startsWith($signal, $multiplier->getName()) && ($pos = strrpos($signal, '-')) !== FALSE) {
$child = $control->getComponent(substr($signal, 0, $pos));
$child->snippetMode = TRUE;
@vojtech-dobes
vojtech-dobes / 0-readme.markdown
Created November 19, 2011 11:02
Řešení NEON konfigurace s include

1: main.neon přepisuje vložené

Zde se hodí dát do .gitignore main.neon (abych mohl kdykoliv svoje údaje přepsat a nestrašilo mi to v gitu), ale zase musím na začátku pamatovat, že si do tohoto main.neon musím dát klauzuli include.

2: vložené přepisují main.neon

credentials.neon obsahuje opravdu jen to nejnutnější (tedy změněné údaje), není pro mě problém si ho hodit do .gitignore a při rozjíždění projektu si ho vytvořit (nemusím si pamatovat kromě jeho vytvoření nic jiného).

Přepsání služby v main.neon je zde ovšem zbytečné, protože ve skutečnosti je původní a bude přepsáno definicí z services.neon (která je ale opticky dříve).

@vojtech-dobes
vojtech-dobes / InputlistFormMacros.php
Created December 14, 2011 00:12
Manual rendering of Nette RadioList & CheckboxList
<?php
/**
* This file is part of the Nette Framework (http://nette.org)
*
* Copyright (c) 2004, 2011 David Grudl (http://davidgrudl.com)
*
* For the full copyright and license information, please view
* the file license.txt that was distributed with this source code.
*/
@vojtech-dobes
vojtech-dobes / BasePresenter.php
Created March 20, 2012 23:16
Annotation support for multiplied Nette components
<?php
use Nette\Application\UI;
use Nette\Reflection\Method;
class BasePresenter extends UI\Presenter
{
/** @var array datasets for Multipliers */