You need to call getArguments() instead. It returns an associative array where you can do the lookup.
Sorry for the confusion, - David On 14.07.2009, at 18:12, [email protected] wrote:
Hi David, I did as you suggested below, but the calls to $this->getArgument('max') and $this->getArgument('min') are both returning the same result. I can't understand why. The validator seems to be set up correctly. Here's the code: <validator class="PriceRangeCustomValidator"> <arguments> <argument name="max">VehicleSalePriceMax</argument> <argument name="min">VehicleSalePriceMin</argument> </arguments> <errors> <error for="max_min_mismatch">ERROR: Vehicle maximum price is lower than vehicle minimum price</error> </errors> <ae:parameters> <ae:parameter name="required">true</ae:parameter> </ae:parameters> </validator> <?php class PriceRangeCustomValidator extends AgaviValidator { protected function validate() { $max = $this->getData($this->getArgument('max')); $min = $this->getData($this->getArgument('min')); echo $this->getArgument('min'); echo $this->getArgument('max'); die; if ($min > $max) { $this->throwError('max_min_mismatch'); return false; } return true; } } ?> output: VehicleSalePriceMaxVehicleSalePriceMax Any ideas why this might be happening? Incidentally, if I switch the order of the arguments in the XML file, the output changes to VehicleSalePriceMinVehicleSalePriceMin VikramYes, there is a better way :) Validators support named arguments. Do this in your code: $max = $this->getData($this->getArgument('max')); $min = $this->getData($this->getArgument('min')); And in the XML: <validator class="PriceRangeCustomValidator"> <argument name="max">pmax</argument> <argument name="min">pmin</argument> </validator> Cheers, David On 06.07.2009, at 15:00, Simon Cornelius P Umacob wrote:Hi, I'm a bit tipsy right now. Just correct me in case I suggest a wrong advice. =) $max = $this->getData($this->getParameter('max')); $min = $this->getData($this->getParameter('min')); In your XML file, do: <validator class="PriceRangeCustomValidator"> <argument>pmax</argument> <argument>pmin</argument> <ae:parameter name="max">pmax</ ae:parameter> <ae:parameter name="min">pmin</ ae:parameter> </validator> Regards, [ simon.cpu ] On Mon, Jul 6, 2009 at 8:39 PM, <[email protected]> wrote:Hi I have the following custom validator: <?php class PriceRangeCustomValidator extends AgaviValidator { protected function validate() { $max = $this->getData('VehicleSalePriceMax'); $min = $this->getData('VehicleSalePriceMin'); if ($min > $max) { $this->throwError('max_min_mismatch'); return false; } return true; } } ?> I'd like to reuse this in another form, where the two inputs are named pmin and pmax. Is there a way for me to do this - maybe by editing the above code to use generic input arguments instead of named form inputs? Thanks Vikram _______________________________________________ users mailing list [email protected] http://lists.agavi.org/mailman/listinfo/users_______________________________________________ users mailing list [email protected] http://lists.agavi.org/mailman/listinfo/users-------------- next part -------------- A non-text attachment was scrubbed... Name: smime.p7s Type: application/pkcs7-signature Size: 2474 bytes Desc: not available Url : http://lists.agavi.org/pipermail/users/attachments/20090706/02a2cd12/attachment-0001.bin ------------------------------ _______________________________________________ users mailing list [email protected] http://lists.agavi.org/mailman/listinfo/users End of users Digest, Vol 33, Issue 5 ************************************_______________________________________________ users mailing list [email protected] http://lists.agavi.org/mailman/listinfo/users
smime.p7s
Description: S/MIME cryptographic signature
_______________________________________________ users mailing list [email protected] http://lists.agavi.org/mailman/listinfo/users
