Skip to main content

Posts

Showing posts with the label Cakephp Library

How to make library in cakephp

1. Make a class in lib folder and Save it url_encoder.php <?php class UrlEncoder {        public static function encode($url) {                   return preg_replace(array('/\+/', '/\//'), array('-', '_'), base64_encode($url));         }  public static function decode($url_encoded) {                  return base64_decode(preg_replace(array('/-/', '/_/'), array('+', '/'), $url_encoded));         } } ?> 2. Now implement in your controller , if you want to initialize lib initially then define it in before filter function function beforeFilter() {        parent::beforeFilter();       App::import('Lib', 'UrlEncoder'); } 3. Now how to use its function UrlEncoder::encode($contact_id); UrlEncoder::decode($contact_id) ;