Zend Framework How To: Creating your own validator for confirm passwords and emails

Filed Under (General) by Wenbert on 14-05-2008

Tagged Under : , ,

Last night I was working on the registration page of my pet-project. I am using Zend_Form for it but I had difficulties creating a validator to confirm 2 fields in the form. I chatted around #zftalk and checked the ZF Documentation but I could not understand anything. I needed a concrete working example.

Today I found this. It has more or less a complete coverage with sample source-code and some explanation.

My “register user” form consists of four elements:

  • Email
  • Confirm email
  • Confirm password
  • Password

Exactly what I was looking for ;)

Very nice syntax highlighting for Aptana

Filed Under (General) by Wenbert on 10-05-2008

Tagged Under : ,

I found this really nice syntax highlighting for Aptana — its called Green Chaud. The color is similar to Zenburn for Vim.

It’s been a few months since I planned to make public my Aptana color theme. After the lasts tweaks, here it is, the “Green Chaud” Aptana color theme !

It’s a light on dark theme, which is easier on the eyes than the standard theme.

PHP: Ternary Operator

Filed Under (General) by Wenbert on 07-05-2008

Tagged Under : ,

This is one my favorites. Sometimes I use this when I come around “short” conditions in variable assignments.

Instead of writing something like this:

if (isset($myvar)) {
    $temp = $myvar;
} else {
    $temp = ""; //i need to set this so that when I echo this, it won’t show a warning
}
 

I just use the ternary operator to make things easier to read by doing something like this:

$temp = isset($myvar)?$myvar:"";
 

Now how does it work? Basically, the syntax of the ternary operator is:
(condition)?“execute when true”:“execute when false”
On first glance it is confusing to use, but trust me, once you get the hang of it, you won’t be able to live without it.

On my way for a 3 day vacation :D

Filed Under (General) by Wenbert on 03-05-2008

I will not be updating for 3 days. I am on my way for a 3 day vacation. A much needed one. I have been killing myself slowing at work and on the side-jobs. I’ll see you guys Monday evening. Cheers!

Twitter moving away from Ruby on Rails

Filed Under (General) by Wenbert on 03-05-2008

Tagged Under : , , ,

This may be a rumor but Techcrunch is reporting that Twitter is abandoning Ruby on Rails due to scalability issues. I have read a few articles a while back about people having problems with Ruby on Rails. That is why I was hesitant to use Ruby on Rails on some of my web applications (at work). I was hesitant so therefore never got to learn it either :(.

Personally, I think the best bet for Twitter would be PHP. I would trust my life with PHP especially with scalability issues. Techcrunch also mentioned Java, but I doubt Java would work for them. Remember Friendster a few years back? It had a .jsp extension in the URL and it was almost unusable. It was dead slow.

The developers of Twitter can write a clone within a day and no one would notice it. They should use the Zend Framework :P Anyways, PHP is FTW!

Yahoo Mail Error :(

Filed Under (General) by Wenbert on 30-04-2008

Tagged Under :


Right now, I can’t open my Yahoo Mail :( I get this error. A page refresh didn’t fix it.

SVN: Revert to a previous revision after a wrong update

Filed Under (General) by Wenbert on 30-04-2008

Tagged Under :

Let’s say for example you accidentally ran “svn update” and your working copy got the updates that it shouldn’t have — unfinished patches, etc.

What you should do is check the logs using:

svn log | more

Look for the revision number then:

svn up -r 1234

*where 1234 is the previous revision number you want to go back to.

Zend_View Helper Tutorial

Filed Under (General) by Wenbert on 30-04-2008

Tagged Under : , , ,

Zend DevZone has a new article up.

What is a View Helper?

A View Helper is simply a class that follows particular naming conventions, When attached to a view object, you can call the helper as if it were a method of the view object itself. The View object retains helper instances, which means that they retain states between calls.

Common use cases for view helpers include:

* Accessing models
* Performing complex or repeatable display logic
* Manipulating and formatting model data
* Persisting data between view scripts

Mixing PHP Variables with Javascript (Zend Framework and jQuery)

Filed Under (General) by Wenbert on 23-04-2008

Tagged Under : , , ,

Sometimes, I “mix” PHP variables with Javascript. For example, I have something like this:

function deletenote(notes_id)
{
    if(!confirm("Delete note? You will not be able to undo this action."))
        return false;
       
    $.post("< ?=$this->baseUrl?>/notes/deletenote",{
        skeedl_notes_id: notes_id
    }, function(data){
        $(‘#notes_id’+data).fadeOut();
    });
}
 

Note the $this->baseUrl, I need it like that. The thing is, I have that code in my view file (.phtml - in Zend Framework, this is parsed like a normal PHP file). If I remove all the Javascript in my view file and place it in a .js file, the $this->baseUrl will not be parsed. To go around this, I create a hidden input element in my view file with $this->baseUrl echoed as the value. Like this:

// … in my .phtml file …
// rest of the php and html code goes here
< input type="hidden" id="base_url" value="<?=$this->baseUrl?>" />
// rest of the php and html code goes here
 

Then in my .js file (assuming that you have already included this file in your header, or somewhere else), I have something like this:

//This is using jQuery, but you can use document.getElementById(’base_url’).value if you like
function deletenote(notes_id)
{
    if(!confirm("Delete note? You will not be able to undo this action."))
        return false;
       
    $.post($(‘base_url’).val()+"/notes/deletenote",{
        skeedl_notes_id: notes_id
    }, function(data){
        $(‘#notes_id’+data).fadeOut();
    });
}
 

What it does is that jQuery gets the value of the hidden form element. The value of this hidden form element is from a PHP Variable.

So there you go, nothing special. Just something that works and I just wanted to share.

Zend Framework Blog Application Example / Tutorial

Filed Under (General) by Wenbert on 23-04-2008

Tagged Under : ,

This is useful to those who are trying to kick start a Zend Framework application.

Starting any new application is like walking into a shop and being dazzled by the displays. You want everything but finally realise you only have so much resources to spend. So you isolate the specifics you must have, and focus on those. That’s why I bought a Classic iPod, and not the much flashier iTouch (crap all storage anyway).

If we drill down the typical blog application we get a very short list of must-haves.

1. Authentication for Authors
2. Authorisation to create/edit/delete/read entries
3. Methods for adding new entries, and modifying them
4. Publishing entries as RSS and Atom
5. Permalinks unique for each entry (SEO friendly of course)
6. Commenting system
7. Spam detection for new comments
8. Perhaps, trackback detection

Click here for the entire post. I haven’t read the entire post yet - I just wanted to share it but I am assuming that it uses the new ZF1.5 stuff like Zend_Form and other cool features.

UPDATE: Here is the second part of the tutorial.

UPDATE2: Today (4-25-2008) Pádraic Brady just announced the link to his Subversion repository for the series of Zend Framework Blog Application Example. The SVN link is found here.