Zend_Db_Table_Abstract mit Singleton Pattern

Um nicht wegen jeder noch so kleinen Datenbankabfrage ein neues Object mit “$myModel = new Application_Model_DbTable_Daten();” erstellen zu müssen, um dann mit $myModel arbeiten zu können, wäre ein Singleton Pattern doch eine nette alternative. Bei der Umsetzung bin ich auf folgende Probleme gestoßen:

  1. getinstance() soll nicht in jedem Model stehen => von Abstrakter Klasse erben
  2. Instanzieren der ChildClass in der ParentClass
  3. Singleton Pattern in ParentClass heist, dass die ParentClass auch nur einmal existiert, was bei “protected $_name;” von Zend_Db_Table_Abstract schnell zu Problemen führt ;)

Um die Sache kurz zu halten, hier ist die ferige abstrakte Klasse:

abstract class My_Db_Table_Abstract extends Zend_Db_Table_Abstract{
  protected static $_instances = array();
  /**
   * für die auto. Codevervollständigung, z.B. in Netbeans
   * @return My_Db_Table_Abstract
   */
  public static function getInstance(){
    if(!isset(static::$_instances[get_called_class()]) || null === static::$_instances[get_called_class()]){
      static::$_instances[get_called_class()] = new static();
    }
    return static::$_instances[get_called_class()];
  }
}

Zu beachten ist hierbei, dass das “Late Static Binding” erst ab PHP Version 5.3 unterstützt wird.

Qt Cross-Compile Ubuntu -> ARM Cortex-A9 (Pandaboard)

1. Install G++ for ARM GNU/Linux

Quelle: https://sourcery.mentor.com/sgpp/lite/arm/portal/release1803 (hier)

$ chmod 755 arm-2011.03-41-arm-none-linux-gnueabi.bin
$ sudo dpkg-reconfigure -plow dash  // => No
$ ./arm-2011.03-41-arm-none-linux-gnueabi.bin
$ PATH=~/CodeSourcery/Sourcery_G++_Lite/bin:$PATH
$ export PATH

Installationsprozess durchlaufen…

2. Compile Qt libraries 4.7.4 for embedded Linux

Quelle: Qt libraries 4.7.4 for embedded Linux (202 MB)
qws/linux-omap3-g++/qmake.conf (linux-omap3-g++.tar.gz) :

#
# qmake configuration for building with arm-linux-g++
#

include(../../common/g++.conf)
include(../../common/linux.conf)
include(../../common/qws.conf)

# modifications to g++.conf
QMAKE_CFLAGS_RELEASE	= -march=armv7-a
QMAKE_CXXFLAGS_RELEASE	= -march=armv7-a -Wall -W -D_REENTRANT -pipe -fno-exceptions $(DEFINES)
QMAKE_CC                = arm-none-linux-gnueabi-gcc
QMAKE_CXX               = arm-none-linux-gnueabi-g++
QMAKE_LINK              = arm-none-linux-gnueabi-g++
QMAKE_LINK_SHLIB        = arm-none-linux-gnueabi-g++
OMAP3_GRAPHICS_SDK	= /home/omap3/OMAP35x_Graphics_SDK_new
#QMAKE_INCDIR_OPENGL 	+= $$OMAP3_GRAPHICS_SDK/GFX_Linux_SDK/OGLES/SDKPackage/Builds/OGLES/Include $$OMAP3_GRAPHICS_SDK/GFX_Linux_SDK/OGLES/SDKPackage/Builds/OGLES/LinuxOMAP3/Include
QMAKE_INCDIR_OPENGL 	+= $$OMAP3_GRAPHICS_SDK/GFX_Linux_SDK/OGLES2/SDKPackage/Builds/OGLES2/Include $$OMAP3_GRAPHICS_SDK/GFX_Linux_SDK/OGLES2/SDKPackage/Builds/OGLES2/LinuxOMAP3/Include
QMAKE_INCDIR_POWERVR	= $$OMAP3_GRAPHICS_SDK/include
QMAKE_LIBDIR_OPENGL     = /home/ubuntu/OMAP35x_Graphics_SDK/gfx_rel
#QMAKE_INCDIR_EGL	= $$OMAP3_GRAPHICS_SDK/GFX_Linux_SDK/OGLES/SDKPackage/Builds/OGLES/Include $$OMAP3_GRAPHICS_SDK/GFX_Linux_SDK/OGLES/SDKPackage/Builds/OGLES/LinuxOMAP3/Include
QMAKE_INCDIR_EGL	= $$OMAP3_GRAPHICS_SDK/GFX_Linux_SDK/OGLES2/SDKPackage/Builds/OGLES2/Include $$OMAP3_GRAPHICS_SDK/GFX_Linux_SDK/OGLES2/SDKPackage/Builds/OGLES2/LinuxOMAP3/Include
QMAKE_LIBDIR_EGL	= /home/ubuntu/OMAP35x_Graphics_SDK/gfx_rel
QMAKE_LIBS_EGL		= -lEGL -lIMGegl -lsrv_um
#QMAKE_LIBS_OPENGL_QT    = -lEGL -lGLES_CM -lIMGegl -lsrv_um
QMAKE_LIBS_OPENGL_QT    = -lEGL -lGLESv2 -lIMGegl -lsrv_um

# modifications to linux.conf
QMAKE_AR                = arm-none-linux-gnueabi-ar cqs
QMAKE_OBJCOPY           = arm-none-linux-gnueabi-objcopy
QMAKE_STRIP             = arm-none-linux-gnueabi-strip

load(qt_config)

Compilieren:

$ ./configure -prefix  -embedded arm -platform qws/linux-x86-g++ -xplatform qws/linux-omap3-g++ -depths 16,24,32 -no-mmx -no-3dnow -no-sse -no-sse2 -no-glib -no-cups -no-largefile -no-accessibility -no-gtkstyle -fast -little-endian
$ make

Das kann ne Weile dauern…

Setup WebDevelopment Environment on Mac OSX Lion

1. Netbeans installieren. (hier)

Das sollte noch jeder selbst hinbekommen ;)

2. MAMP installieren (hier)

MAMP oder MAMP Pro ist eigentlich egal, MAMP Pro hat die bessere GUI und macht vieles einfacher.

3. PHPUnit installieren (Pear)

Ihr bewegt euch im Terminal nach “/Applications/MAMP/bin/php/php5.3.6/bin”, hier folgende Befehle ausführen:

sudo ./pear channel-discover pear.phpunit.de
sudo ./pear channel-discover pear.symfony-project.com
sudo ./pear install phpunit/PHPUnit

4. PHPDocumentor installieren (Pear)

5. XDebug installieren (hier)

XDebug ist bei MAMP schon dabei, muss aber noch aktiviert werden. Hierfür muss die php.ini angepasst werden. man findest sie hier: ”/Applications/MAMP/bin/php/php5.3.6/conf”

Am Ende der php.ini findet man z.B. folgendes:

[xdebug]
;zend_extension="/Applications/MAMP/bin/php/php5.3.6/lib/php/extensions/no-debug-non-zts-20090626/xdebug.so"

Hier muss XDebug aktiviert und konfiguriert werden:

[xdebug]
zend_extension="/Applications/MAMP/bin/php/php5.3.6/lib/php/extensions/no-debug-non-zts-20090626/xdebug.so"
xdebug.remote_enable = On
xdebug.remote_host = localhost
xdebug.remote_port = 9010
xdebug.remote_handler=dbgp

Wenn man grade schon hier ist, sollte man das memory_limit hoch setzen, da die PHPUnit Test viel Speicher benötigen. 512M sollten für den Anfang reichen.

;;;;;;;;;;;;;;;;;;;
; Resource Limits ;
;;;;;;;;;;;;;;;;;;;

max_execution_time = 30  ; Maximum execution time of each script, in seconds
max_input_time = 60	 ; Maximum amount of time each script may spend parsing request data
memory_limit = 512M      ; Maximum amount of memory a script may consume (8MB)

6. IonCube Loader installieren (hier)

Kopiere die ioncube_loder_dar_5.3.so nach “/Applications/MAMP/bin/php/php5.3.6/lib/php/extensions/no-debug-non-zts-20090626/” und füge in der php.ini folgendes ein:

zend_extension="/Applications/MAMP/bin/php/php5.3.6/lib/php/extensions/no-debug-non-zts-20090626/ioncube_loader_dar_5.3.so"

(der Eintrag muss der erste zend_extension Eintrag in der php.ini sein)

7. Runkit installieren (hier)

Um runkit installieren zu können braucht man z.b XCode, da hier die Sources von php liegen.

ln -s /Developer/SDKs/MacOSX10.7.sdk/usr/include/ /Applications/MAMP/bin/php/php5.3.6/include
svn checkout http://svn.php.net/repository/pecl/runkit/trunk/
cd trunk
sudo /PATHTO/pecl install package.xml
You should add "extension=runkit.so" to php.ini

8. Zend Framework installieren (hier)

Kopiere den Zend und ZendX Ordner einfach nach “/Applications/MAMP/bin/php/php5.3.6/lib/php” oder richte hier symbolische Links ein.

9. Netbeans konfigurieren

PHP & XDebug

PHPUnit

PhpDoc

Zend Tool

 

Typo3: Embed YouTube Videos in tt_news

Um in der Typo3 Extension tt_news das Einbinden von YouTube-Videos oder ähnlichen zu ermöglichen muss das Template TypoScript anpassen:

RTE.default.proc.allowTags := addToList(iframe,embed,object,param)
RTE.default.proc.entryHTMLparser_db.allowTags := addToList(iframe,embed,object,param)
RTE.default.proc.allowTagsOutside := addToList(iframe,embed,object,param)

plugin.tt_news.displaySingle.content_stdWrap.parseFunc {
	nonTypoTagStdWrap.encapsLines.nonWrappedTag >
	allowTags = script, iframe, param, embed, object, a, abbr, acronym, address, blockquote, b, br, caption, center, cite, code, div, em, font, h1, h2, h3, h4, h5, h6, hr, i, img, li, link, ol, p, pre, q, sdfield, span, strike, strong, sub, sup, table, thead, tbody, tfoot, td, th, tr, tt, u, ul
}
plugin.tt_news.general_stdWrap.parseFunc.allowTags := addToList(iframe,embed,object,param,p)

In den Template Constants muss folgendes hinzgefügt werden:

styles.content.links.allowTags = b,i,u,a,img,br,div,center,pre,font,hr,sub,sup,p,strong,em,li,ul,ol,blockquote,strike,del,ins,span,h1,h2,h3,h4,h5,h6,address,iframe,object,param,embed

Zusätzlich sollte die /typo3/systext/rtehtmlarea/res/proc/pageTSConfig.txt

# ***************************************************************************************
# Default proc options in Page TSconfig for htmlArea RTE and Classic RTE
#
# Sets the proc options for all default configurations.
#
# Assumptions:	- CSS Styled Content is installed.
#		- XHTML output is expected.
#
# For documentation of RTE tranformations, see: http://typo3.org/documentation/document-library/core-documentation/doc_core_api/4.1.0/view/5/2/
# For documentation of Page TSConfig configuration of RTE processing, see: http://typo3.org/documentation/document-library/doc_core_api/Page_TSconfig/
# For documentation of the HTMLparser, see: http://typo3.org/documentation/document-library/doc_core_tsref/HTMLparser/
# For documentation of RTE settings in TCA, see: http://typo3.org/documentation/document-library/core-documentation/doc_core_api/4.1.0/view/4/3/#id3665895
#
# @author	Stanislas Rolland
#
# TYPO3 SVN ID: $Id: pageTSConfig.txt 3971 2008-08-12 21:13:52Z stan $
# ***************************************************************************************

	## Default RTE processing rules
RTE.default.proc {

		## TRANSFORMATION METHOD
		## We assume that CSS Styled Content is used.
	overruleMode = ts_css

		## DO NOT CONVERT BR TAGS INTO LINEBREAKS
		## br tags in the content are assumed to be intentional.
	dontConvBRtoParagraph = 1

		## PRESERVE DIV SECTIONS - DO NOT REMAP TO P
	preserveDIVSections = 1

		## TAGS ALLOWED OUTSIDE P & DIV
	allowTagsOutside = hr, address, object, param, embed, iframe

		## TAGS ALLOWED
		## Added to the default internal list: b,i,u,a,img,br,div,center,pre,font,hr,sub,sup,p,strong,em,li,ul,ol,blockquote,strike,span
		## But, for the sake of clarity, we use a complete list in alphabetic order.
		## center, font, link, meta, o:p, strike, sdfield, style, title and  u will be removed on entry (see below).
		## b and i will be remapped on exit (see below).
		## Note that the link accessibility feature of htmlArea RTE does insert img tags.
	allowTags (
		a, abbr, acronym, address, b, bdo, big, blockquote, br, caption, center, cite, code, col, colgroup, del, dfn, div, em, font,
		h1, h2, h3, h4, h5, h6, hr, i, img, ins, kbd, label, li, link, meta, ol, p, pre, q, samp, sdfield, small,
		span, strike, strong, style, sub, sup, table, thead, tbody, tfoot, td, th, tr, title, tt, u, ul, var,
		object, param, embed, iframe
		)

		## TAGS DENIED
		## Make sure we can set rules on any tag listed in allowTags.
	denyTags >

		## ALLOWED P & DIV ATTRIBUTES
		## Attributes class and align are always preserved
		## Align attribute will be unset on entry (see below)
		## This is a list of additional attributes to keep
	keepPDIVattribs = id, title, dir, lang, xml:lang

		## REMAP BOLD AND ITALIC TO STRONG AND EMPHASIS AND VICE VERSA
	transformBoldAndItalicTags = 1

		## ALLOW TO WRITE ABOUT HTML
	dontUndoHSC_db = 1
	dontHSC_rte = 1

		## CONTENT TO DATABASE
	entryHTMLparser_db = 1
	entryHTMLparser_db {

			## TAGS ALLOWED
			## Always use the same list of allowed tags.
		allowTags < RTE.default.proc.allowTags 			## TAGS DENIED 			## Make sure we can set rules on any tag listed in allowTags. 		denyTags >

			## AVOID CONTENT BEING HSC'ed TWICE
		htmlSpecialChars = 0

		tags {

				## REMOVE IMG TAGS
			img.allowedAttribs = 0
			img.rmTagIfNoAttrib = 1

				## CLEAN ATTRIBUTES ON THE FOLLOWING TAGS
			span.fixAttrib.style.unset = 1
			p {
				allowedAttribs = id, title, dir, lang, xml:lang, class
				fixAttrib.align.unset = 1
			}
			div < .p
			hr.allowedAttribs = class
			b.allowedAttribs = id, title, dir, lang, xml:lang, class
			bdo.allowedAttribs = id, title, dir, lang, xml:lang, class
			big.allowedAttribs = id, title, dir, lang, xml:lang, class
			blockquote.allowedAttribs = id, title, dir, lang, xml:lang, class
			cite.allowedAttribs = id, title, dir, lang, xml:lang, class
			code.allowedAttribs = id, title, dir, lang, xml:lang, class
			del.allowedAttribs = id, title, dir, lang, xml:lang, class
			dfn.allowedAttribs = id, title, dir, lang, xml:lang, class
			em.allowedAttribs = id, title, dir, lang, xml:lang, class
			i.allowedAttribs = id, title, dir, lang, xml:lang, class
			ins.allowedAttribs = id, title, dir, lang, xml:lang, class
			kbd.allowedAttribs = id, title, dir, lang, xml:lang, class
			label.allowedAttribs = id, title, dir, lang, xml:lang, class
			q.allowedAttribs = id, title, dir, lang, xml:lang, class
			samp.allowedAttribs = id, title, dir, lang, xml:lang, class
			small.allowedAttribs = id, title, dir, lang, xml:lang, class
			strike.allowedAttribs = id, title, dir, lang, xml:lang, class
			strong.allowedAttribs = id, title, dir, lang, xml:lang, class
			sub.allowedAttribs = id, title, dir, lang, xml:lang, class
			sup.allowedAttribs = id, title, dir, lang, xml:lang, class
			tt.allowedAttribs = id, title, dir, lang, xml:lang, class
			u.allowedAttribs = id, title, dir, lang, xml:lang, class
			var.allowedAttribs = id, title, dir, lang, xml:lang, class
			object.allowedAttribs = style
			param.allowedAttribs = name, value
			embed.allowedAttribs = src, type, allowfullscreen, allowScriptAccess, width, height
			iframe.allowedAttribs = src, width, height, frameborder
		}

			## REMOVE OPEN OFFICE META DATA TAGS, WORD 2003 TAGS, LINK, META, STYLE AND TITLE TAGS, AND DEPRECATED HTML TAGS
			## We use this rule instead of the denyTags rule so that we can protect custom tags without protecting these unwanted tags.
		  removeTags = center, font, link, o:p, sdfield, meta, style, title, strike, u

			## PROTECT CUSTOM TAGS
		keepNonMatchedTags = protect
	}

	HTMLparser_db {
			## STRIP ALL ATTRIBUTES FROM THESE TAGS
			## If this list of tags is not set, it will default to: b,i,u,br,center,hr,sub,sup,strong,em,li,ul,ol,blockquote,strike.
			## However, we want to keep xml:lang attribute on most tags and tags from the default list where cleaned on entry.
		noAttrib = br

			## XHTML COMPLIANCE
			## Note that applying xhtml_cleaning on exit would break non-standard attributes of typolink tags
		xhtml_cleaning = 1
	}

	exitHTMLparser_db = 1
	exitHTMLparser_db {
			## KEEP ALL TAGS
			## Unwanted tags were removed on entry.
			## Without this rule, the parser will remove all tags! Presumably, this rule will be more efficient than repeating the allowTags rule
		keepNonMatchedTags = 1

			## AVOID CONTENT BEING HSC'ed TWICE
		htmlSpecialChars = 0
	}
}

	## Use same RTE processing rules in FE
RTE.default.FE.proc < RTE.default.proc 	## RTE processing rules for bodytext column of tt_content table 	## Erase settings from other extensions RTE.config.tt_content.bodytext >

	## Make sure we use ts_css transformation
RTE.config.tt_content.bodytext.proc.overruleMode = ts_css
RTE.config.tt_content.bodytext.types.text.proc.overruleMode = ts_css
RTE.config.tt_content.bodytext.types.textpic.proc.overruleMode = ts_css

(Getestet mit Typo3 in der Version 4.2.9 und tt_news 2.5.2)

JTL-Shop3: Hersteller Array im Template

Um im Template Zugriff auf eine erweiterte Herstellerliste (nicht $smarty.session.Hersteller) zu bekommen, braucht man gar nicht viel.

1. Anpassung der functions.php des Templates:

$smarty->register_function("getHersteller", "getHersteller");

function getHersteller($params, &$smarty){
	$a = gibHersteller(NULL);
	$smarty->assign("oHersteller_arr", $a);
}

2. Zugriff im Template

{getHersteller}
    {foreach name=hersteller from=$oHersteller_arr item=hst}
  • {$hst->cName}
  • {/foreach}

Somit hat man nicht nur Zugriff auf die Hersteller-Id und den Namen, sondern auch auf die Bilder, MetaDaten, Homepage, SEO-Daten und vieles mehr…

Für einen “var_dump” kann man folgenden Code verwenden:

{php}
  $hst = $this->get_template_vars('hst');
  var_dump($hst);
{/php}

Kleiner Nachtrag: Wenn man nur Hersteller mit mindestens X Artikeln anzeigen möchte (functions.php):

function getHersteller($params, &$smarty){
	$a = gibHerstellerMinArtikel(NULL, $params['min']);

	$smarty->assign("oHersteller_arr", $a);
}

function gibHerstellerMinArtikel($Einstellungen, $min = 0)
{
    $oHersteller_arr = array();
    if(!intval($min))$min = 0;

    $oHerstellerTMP_arr = $GLOBALS['DB']->executeQuery("SELECT thersteller.kHersteller, count(tartikel.kArtikel) as cArtikel
														FROM thersteller
														JOIN tartikel ON thersteller.kHersteller = tartikel.kHersteller
														GROUP BY thersteller.kHersteller
														HAVING cArtikel >= $min
														ORDER BY thersteller.cName", 2);

	// URL umbauen
	if(count($oHerstellerTMP_arr) > 0)
	{
        require_once(PFAD_ROOT . PFAD_CLASSES . "class.JTL-Shop.Hersteller.php");

		foreach($oHerstellerTMP_arr as $oHerstellerTMP)
            $oHersteller_arr[] = new Hersteller($oHerstellerTMP->kHersteller);
	}

	return $oHersteller_arr;
}