Skip to content

Instantly share code, notes, and snippets.

View juriansluiman's full-sized avatar

Jurian Sluiman juriansluiman

View GitHub Profile
@juriansluiman
juriansluiman / IndexController.php
Created October 14, 2011 08:31
IndexController with "preDispatch" event simulation
<?php
namespace Application\Controller;
use Zend\Mvc\Controller\ActionController
Zend\Mvc\MvcEvent;
class IndexController extends ActionController
{
public function indexAction()
@juriansluiman
juriansluiman / Barcode.php
Created October 27, 2011 07:18
Barcode view helper
<?php
class Soflomo_View_Helper_Barcode extends Zend_View_Helper_Abstract
{
public function barcode ($text, $type = 'code128', $options = array())
{
$options = array('text' => $text) + $options;
$resource = Zend_Barcode::draw(
$type, 'image', $options, array()
);
@juriansluiman
juriansluiman / 1. Application.md
Created November 8, 2011 14:35
Modular application system for ZF2

Application system

This document describes how a system can be formed to set up modules in combination with a tree of pages stored in the database. The general idea is to have pages stored within a database in a tree structure, where every page is coupled to a module (1:n). Pages are queried and parsed to routes as a combination of the page route and the modules route(s).

Goal

Webapplications exist often with a frontend (for normal visitors) and backend (to manage the whole bunch). Also some pages might want to utilize the same module (two simple text pages as basic example). Thirdly, it should be easy for end users to create new pages, modify them or delete pages. To accomplish this, a robust system ("content management framework") should be made on top of zf2 to accomodate this.

Configuration

@juriansluiman
juriansluiman / 1. Wrapper.phtml
Created November 25, 2011 15:11
Three step based view
<?php echo $this->doctype() ?>
<html>
<head>
<?php echo $this->headTitle() ?>
<?php echo $this->headMeta() ?>
<?php echo $this->headLink() ?>
<?php echo $this->headScript() ?>
</head>
@juriansluiman
juriansluiman / 1. Actions.html
Created November 26, 2011 20:24
jQuery plugin for modal dialogs
<!--
First use case: ask for a confirmation before requesting the uri in the hyperlink
Everything works with html5 data attributes. Possible options:
* data-template: id in dom or uri for contents of modal. This attribute is required
* data-title: title of the modal
* data-method: specify a GET or POST request, defaults to GET
* data-submit: specify the label of the button to continue to the link, defaults to "Submit"
* data-cancel: specify the label of the button to cancel the modal, defaults to "Cancel"
* data-* : every other attribute can be used to replace keys in the template
@juriansluiman
juriansluiman / Requirements.md
Created March 13, 2012 10:00
Requirements for an Assetic module in ZF2

Assetic module in ZF2

This file describes my opinion of the integration of a public asset management tool within Zend Framework 2. It doesn't necessarily involve Assetic, but because Assetic is the most advanced and most used tool, I will focus on that. There is already an alternative module for Assetic integration, but the configuration of this module strikes 100% against my opinion of usage patterns. Therefore I write this document, to open up the discussion about improvements of zf2-assetic-module or write an alternative module.

Main usage pattern

The people using asset management tools are probably the frontend developers, as they write the html code in views, layouts etc. Currently they use helpers like headLink, headScript and inlineScript to control the assets. Starting point for this text is their workflow should not change as much as possible.

This means, an Assetic module should override the view helpers plugin broker, providing al

@juriansluiman
juriansluiman / Module.php
Created July 11, 2012 13:14
Set a default locale for your application in Zend Framework 2
<?php
namespace Application;
use Locale;
use Zend\EventManager\Event;
use Zend\ModuleManager\Feature;
class Module implements
Feature\BootstrapListenerInterface
{
@juriansluiman
juriansluiman / RFC.md
Created August 19, 2012 12:28
New Navigation module for Zend Framework 2

Proposal for a new navigation component

This document is a start to get a new navigation component of the ground. The current Zend\Navigation has shown to be a powerful component for navigation purposes. On the other hand, the code is since it's introduction in Zend Framework 1.8 not really updated. The complexity is for some features very difficult to comprehend. In ZF2, the overhaul of the view helpers made it even more difficult to customize the behaviour of Zend\Navigation.

The good parts:

  1. A structure of containers and pages to create hierarchal trees
  2. A set of domain layer-like objects (containers and pages) and view helpers to render them into html
  3. The option to mark pages as "active"
  4. The option to tune visibility of pages
  5. The option to attach an ACL object to the navigation list to show or hide parts based on access permission
@juriansluiman
juriansluiman / DI.php
Created March 31, 2013 13:25
Dependency injection versus Service Locator pattern
<?php
// Dependency
class Dependency
{
}
// Service
@juriansluiman
juriansluiman / BarController.php
Last active December 16, 2015 17:49
Standard CRUD methods in Controllers / Services / Repositories for Zend Framework 2
<?php
namespace Foo\Controller;
use Foo\Repository\BarInterface as Repository;
use Foo\Form\BarInterface as Form;
use Foo\Service\BarInterface as Service;
use Foo\Options\ModuleOptions;
use Zend\Mvc\Controller\AbstractActionController;