dracoblue.net

PDT Autovervollständigungstipps (für Agavi)

Mit den PDT (PHP Development Tools für Eclipse) kannst Du die meisten Variablen in PHP autovervollständigen. Das aber meist nur, sofern sie richtig definiert sind oder das php-doc richtig eingepflegt ist.

Dieser Artikel zeigt ein paar Tipps, wie Du auch in unklaren Situationen die Autovervollständigung eindeutig machen kannst. Wenn Du lediglich

die aktuellste Version von PDT aufsetzen möchtest, schau Dir bitte das andere Tutorial an.

Graste hat ein kleines Script veröffentlicht, welches dem gesamten (Agavi-)Projekt in Eclipse sagt, dass die Variablen $template, $ro, $rd usw. vom richtigen Typ definiert sind. Diese sind normalerweise in Agavitemplates verfügbar, werden aber via .xml beim Compile-Vorgang reinkompiliert und sind daher für Eclipse nicht sichtbar.

Hier meine leicht veränderte autocomplete.php:

<?php
exit();
$slots = array();
$template = array(); // agavi 0.11 standard
$t = array(); // agavi 1.0 standard
$tm = new AgaviTranslationManager();
$ro = new AgaviWebRouting();
$rq = new AgaviWebRequest();
$ct = new AgaviController();
$us = new AgaviSecurityUser();
$rd = new AgaviWebRequestDataHolder();
?>

Diese Datei einfach als autocomplete.php in Dein Projekt speichern und Eclipse wird diese Variablen standardgemäß mit dieser Klasse initialisiert vermuten und schon hat man die nette Autovervollständigung auch in Agavitemplates.

Wenn Du den Rückgabetyp für eine Funktion auch für einen bestimmten Typ (und damit autovervollständigungsfähig) definieren möchtest, brauchst Du nur die PHP-Docs richtig zu setzen. In diesem Beispiel gibt die Funktion test123() ein SomeClass-getyptes Element zurück:

/**
 * [strong]@return SomeClass[/strong]
 */
function test123() {
	/* ... */
}

Manchmal möchte man, dass eine Variable für einen bestimmten Scope den richtigen Typ hat. Das geht dann wie folgt:

if (false) $instance = new [strong]SomeClass[/strong]();

oder besser sogar

/* @var $instance [strong]SomeClass[/strong] */

und Eclipse wird die Variable $instance nun für eine SomeClass halten.

Hast Du weitere Tipps? Dann schreib sie bitte in die Kommentare!

In Agavi, Eclipse, PDT for Eclipse, open source, php by DracoBlue @ 2009-02-23 | 292 Words

Preloading CSS-images for :hover

The top navigation here at dracoblue.net is done with css images, which also have a :hover-effect (showing a lighter version of the image).

So there is a:

http://dracoblue.net/style/menu_news_hover.png

and a

http://dracoblue.net/style/menu_news.png

In CSS it looked like that:

a#newsLink {
	background: transparent url('menu_news.png') no-repeat;
}
a#newsLink:hover {
	background: transparent url('menu_news_hover.png') no-repeat;
}

All this is quite common, but I was facing a usability problem here. The

*hover.png files won't be loaded until one of the links got hover'd. In the perspective of the server owner, you might be happy about that. But for the user, the image is unavailable for nearly a second, because it takes time to deliver the image to the user.

So here is my solution to preload the image (without using javascript or stub-'s).

td#newsLink a {
  background: transparent url('menu_news.png') no-repeat;
}
td#newsLink a:hover {
  background: transparent url('menu_news_hover.png') no-repeat;
}
[strong]td#newsLink {
	background:
		transparent
		url('menu_news_hover.png')
		fixed no-repeat
		-120px -120px;
}[/strong]

I moved the #newsLink to the td surrouding the newsLink. And at the end, I added a new decleration for a non-repeating and - with coordinates -120x-120 - clearly invisible image.

In CSS, HTML, open source by DracoBlue @ 2009-02-23 | 185 Words

Vorladen von CSS-Bildern für :hover

Die Navigation von dracoblue.net habe ich mit CSS-Background Bildern und einem :hover-effect gemacht. Beim Hovern, wird das Bild dann einfach in einer etwas helleren Version zeigt.

Es gibt also:

http://dracoblue.net/style/menu_news_hover.png

und

http://dracoblue.net/style/menu_news.png

In meinem CSS, sieht das dann so aus:

a#newsLink {
	background: transparent url('menu_news.png') no-repeat;
}
a#newsLink:hover {
	background: transparent url('menu_news_hover.png') no-repeat;
}

All dass ist natürlich gängige Praxis, aber ich hatte damit ein Usability-Problem für meine Benutzer. Die

*hover.png Dateien werden erst geladen, sobald man mit der Maus über den Navigationseintrag geht, ihn also hover't. In der Perspektive des Serverbesitzers, ist man darüber vielleicht froh. Aber für den Benutzer, ist das neue (hellere) Bild, für knapp eine Sekunde nicht verfügbar. Es dauert ja ein bisschen, bis das Bild vom Server zum User kommt.

Hier nun meine Lösung, woe man die Bilder vorlädt (ohne Javascript oder stub-'s zu benutzen).

td#newsLink a {
  background: transparent url('menu_news.png') no-repeat;
}
td#newsLink a:hover {
  background: transparent url('menu_news_hover.png') no-repeat;
}
[strong]td#newsLink {
	background:
		transparent
		url('menu_news_hover.png')
		fixed no-repeat
		-120px -120px;
}[/strong]

In dem Beispiel habe ich das #newsLink auf das td des eigentlichen Links verschoben. Abschließend, habe ich eine neue Definition eingefügt, die ein sich nicht-wiederholendes und - mit Koordinaten -120x-120 - eindeutig unsichtbares Bild anzeigt.

In CSS, HTML, open source by DracoBlue @ 2009-02-23 | 202 Words

Concat multiple references as one imploded column (mysql)

In my blog I have the following structure (short version):

entry = id,title
category = id,name
entry_in_category = category_id, entry_id

I want to query for the following:

id | title           | categories
---------------------------------
1  | My Entry        | php,mysql
2  | Second ...      | mysql,java

So if you want to get all entries with the corresponding categories you may do a refetch on each of the entries id in the entry_in_category table. But if (for example for tags) you really just want to have the name of the categories and nothing more, here comes a pretty gentle way to solve that issue.

SELECT 
	e.id, e.title,
	(
		SELECT <a href="http://dev.mysql.com/doc/refman/5.0/en/group-by-functions.html#function_group-concat">GROUP_CONCAT</a>(c.name)
		FROM entry_in_category e_i_c 
			LEFT JOIN category c ON c.id=e_i_c.category_id
		WHERE e_i_c.entry_id = e.id
	) categories
FROM entry e

This solution uses the

GROUP_CONCAT function, which was intruduced in mysql 4.1 and concats all results name-fields (oviously not grouped by anything) into a single string.

By default mysql concats the entries by using a ',' but you may use a different seperator by replacing the group-concat-part with the following:

GROUP_CONCAT(c.name SEPARATOR '-')

Thanks to Christian for bringing up a similiar issue, hope that solution helps you to get an idea on how to deal with similiar cases.

In mysql, open source by DracoBlue @ 2009-02-21 | 206 Words

UTF-8 connections with Propel in Agavi

If you want to override the propel configurations for charset (encoding) for the connection you usally set the settings['charset'] value to for example utf8.

But if you are using agavi you want to configure propel properly by using agavi's databases.xml.

So after trying a while, here is how you can set the charset (magic is

bold):

<?xml version="1.0" encoding="UTF-8"?>
&lt;ae:configurations
  xmlns:ae="http://agavi.org/agavi/config/global/envelope/1.0"
  xmlns="http://agavi.org/agavi/config/parts/databases/1.0">
  &lt;ae:configuration>
    &lt;databases default="propel">
      &lt;database name="propel"
        class="AgaviPropelDatabase">
        &lt;ae:parameter name="config">%core.app_dir%/config/propelproject-conf.php&lt;/ae:parameter>
        &lt;ae:parameter name="overrides">
          &lt;ae:parameter name="connection">
            &lt;ae:parameter name="dsn">mysql:dbname=icanhazagavirelease;host=127.0.0.1&lt;/ae:parameter>
            &lt;ae:parameter name="user">w00t&lt;/ae:parameter>
            &lt;ae:parameter name="password">not_default_pass&lt;/ae:parameter>
            [strong]&lt;ae:parameter name="settings">
              &lt;ae:parameter name="charset">
                &lt;ae:parameter name="value">utf8&lt;/ae:parameter>
              &lt;/ae:parameter>
            &lt;/ae:parameter>[/strong]
          &lt;/ae:parameter>
        &lt;/ae:parameter>      
      &lt;/database>
    &lt;/databases>
  &lt;/ae:configuration>
&lt;/ae:configurations>

In Agavi, Propel, open source, php by DracoBlue @ 2009-02-18 | 95 Words

Page 28 - Page 29 - Page 30