CodeIgniter Forums
Cart library: how to extend library class regex validation without messing with the core? - Printable Version

+- CodeIgniter Forums (https://forum.codeigniter.com)
+-- Forum: Archived Discussions (https://forum.codeigniter.com/forumdisplay.php?fid=20)
+--- Forum: Archived Development & Programming (https://forum.codeigniter.com/forumdisplay.php?fid=23)
+--- Thread: Cart library: how to extend library class regex validation without messing with the core? (/showthread.php?tid=23457)



Cart library: how to extend library class regex validation without messing with the core? - El Forum - 10-12-2009

[eluser]moonbeetle[/eluser]
Cart.php, line 31
Code:
var $product_name_rules    = '\.\:\-_ a-z0-9'; // alpha-numeric, dashes, underscores, colons or periods

While the pattern above will be valid in 99% of the cases I need to add a few allowed characters like a ? and a !
(building a shopping cart for book titles where some have a question or exclamation mark at the end)

Of course I can add those extra characters to the array. But this would mean that when I upgrade to a newer version of CI, I must keep track of such changes. Is there a better way in this case?


Cart library: how to extend library class regex validation without messing with the core? - El Forum - 10-12-2009

[eluser]Pascal Kriete[/eluser]
It's a public variable - so you can change it to anything you want.
Code:
$this->load->library('cart');
$this->cart->product_name_rules = 'ponies';

Or you could [url=http://ellislab.com/codeigniter/user-guide/general/core_classes.html]extend the library[/code] and just set it in there, which will then be in effect globally.