Zend Framework 1.7.0 is now available!
Almost three hundred bugs fixed and many welcome additions, one of which is the new Performance Guide in the reference manual.
1.7.0 can be downloaded from the Zend Framework download site.
Well done ZF Team!
Almost three hundred bugs fixed and many welcome additions, one of which is the new Performance Guide in the reference manual.
1.7.0 can be downloaded from the Zend Framework download site.
Well done ZF Team!
One thing those of you who have been using Zend_Dojo_Form might have noticed is that dojo enabled forms don’t show validation warnings when submitted i.e. when the submit button is clicked. This can be quite confusing for the end user.
So, how do we get our dojo enabled forms to validate when submitted?
Matthew Weier O’Phinney explains on nabble that:
You need to bind to the onSubmit event of your form, and validate in
your callback. One way to do this is as follows, from your view script:
< ? $this->dojo()->javascriptCaptureStart() ?> function validateForm() { var form = dijit.byId("<formid>"); if (!form.validate()) { alert("Invalid form"); return false; } return true; } < ? $this->dojo()->javascriptCaptureEnd() ?> < ? $this->dojo()->onLoadCaptureStart() ?> function () { dojo.connect(dijit.byId("</formid><formid>"), "onSubmit", "validateForm"); } < ? $this->dojo()->onLoadCaptureEnd() ?> </formid>
What the above does is connect the onSubmit event to the form, which
then executes the validateForm() function; if this returns false,
submission is halted, and, in this case, an alert raised. You could also
popup a dialog box or some other notification.
The above snippet of code Matthew describes doesn’t quite work. An Issue has been created for it here http://framework.zend.com/issues/browse/ZF-4587, but there is a work around, we can use headScript()->capture instead.
The view helper:
library/My/View/Helper/ValidateDojoForm.php
class My_View_Helper_ValidateDojoForm extends Zend_View_Helper_Abstract { public $view; public function setView(Zend_View_Interface $view) { $this->view = $view; } /** * Validate dojo enabled form onSubmit. * * @param string $formId * @return void */ public function ValidateDojoForm($formId) { $this->view->headScript()->captureStart(); ?> function validateForm() { var form = dijit.byId("< ?php echo $formId; ?>"); if (!form.validate()) { return false; } return true; } dojo.addOnLoad(function () { dojo.connect(dijit.byId("< ?php echo $formId; ?>"), "onSubmit", "validateForm"); }); < ?php $this->view->headScript()->captureEnd(); } }
This is very simple view helper. All you need to do is call validateDojoForm in your view script passing in the id of the form you want to be validated on submission as follows:
$this->validateDojoForm('formId');
Helper paths need set up, one way of doing this is in our bootstrap as follows:
/** * Initialize view and layouts */ $layout = Zend_Layout::startMvc('/path/to/layouts'); $view = $layout->getView() ->addHelperPath('My/View/Helper/', 'My_View_Helper') ->addHelperPath('Zend/Dojo/View/Helper/', 'Zend_Dojo_View_Helper');
More information on view helpers and helper paths.
What about a custom class that does all the work for us?
library/My/Dojo/Form.php
class My_Dojo_Form extends Zend_Dojo_Form { /** * Set form name * * @param string $name * @return Zend_Form */ public function setName($name) { parent::setName($name); $this->getView()->validateDojoForm($this->getName()); return $this; } }
All this does is call our validateDojoForm helper and pass it the id of the form we create. Now we create all our Dojo forms by extending our custom class:
class Form_Name extends My_Dojo_Form { public function init() { $this->setName('myForm'); $this->addElement('ValidationTextBox', 'name', array( 'validators' => array( array('StringLength', false, array(0, 255)), ), 'label' => 'Name', 'required' => true, 'invalidMessage' => 'Please type your name.', 'trim' => true, )); $this->addElement('SubmitButton', 'submitButton', array( 'required' => false, 'ignore' => true, 'label' => 'Save' ) ); } }
Be sure to call setName() when creating your form. This will call our validateDojoForm helper and pass it the id of the form we create and thus capturing the neccessary javascript to validate our form when it’s submitted.
enjoy!
Logging database queries to FireBug is sinfully simple with the new component Zend_Db_Profiler_Firebug in ZF 1.6, now available, you can download it here Zend Framework Download Page.
Requirements:
More information on requirements at the Zend Framework Documentation - Profiling with Firebug
Let’s look at some examples.
< ?php // Instatiate the database $db = Zend_Db::factory('Pdo_Mysql', array( 'host' => 'localhost', 'dbname' => 'zf_feature_testing', 'username' => 'user123', 'password' => 'pass123' ) ); // Instantiate the profiler in your bootstrap file $profiler = new Zend_Db_Profiler_Firebug('All Database Queries:'); // Enable it $profiler->setEnabled(true); // Attach the profiler to your db adapter $db->setProfiler($profiler); // Run your queries $result1 = $db->fetchAll('SELECT * FROM zf_test'); $result2 = $db->fetchAll('SELECT * FROM zf_test where id = ?', 3);
Alternatively you can add the profiler parameters to the Zend_Db factory.
< ?php // Instatiate the database, passing in the profiler parameters. $db = Zend_Db::factory('Pdo_Mysql', array( 'host' => 'localhost', 'dbname' => 'zf_feature_testing', 'username' => 'user123', 'password' => 'pass123', 'profiler' => array( 'enabled' => true, 'class' => 'Zend_Db_Profiler_Firebug' ) ) );
Or from an .ini file using Zend_Config_Ini
$config = new Zend_Config_Ini('../application/config.ini', 'development'); $db = Zend_Db::factory($config->database);
config.ini
[development] database.adapter = pdo_mysql database.params.host = localhost database.params.username = user123 database.params.password = pass123 database.params.dbname = zf_feature_testing database.params.profiler.enabled = true database.params.profiler.class = Zend_Db_Profiler_Firebug
Show me my profiling data?
Open FireBug, you will see a link under console.

Click it open and it will list all the queries that were run.

Enjoy!
Wildfire, captcha and dojo integration are just some of the highlights.
“Watch this presentation to hear the entire Zend Framework team talk about what to expect from Zend Framework 1.6, soon to be released.
Presented by Wil Sinclair, Development Manager, Matthew Weier O’phinney, Software Architect, Alexander Veremyev, Software Engineer and Ralph Schindler, Software Engineer. - Zend“
Quickstart Screencasts
Zend Developer Zone Tutorials
Zend_Acl and MVC Integration Part I (Basic Use)
Zend_Acl and MVC Integration Part II (Advanced Use)
Matthew Weier O’Phinney Tutorial
Login and Authentication with Zend Framework
“
Zend_Authdoes a lot of behind the scenes work to make persisting an identity in the session trivial. Combine it withZend_Form, and you have a very easy to implement solution for retrieving and validating credentials; add standard hooks in theZend_Controllercomponent for filtering actions prior to dispatch, and you can restrict access to applications easily based on authentication status.”
Zend
“
Zend_Authhelps web developers to implement authentication for their applications by providing a simple API and various adapters for popular authentication backends, such as LDAP, InfoCard, and OpenID. In this webinar, we implemented the authentication process usingZend_Authand demonstrate its flexibility and extensibility for custom functionality.”