Skip to content

Instantly share code, notes, and snippets.

<?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.
*/
@juzna
juzna / FormContainer.php
Created March 19, 2011 00:32
Nette\Forms\FormContainer
<?php
class FormContainer {
/**
* Fill-in with values.
* @param array|Traversable values used to fill the form
* @param bool erase other controls?
* @return FormContainer provides a fluent interface
*/
public function setValues($values, $erase = FALSE)
@juzna
juzna / BasePresenter.php
Created April 5, 2011 02:42
Allowing errors
<?php
class BasePresenter extends \Nette\Presenter {
/**
* @overload When sending AJAX response, send also number error details
* @return array
*/
public function sendPayload() {
// Add errors to payload
if(\Nette\Debug::$errors) {
ob_start();
@juzna
juzna / basic.php
Created September 15, 2011 09:46
Renderers
<?php
class Movie {
const GENRE_HORROR = 1;
const GENRE_SCIFI = 2;
const GENRE_FAMILY = 3;
const GENRE_X0 = 4; // just to have more labels (for performance testing)
const GENRE_X1 = 5;
const GENRE_X2 = 6;
@juzna
juzna / EntityForm.php
Created December 27, 2011 14:14
Data binding in Nette
<?php
class EntityForm extends Form {
/**
* Bind entity to this form and set default values from it
*
* @param \Nella\Models\IEntity $entity
* @throws \Nette\InvalidStateException
*/
public function bind(\Nella\Models\IEntity $entity)
@juzna
juzna / EntitySelectBox.php
Created December 27, 2011 14:54
EntitySelectBox
<?php
use Nette\Forms\Controls\BaseControl,
Nella\Models\IEntity;
/**
* Select box control that display entities
*
* @author Jan Dolecek <juzna.cz@gmail.com>
*/
@juzna
juzna / datagrid.php
Created December 28, 2011 17:43
RFC: how to DataGrid
Intro: Need to display tables of content, they need to be dynamic (pagable, sortable, filterable), how to solve it?
-------------------------------------------
1st - static table
<table>
<thead>
<tr>
<th>#</th>
<th>Published</th>
@juzna
juzna / test.php
Created December 30, 2011 14:25
Doctrine partial fetch
<?php
// method 1 - partial fetch
{
$q = $em->createQuery("select partial a.{id,title}, length(a.body) from Model\\Article a");
$q->setMaxResults(1);
$list = $q->execute();
$entity = $list[0][0];
/*dump($entity);*/
var_dump($entity->body); // NULL as it was not fetched
@juzna
juzna / test-ob.php
Created January 16, 2012 13:20
PHP Output Buffer bug
<?php
$path = "/tmp/ob.log";
$logHandle = fopen($path, 'w') or die("unable to open temp file");
ob_start(function($buffer) use ($logHandle) { fwrite($logHandle, $buffer); }, 20);
echo str_repeat("0", 20); // fill in the buffer
for($i = 0; $i < 10; $i++) {
@juzna
juzna / 01-choose.png
Created January 23, 2012 20:30
GitHub Play
01-choose.png