Use model inside helper class cakephp
Posted on February 23, 2010

Hello All,

Finally after researching for hours we got the solution to call a model inside a helper class. we hope this helps you.

In a method of your helper class just use : $this->ModelName=& ClassRegistry::init(’ModelName’);

And now $this->ModelName has all the property of the model.

Do let us know if you are unable to use the same.

Happy Algo-blogging.

Cakephp lightbox, cakephp modalbox
Posted on July 13, 2009

Hello friends getting lightbox/modalbox in to the application is really an addon to the site.

Here are few simple steps to get  lightbox/modalbox working on your cakephp site.

  1. Download ModalBox (you also need a prototype + script.aculo.us files there.) extract them all and place the files in webroot folder. (files you should see after extraction are “js/cakemodalbox.js” , “js/modalbox.js”, “css/modalbox.css”, “css/spinner.gif”).
  2. Include  4 javascripts i.e prototype.js, scriptaculos.js, modalbox.js and cakemodalbox.js in your default template file in the same order mentioned here. (Note for cakemodalbox.js coming below modalbox.js)
  3. In your controller include 2 lines of code
    1. var $components = array(’RequestHandler’);   // note for ‘RequestHandler’
    2. var $helpers    = array(’Html’,'Javascript’, ’Ajax’);
  4. There are no changes in model specifically.
  5. Now for example you want to show a view file say your login page with lightbox then just follow the simple steps.
    1. Include var $components = array(’RequestHandler’); and var $helpers    = array(’Html’,'Javascript’, ’Ajax’); in your controller. In my case it is user controller.
    2. Now for example you want to show a view file say your login page with lightbox then just follow the simple steps.echo $html->link(’Login’,array(’action’ => ‘ControllerName/login‘),array(’title’ => ‘Customer details’,'onclick’ => “Modalbox.show(this.href, {title: this.title, width: 400}); return false;”));
  6. change the ‘ControllerName’ as per your need.

    Likeways you can show any page in a light box or modalbox.

    Do let us know in case of any issue.

    Algoworks