If you want to understand what's in your Zend_Search_Lucene index files, then download Luke (http://www.getopt.org/luke/) and point it at the directory containing your index files.
views/helpers/MyHelper.php contains class Zend_View_Helper_MyHelper which has a function called myHelper()
Also, if you add a function called setView() to your class, then the View will pass you an instance of itself before it calls your view helper function.
i.e.
Class Zend_View_Helper_MyHelper
{
protected $_view;
public function setView($view)
{
$this->_view = $view;
}
public function myHelper($myVar)
{
return $this->_view->escape($myVar);
}
}
Just a heads-up. Tomorrow, this site is being moved to a new server and so is going to be down for most of tomorrow from around 10:00 (GMT) to late evening.
$filters = array('body' => array('StringTrim' , 'StripTags'));
$validators = array('body' => 'Alpha');
$input = new Zend_Filter_Input($filters, $validators, $_POST);
if ($input->isValid()) {
// do something with form
} else {
// failed validation
$messages = $input->getMessages();
// iterate though $messages to display to user
}
The problem is that the message you get out isn't always written as you would like. Consider the output if the body record is empty. A dump() of $messages gives this:
array(1) {
["body"] => array(1) {
[0] => string(21) "" is an empty string"
}
}
The text isn't exactly what I would want to display to a user. To change it you pass in a messages parameter to the $validators array:
$filters = array('body' => array('StringTrim' , 'StripTags'));
$validators = array( 'body' => array('Alpha',
'messages'=>array(Zend_Validate_Alpha::STRING_EMPTY=>'The body is empty!')));
$input = new Zend_Filter_Input($filters, $validators, $_POST);
This works as expected. The problem now is that you need to know the "magic constants", so here is a list of all the constants and the associated default message:
Zend_Validate_Alnum::NOT_ALNUM
'%value%' has not only alphabetic and digit characters
Zend_Validate_Alnum::STRING_EMPTY
'%value%' is an empty string
Zend_Validate_Alpha::NOT_ALPHA
'%value%' has not only alphabetic characters
Zend_Validate_Alpha::STRING_EMPTY
'%value%' is an empty string
Zend_Validate_Between::NOT_BETWEEN
'%value%' is not between '%min%' and '%max%', inclusively
Zend_Validate_Between::NOT_BETWEEN_STRICT
'%value%' is not strictly between '%min%' and '%max%'
Zend_Validate_Ccnum::LENGTH
'%value%' must contain between 13 and 19 digits
Zend_Validate_Ccnum::CHECKSUM
Luhn algorithm (mod-10 checksum) failed on '%value%'
Zend_Validate_Date::NOT_YYYY_MM_DD
'%value%' is not of the format YYYY-MM-DD
Zend_Validate_Date::INVALID
'%value%' does not appear to be a valid date
Zend_Validate_Digits::NOT_DIGITS
'%value%' contains not only digit characters
Zend_Validate_Digits::STRING_EMPTY
'%value%' is an empty string
Zend_Validate_EmailAddress::INVALID
'%value%' is not a valid email address in the basic format local-part@hostname
Zend_Validate_EmailAddress::INVALID_HOSTNAME
'%hostname%' is not a valid hostname for email address '%value%'
Zend_Validate_EmailAddress::INVALID_MX_RECORD
'%hostname%' does not appear to have a valid MX record for the email address '%value%'
Zend_Validate_EmailAddress::DOT_ATOM
'%localPart%' not matched against dot-atom format
Zend_Validate_EmailAddress::QUOTED_STRING
'%localPart%' not matched against quoted-string format
Zend_Validate_EmailAddress::INVALID_LOCAL_PART
'%localPart%' is not a valid local part for email address '%value%'
Zend_Validate_Float::NOT_FLOAT
'%value%' does not appear to be a float
Zend_Validate_GreaterThan::NOT_GREATER
'%value%' is not greater than '%min%'
Zend_Validate_Hex::NOT_HEX
'%value%' has not only hexadecimal digit characters
Zend_Validate_Hostname::IP_ADDRESS_NOT_ALLOWED
'%value%' appears to be an IP address, but IP addresses are not allowed
Zend_Validate_Hostname::UNKNOWN_TLD
'%value%' appears to be a DNS hostname but cannot match TLD against known list
Zend_Validate_Hostname::INVALID_DASH
'%value%' appears to be a DNS hostname but contains a dash (-) in an invalid position
Zend_Validate_Hostname::INVALID_HOSTNAME_SCHEMA
'%value%' appears to be a DNS hostname but cannot match against hostname schema for TLD '%tld%'
Zend_Validate_Hostname::UNDECIPHERABLE_TLD
'%value%' appears to be a DNS hostname but cannot extract TLD part
Zend_Validate_Hostname::INVALID_HOSTNAME
'%value%' does not match the expected structure for a DNS hostname
Zend_Validate_Hostname::INVALID_LOCAL_NAME
'%value%' does not appear to be a valid local network name
Zend_Validate_Hostname::LOCAL_NAME_NOT_ALLOWED
'%value%' appears to be a local network name but but local network names are not allowed
Zend_Validate_InArray::NOT_IN_ARRAY
'%value%' was not found in the haystack
Zend_Validate_Int::NOT_INT
'%value%' does not appear to be an integer
Zend_Validate_Ip::NOT_IP_ADDRESS
'%value%' does not appear to be a valid IP address
Zend_Validate_LessThan::NOT_LESS
'%value%' is not less than '%max%'
Zend_Validate_NotEmpty::IS_EMPTY
Value is empty, but a non-empty value is required
Zend_Validate_Regex::NOT_MATCH
'%value%' does not match against pattern '%pattern%'
Zend_Validate_StringLength::TOO_SHORT
'%value%' is less than %min% characters long
Zend_Validate_StringLength::TOO_LONG
'%value%' is greater than %max% characters long
Finally, you can also change the generic "not empty" and "missing" messages in Zend_Filter_Input using:
$options = array(
'notEmptyMessage' => "A non-empty value is required for field '%field%'",
'missingMessage' => "Field '%field%' is required"
);
$filters = array('body' => array('StringTrim' , 'StripTags'));
$validators = array('body' => 'Alpha');
$input = new Zend_Filter_Input($filters, $validators, $_POST);
$input->setOptions($options);
Now you can fix those messages to say something useful and your users will thank you for it!
Now that it's been announced by Manning, I think I can talk a little more about the project that's been taking up most of my spare time!
Zend Framework in Action is a collaboration between myself and Nick Lo. We are still writing, but Chapter 1 is available for you to download and see where we are heading with the book. Manning has an early access program where you can get access to pre-production PDFs of each chapter if you can't wait. As a bonus for signing up early, you get to tell us what's wrong (and what's right!) before the prose is committed to the printed page so we can fix it and you'll get a better final book.
In order to set expectations, I should probably point out that Zend Framework in Action is a tutorial book intended to show how to use the components of the framework together within "real world" projects. Each component is dealt with in a "what is it?", "why use it?", "how do you use it?", "let's use it in the real world" manner. It's not an advanced exposition of each component as that would take many books!
So far, I've learnt that writing a book is considerably different (and much harder!) than writing a tutorial. Having help from the excellent people at Manning has eased the transition from writing when I feel like it to sitting down and writing daily. I still need to work out how to write good quality prose at a decent pace though!
I've finally updated the source code to my Zend Framework tutorial so that the hidden field in the form is named "id" rather than "ID". A minor error that meant that editing didn't work! This is because in PHP $_POST['id'] is not the same as $_POST['ID']!
Whilst I was poking around the source code, I also changed the Zend Auth tutorial to use $db rather than $dbAdapter so that it is consistent with the first tutorial. I've updated the PDF to reflect this too.
I've also updated the Zip files for both tutorials too.