0
votes

I am working on a CakePHP project that sometimes needs to load the Javascript and CSS for the jQuery Datepicker.

I only want it to load when needed, and I want one central loading point because there are several files involved, and if something changes, I, of course, don't want to go back and change it in all the places the datepicker files were loaded.

Right now, I've created an element called 'load_datepicker'. The only code in this file is the CakePHP calls to load the necessary files. I could not find any other solution.

This -seems- to be a good solution. I can load an element into any view or other elements.

Is this a reasonable way to approach this need or is there some specific CakePHP way to do this?

lee

2

2 Answers

0
votes

Another option is to include the javascript and css in your layout file, but surround it in an if block. Then in your controller actions, you can set a variable on the pages where you need the datepicker, and check for it in the if block.

0
votes

Completely fine and a good solution for your needs.