[fw-general] zend_form:display validation and error messages
I have a common ‘Contact Form’ in my project which is called in most of pages like index, about us etc. this page accept user inputs and sent an email to admin, then return back to the page, from which it is called Code for contact form is class Form_Contactus extends Zend_Form { public function init() { $this-setMethod('post'); $this-setAction('contactus/index'); $frontController = Zend_Controller_Front::getInstance(); $pageName = $this-createElement('hidden','pageName'); $pageName-setValue( $frontController-getRequest()-getControllerName() ); $FullName = $this-createElement('text','FullName'); $FullName-setLabel('Full Name') -setRequired(true) -addFilter('StripTags') -addFilter('StringTrim') -addValidator('NotEmpty'); $Email = $this-createElement('text','Email'); $Email-setLabel('Email') -setRequired(true) -addFilter('StringTrim') -addValidator('EmailAddress') -addValidator('NotEmpty'); $Message = $this-createElement('textarea','Message'); $Message-setLabel('Message') -setAttribs( array('rows' = 3, 'cols' = 20 )) -setRequired(true) -addFilter('StripTags') -addFilter('StringTrim') -addValidator('NotEmpty'); $submit = $this-createElement('submit','submit'); $submit-setLabel('Submit') -setIgnore(true); $this-addElements(array( $pageName, $FullName, $Email, $Message, $submit, )); } } Please note that, the line $this-setAction('contactus/index');. My idea is, if I fill this form (note it is a common form) from index page, it pass through 'contactus controller’ index action. Sent a mail from there and return back to index page. If the page is filled from about us page, it return back to about us page. It is included in the different pages like index, about etc by code $conForm = new Form_Contactus(); echo $conForm; And the controller code looks like as class ContactusController extends Zend_Controller_Action { protected $_redirector = null; public function init() { $registry =Zend_Registry::getInstance(); $this-msgObj =$registry['MessageHandler']; } public function indexAction() { $this-_helper-layout()-disableLayout(); $this-_helper-viewRenderer-setNoRender(); $form = new Form_Contactus(); if ($this-_request-isPost()) { $formData = $this-_request-getPost(); if ($form-isValid($formData)) { $pageName = $formData['pageName']; $FullName = $formData['FullName']; $Email = $formData['Email']; $Message= $formData['Message']; if( strlen(trim( $FullName) ) ){ $mailBody .= Name:\r\n\t.$FullName .\r\n\r\n; $mailBody .= Email:\r\n\t.$Email .\r\n\r\n; $mailBody .= Message:\r\n\t.$Message .\r\n\r\n; $mail = new Zend_Mail(); $transport = new Zend_Mail_Transport_Smtp('localhost'); Zend_Mail::setDefaultTransport($transport); $mail-setSubject('Contact Enquiry.'); $mail-setFrom($Email, $FullName); $mail-addTo(CONTACT_ADMIN_EMAIL, CONTACT_ADMIN_NAME); $mail-setBodyText($mailBody); if( $mail-send() ){
[fw-general] Re: Zend_Validate_NotEmpty and unchecked radio button marked as required fields
Hi again, Just following up on the issue I previously described to see if someone can confirm the issue and to see if there's a different(better) solution for it. It's a problem that need to be solved before I can upgrade our application to 1.9.x because it messes with our custom error messages and translations. Thank you in advance for your help. Martin Carpentier On Thu, Sep 3, 2009 at 17:19, Martin Carpentier carpentier.mar...@gmail.com wrote: Hi, since the modification made to Zend_Validate_NotEmpty in ZF 1.9.0 (checking the value for valid types) radio buttons set with the required flags don't return the proper error message if submitted without any of its options checked. here's a simple example to recreate the problem: // in a TestController public function testAction() { $request = $this-getRequest(); $form = new Zend_Form(); $form-setAction('/test/test') -setName('formTest') ; $options = array( 'no'= 'no', 'yes' = 'yes', ); $form-addElement('Radio', 'testRadio', array( 'label'= test ?, 'required' = true, 'multiOptions' = $options, )); $form-addElement('Submit', 'suivant', array( 'required' = false, 'ignore' = true, 'label'= 'submit test', )); if ($this-getRequest()-isPost()) { if ($form-isValid($request-getPost())) { Zend_Debug::dump($form); } } $this-view-form = $form; } Now, when submitting the form without selecting any option, we get the invalid message: Invalid type given, value should be float, string, or integer Before 1.9.0 we would get the correct and expected message: Value is required and can't be empty The problem is caused by the addition of those lines in Zend_Validate_NotEmpty: if (!is_string($value) !is_int($value) !is_float($value) !is_bool($value)) { $this-_error(self::INVALID); return false; } With that check in place, a null $value would get flagged as being of an INVALID type A fix would be to check also that the value is not null like this: if (null !== $value !is_string($value) !is_int($value) !is_float($value) !is_bool($value)) { $this-_error(self::INVALID); return false; } Let me know if I should submit a bug report... or if I shouldn't be expecting that behavior anymore. Martin Carpentier
[fw-general] How to config multiple menus ?
Hi, Zend_Navigation likes to be really helpful for me ! But there are some cases on which i couldn't find enough documentation. What I would have liked, is to be able to create multiple menus without instancing different Zend Navigation object. Here is an UC : a main menu with a 'Home' root. a footer menu without root, or one which will not be displayed. I understood how to render a subMenu from the 'main menu' But I wasn't able to config multiple menus without using hacks or something.. I tried to add a 'group' elements to my top level label, and then tried to render using the magic __call with findOneByGroup('main'); But it didn't work. Any ideas on how I could achieve this ?
Re: [fw-general] Zend Framework QuickStart
-- bizhat flash...@gmail.com wrote (on Monday, 07 September 2009, 08:00 PM -0700): I have been trying to study Zend Framework. I have followed Zend Quick start, the database part looks very complex. http://framework.zend.com/docs/quickstart/create-a-model-and-database-table This is how every one create their models ? To me it looks very complex and time consuimg to create model with data mapper (3 files for a database). How this is going to save time and increase productivity ? This is *one* approach to creating models in ZF. The reason it is used here is for several reasons. The most important reason is that coupling models to the database is problematic. Models should just be classes; how you persist them should be decoupled. Why? * What if your data storage in production will be done via a web service? * How do you easily test model interactions when models are tied to the database? It's a non-trivial task that involves creation of and maintenance of database fixtures, and creates a lot more work than simply testing object interactions. * Where do you introduce caching when you need it? (This is trivial to do when you have de-coupled persistence from the models.) CakePHP have only 3 lines to create a model. http://book.cakephp.org/view/334/Create-a-Post-Model Why Zend need 3 large and complex files to handle database interaction ? 3 files and complex code need more processing time and slow up application ? I'd argue that performance is not going to be the issue here. Processing function calls and object creation is much faster than the actual I/O used to interact with the database. The benefits you get, as outlined above, will outweigh the extra code in most situations. -- Matthew Weier O'Phinney Project Lead| matt...@zend.com Zend Framework | http://framework.zend.com/
Re: [fw-general] Zend Framework QuickStart
I think one of the things that he is complaining is that the process of doing models in the Zend Framework is not well defined yet, it is not a problem for advanced programmers that know how to architect the system in a good way, but really trouble for new programmers. But i think it may get better as soon new proposals like Zend_Entity get mature enough to support this kind of separation Mathew is talking about. ::: Diego Potapczuk On Tue, Sep 8, 2009 at 7:45 AM, Matthew Weier O'Phinney matt...@zend.comwrote: -- bizhat flash...@gmail.com wrote (on Monday, 07 September 2009, 08:00 PM -0700): I have been trying to study Zend Framework. I have followed Zend Quick start, the database part looks very complex. http://framework.zend.com/docs/quickstart/create-a-model-and-database-table This is how every one create their models ? To me it looks very complex and time consuimg to create model with data mapper (3 files for a database). How this is going to save time and increase productivity ? This is *one* approach to creating models in ZF. The reason it is used here is for several reasons. The most important reason is that coupling models to the database is problematic. Models should just be classes; how you persist them should be decoupled. Why? * What if your data storage in production will be done via a web service? * How do you easily test model interactions when models are tied to the database? It's a non-trivial task that involves creation of and maintenance of database fixtures, and creates a lot more work than simply testing object interactions. * Where do you introduce caching when you need it? (This is trivial to do when you have de-coupled persistence from the models.) CakePHP have only 3 lines to create a model. http://book.cakephp.org/view/334/Create-a-Post-Model Why Zend need 3 large and complex files to handle database interaction ? 3 files and complex code need more processing time and slow up application ? I'd argue that performance is not going to be the issue here. Processing function calls and object creation is much faster than the actual I/O used to interact with the database. The benefits you get, as outlined above, will outweigh the extra code in most situations. -- Matthew Weier O'Phinney Project Lead| matt...@zend.com Zend Framework | http://framework.zend.com/
Re: [fw-general] Zend_Validate::is() runs constructor with wrong parameters
I just wonder how the Int validator should check if a value is between something as it just checks if a given value is a integer or not. Shouldn't in your case Zend_Validate_Between be used ? For Zend_Validate_Int the question is where the 1 comes from. As you did not provide an example how you called Zend_Validate::is() we can only guess. Greetings Thomas Weidner, I18N Team Leader, Zend Framework http://www.thomasweidner.com - Original Message - From: Dennis Becker mail.dennisbec...@gmail.com To: Zend Framework General fw-general@lists.zend.com Sent: Tuesday, September 08, 2009 3:03 PM Subject: [fw-general] Zend_Validate::is() runs constructor with wrong parameters II have recently switched ZF Version from 1.7.4 to ZF 1.9.2 and I ran into a problem with Zend_Validate::is() and Zend_Validate_Int. A variable should be checked if it is an integer and between 1 and 31 - nothing special so far. But Zend_Validate calls Zend_Validate_Int with 1 as parameter for the constructor - which self tries to find a locale with Zend_Locale::findLocale('1') - and then throws an exception. I know that this worked without any problem with 1.7.4 On the SVN repository, I can see that with ZF Version 1.8.0 a constructor was added to Zend_Validate_Int. Can anybody confirm this? I have opened a bug report at http://framework.zend.com/issues/browse/ZF-7800 Also compare these files: http://framework.zend.com/svn/framework/standard/tags/release-1.7.5/library/Zend/Validate/Int.php http://framework.zend.com/svn/framework/standard/tags/release-1.8.0/library/Zend/Validate/Int.php Has anybody a workaround for this? Or is it just a wrong behaviour in Zend_Validate::is() static method? Regards, Dennis
[fw-general] Zend_Validate::is() runs constructor with wrong parameters
II have recently switched ZF Version from 1.7.4 to ZF 1.9.2 and I ran into a problem with Zend_Validate::is() and Zend_Validate_Int. A variable should be checked if it is an integer and between 1 and 31 - nothing special so far. But Zend_Validate calls Zend_Validate_Int with 1 as parameter for the constructor - which self tries to find a locale with Zend_Locale::findLocale('1') - and then throws an exception. I know that this worked without any problem with 1.7.4 On the SVN repository, I can see that with ZF Version 1.8.0 a constructor was added to Zend_Validate_Int. Can anybody confirm this? I have opened a bug report at http://framework.zend.com/issues/browse/ZF-7800 Also compare these files: http://framework.zend.com/svn/framework/standard/tags/release-1.7.5/library/Zend/Validate/Int.php http://framework.zend.com/svn/framework/standard/tags/release-1.8.0/library/Zend/Validate/Int.php Has anybody a workaround for this? Or is it just a wrong behaviour in Zend_Validate::is() static method? Regards, Dennis
[fw-general] Why serialize twice for Zend_Cache?
Hello, I am using Zend_Cache with Zend_Cache_Backend_Memcached (which is using php_memcache) extension. Since the php_memcache extension already do serialization automatically, but Zend_Cache would need me to serialize me before saving into cache, so this turn out that the data actually stored in memcached was serialize twice times. Anyone got the same experience. Thanks.
[fw-general] Debug Warning Zend Loader line 165
Should I expect to see these debug warnings when debugging my ZF-based application in Zend Studio? Debug Warning: /www/lib/zend/ZendFramework-1.9.2/library/Zend/Loader.php line 165 - fopen(/www/vhosts/local.test.com/application/views/helpers/Url.php) [a href='function.fopen'function.fopen/a]: failed to open stream: No such file or directory Debug Warning: /www/lib/zend/ZendFramework-1.9.2/library/Zend/Loader.php line 165 - fopen(/www/vhosts/local.test.com/application/views/helpers/HeadLink.php) [a href='function.fopen'function.fopen/a]: failed to open stream: No such file or directory Debug Warning: /www/lib/zend/ZendFramework-1.9.2/library/Zend/Loader.php line 165 - fopen(/www/vhosts/local.test.com/application/views/helpers/Layout.php) [a href='function.fopen'function.fopen/a]: failed to open stream: No such file or directory The source code is the latest available from the ZF Quick Start guide. Zend Application is being used. The application loads and works. For example, even though there's a debug warning about Url.php, you can tell that ZF eventually finds and loads the correct Url.php, because the link does show up in the final webpage. I found this article talking about the problem and it seems to offer a solution. I just can't tell if the new Quick Start guide takes advantage of it or if I'm just misunderstanding - that I should always expect to see the debug warnings? http://devzone.zend.com/article/4525-Developing-a-Comprehensive-Autoloader. Here's my main concern... A lot of debug warnings like this show up when I debug my main ZF application. As a result, I tend to ignore the debug console output. That seems like a bad habit considering that some of the warnings may need to be addressed. Plus, it seems like a smooth running application shouldn't have any warnings or errors. The second concern is that there might be some sort of overhead involved in generating these warnings. Wouldn't resolving this issue improve the overall performance of my application? I'm testing using code from the Quick Start guide to keep things simple and provide some sort of reference point. I'm hoping there's a way for me to adjust the configuration and eliminate these debug warnings. Or, at the very least, it would be nice having the confirmation that everything is configured properly - the warnings and associated overhead are expected and part of how ZF works. Thanks, Ed
[fw-general] view helpers within a view helper
I create a view helper to show comments for a article.(by getting article_id from comments table and using foreach to get each comment). But in comment table only has commentator's id. I used a view helper to convert user_id to get the user name. With in a view helper can I call another view helper? How do I handle this case? -- View this message in context: http://www.nabble.com/view-helpers-within-a-view-helper-tp25351769p25351769.html Sent from the Zend Framework mailing list archive at Nabble.com.
Re: [fw-general] view helpers within a view helper
If you extend Zend_View_Abstract, your view helper will have the view set as the $view property of the class, allowing you to call other helpers like this: $this-view-someOtherHelper(); Or, you can add your own setView() method public function setView(Zend_View_Interface $view) { $this-view = $view; } Take a look at this page for more information: http://framework.zend.com/manual/en/zend.view.helpers.html#zend.view.helpers.custom -- Hector On Tue, Sep 8, 2009 at 11:36 AM, neobeacon neobea...@gmail.com wrote: I create a view helper to show comments for a article.(by getting article_id from comments table and using foreach to get each comment). But in comment table only has commentator's id. I used a view helper to convert user_id to get the user name. With in a view helper can I call another view helper? How do I handle this case? -- View this message in context: http://www.nabble.com/view-helpers-within-a-view-helper-tp25351769p25351769.html Sent from the Zend Framework mailing list archive at Nabble.com.
Re: [fw-general] view helpers within a view helper
=)Thanks -- View this message in context: http://www.nabble.com/view-helpers-within-a-view-helper-tp25351769p25352263.html Sent from the Zend Framework mailing list archive at Nabble.com.
Re: [fw-general] Re: unit testing front controller plugin: $front-getParam('bootstrap') returns NULL
On Sat, Sep 5, 2009 at 6:19 AM, Jens Kleikamp j...@codes-concepts.comwrote: David Mintz wrote: Playing around with Zend_Application and friends, I made a Bootstrap.php which does this: protected function _initLog() { printf (running %s:%s()\n,__CLASS__,__FUNCTION__); return new Zend_Log(new Zend_Log_Writer_Firebug()); } --- And a controller plugin: --- class Plugin_OurTestPlugin extends Zend_Controller_Plugin_Abstract { function preDispatch(Zend_Controller_Request_Abstract $request ) { $front = Zend_Controller_Front::getInstance(); $bootstrap = $front-getParam('bootstrap'); printf (\$bootstrap is a %s.\n, gettype($bootstrap)); $log = $front-getParam('bootstrap')-getResource('log'); $log-info('woo hoo, your controller plugin works'); } } --- In a browser, the printf statement outputs $bootstrap is a object and indeed it is, but when I run phpunit tests from the command line, -- forgive all the echo output, I have temporarily polluted my code with echo()s in order to determine what's executing -- Bootstrap constructor running... running Bootstrap:_initLog() we are bootstrapping the application in /opt/www/shitou/tests/ControllerTestCase.php $bootstrap is a NULL. Fatal error: Call to a member function getResource() on a non-object in /opt/www/shitou/application/plugins/OurTestPlugin.php on line 14 snip/ I stumbled across the same issue lately. The bootstrap object is assigned as a frontcontroller param in the run() method of Zend_Application_Bootstrap_Bootstrap. But this method is not executed in the test environment, only bootstrap(). I think that愀 the reason for the error you get (Fatal error: Call to a member function getResource() on a non-object...) As a workaround I set the frontcontroller param bootstrap manually within the callback method appBootstrap() of my testclasses. public function setUp() { snip... } public function appBootstrap() { $this-application-bootstrap(); // set bootstrap param $bootstrap = $this-application-getBootstrap(); $front = $bootstrap-getResource('FrontController'); $front-setParam('bootstrap', $bootstrap); } Sweet! That works. Thank you very much. btw maybe this deserves to be mentioned in the official docs. -- David Mintz http://davidmintz.org/ The subtle source is clear and bright The tributary streams flow through the darkness
[fw-general] zf tool: no way to delete yet?
Suppose you created controller foo with the cli tool but then you changed your mind. I don't suppose there's way to 'zf delete controller foo' so that .zfproject.xml will stay in sync with reality. Or is there? Meanwhile... delete it manually and don't worry about .zfproject.xml? Or... bleh... update it by hand? -- David Mintz http://davidmintz.org/ The subtle source is clear and bright The tributary streams flow through the darkness
Re: [fw-general] zf tool: no way to delete yet?
Hey David, This functionality is slated for 1.10. It was left out of the 1.8 and 1.9 release for a couple of good reasons. Since deleting is a pretty irreversible action, and sometimes is also a recursive action- we wanted to ensure that the console/cli interface at least had the capability to ask the user if deleting is OK, in other words confirming the decision to delete something. This way, people will not accidentally delete things they will not be able to recover. -ralph David Mintz wrote: Suppose you created controller foo with the cli tool but then you changed your mind. I don't suppose there's way to 'zf delete controller foo' so that .zfproject.xml will stay in sync with reality. Or is there? Meanwhile... delete it manually and don't worry about .zfproject.xml? Or... bleh... update it by hand? -- David Mintz http://davidmintz.org/ The subtle source is clear and bright The tributary streams flow through the darkness
Re: [fw-general] Debug Warning Zend Loader line 165
Ed Lazor wrote: Should I expect to see these debug warnings when debugging my ZF-based application in Zend Studio? Debug Warning: /www/lib/zend/ZendFramework-1.9.2/library/Zend/Loader.php line 165 - fopen(/www/vhosts/local.test.com/application/views/helpers/Url.php) [a href='function.fopen'function.fopen/a]: failed to open stream: No such file or directory Debug Warning: /www/lib/zend/ZendFramework-1.9.2/library/Zend/Loader.php line 165 - fopen(/www/vhosts/local.test.com/application/views/helpers/HeadLink.php) [a href='function.fopen'function.fopen/a]: failed to open stream: No such file or directory Debug Warning: /www/lib/zend/ZendFramework-1.9.2/library/Zend/Loader.php line 165 - fopen(/www/vhosts/local.test.com/application/views/helpers/Layout.php) [a href='function.fopen'function.fopen/a]: failed to open stream: No such file or directory The source code is the latest available from the ZF Quick Start guide. Zend Application is being used. This is correct behavior. The debugger in studio is throwing a warning in a situation where PHP has already suppressed the error. FYI, Zend_Loader is using the only technique available in the php 5.2 series to locate a file on the include_path. Other techniques are completely userland based and extremely slow and non-performant. Here's my main concern... A lot of debug warnings like this show up when I debug my main ZF application. As a result, I tend to ignore the debug console output. That seems like a bad habit considering that some of the warnings may need to be addressed. Plus, it seems like a smooth running application shouldn't have any warnings or errors. Thats a valid concern, although I am not seeing any way to supress the errors in studio, I think this would be better asked on the Studio forums. The second concern is that there might be some sort of overhead involved in generating these warnings. Wouldn't resolving this issue improve the overall performance of my application? As mentioned before, this is the most ideal solution for 5.2. Also, the performance cost is negligible. When 5.3 rolls around as well as ZF 2.0, there are several language level features we'll be able to leverage to remove this limitation and warnings you are seeing. I'm testing using code from the Quick Start guide to keep things simple and provide some sort of reference point. I'm hoping there's a way for me to adjust the configuration and eliminate these debug warnings. Or, at the very least, it would be nice having the confirmation that everything is configured properly - the warnings and associated overhead are expected and part of how ZF works. Everything is working fine :) But as I mentioned, you might want to pop on over to the Studio forums, this might be an opportunity to see if a filter exists, or perhaps ask for the feature request. -ralph