Seva's notes

Wisdom, Awareness, Responsibility :)

Archive for the ‘html’ Category

Zend Framework View Script Recursion

leave a comment »

We know that in Zend Framework View Scripts it’s possible  to run in a recursion using a View Helper – either Partial, or Action, or a custom one.

However all of these become a certain execution overhead in case we need just a simple one-time tree traversal. Also for readability purpose, it would be nice to have the recursion defined inline.

Luckily, since PHP 5.3 we can use self referencing closures to define the behavior within the script:


<?php
$showTree = function(array $entities) use(&$showTree) {?>
 <?if(!$entities) return?>
 <ul>
 <?foreach($entities as $entity):?>
 <li><?=$entity->getName()?></li>
 <?=$showTree($entity->getChildren())?>
 <?endforeach?>
 </ul>
<?}
?>
<?=$showTree($this->entities)?>

Written by Seva

2013-04-03 (April 3) at 11:37:04

Simple No-Framework Object Oriented Multi-Layer MVC Application Example

with one comment

Recently I’ve created the subj. It’s a memory game, written in pure PHP/HTML, called “PHP Memory”.

What was important for me to demonstrate is the next principles:

  1. Even if you don’t use a framework, you should write modular code with appropriate architecture.
  2. Despite that, the application design and code should match its required functionality with no overhead of unneeded patterns and abstraction or preparations for future enhancements, unless they’re planned.
  3. Nevertheless, the code should be readable and maintainable.
  4. The bottom line is – developing a framework versus developing an application are completely different tasks. The strategy and tactics should vary very much. Of course, developers should learn from the frameworks source code, since they accumulate collective experience of great coders, but the ideas implemented in frameworks sometimes not required or even harmful while developing an application.
The demo and source code can be found here.

Written by Seva

2011-08-30 (August 30) at 01:59:26

SyntaxHighlighter

leave a comment »

Shame on me! I’ve discovered that wordpress.com provides syntaxHighlighter functionality just today. So I hurry to report that the only 2 posts in this blog, which contain code snippets have been immediately converted:

<a href="https://sevalapsha.wordpress.com/2008/06/26/copy-nodes-xml-documents-java-dom/">
    Copying nodes between XML documents with Java DOM
</a>
&amp;
<a href="https://sevalapsha.wordpress.com/2008/08/11/prototype-google-analytics-javascript/">
    Prototype styled Google Analytics javascript snippet
</a>

BTW, isn’t it weird I don’t have one snipped in PHP yet?

Written by Seva

2009-09-16 (September 16) at 09:14:52

Posted in html, java, javascript, php, software, web, xml

Tagged with

Prototype styled Google Analytics javascript snippet

leave a comment »

Recently I’ve created a prototype styled javascript snippet to enable google analytics on one of my sites. Save this code in google.analytics.js file and include it from the head tag of the page just after including of the prototype.js:

gaTrackerId = 'ss-ddddddd-d'; // insert your tracker id here
document.observe('dom:loaded', function() {
    var gaJsHost = (
        'https:' == document.location.protocol
            ? 'https://ssl.'
            : 'http://www.'
    ) + 'google-analytics.com/ga.js';
    var script = new Element('script', { 'src': gaJsHost});
    var gaTrack = function() {
        if (
            !script.readyState
            || /loaded|complete/.test(script.readyState)
        ) {
            var pageTracker = _gat._getTracker(gaTrackerId);
            pageTracker._trackPageview();
        }
    };
    script.observe('load', gaTrack);
    script.observe('readystatechange', gaTrack);
    document.body.appendChild(script);
});

Written by Seva

2008-08-11 (August 11) at 08:00:07

Integration of Zend Framework and Prototype Ajax

with 3 comments

Last two days I’ve worked on implementing an example of integration of Zend Framework‘s MVC and Prototype‘s Ajax for HTML Forms submission and validation.

The solution consist of 2 parts:

1. There is a new View Helper to create an Ajax-enabled form.

This part mostly consists of JavaScript code, which alters default HTML Form behavior to submit the input element values to the action’s URL with Ajax, if form’s method is set to ‘ajax’.

In addition the form itself listens to submission result events and (by default) marks input elements if they are invalid.

2. There is a new customized abstract base Controller which replaces default ViewRenderer with a new one, which:

a) detects whether the request was received from Ajax.
b) if true, will not render the view, but instead will output with the input validation information, if either.

Well, the development is not really over yet, but what I originally wanted to say is I’ve just realized how I miss writing good old JS. 🙂

By the way, I need to repeat [ad:start] how happy I am to have PHP, HTML and JavaScript editors in one powerful standardized environment (Eclipse) – what I never had in the past, before PDT, WST & ATF came to the picture [ad:end] :)).

Written by Seva

2007-10-29 (October 29) at 10:49:00