OK, after weeks of cruising the Yii web sites I have finally figured out that a helper class should be put in the compnents directory. Now I have a function that I want to write that will require a .js file.
Where do I put the clientScript() call? Do I out it in the function()? init()? etc… My function is to ‘encode’ an email address and I don’t want to ‘register’ the javascript everytime I call this function, but I am just not sure how to handle the registration.
I looked at the extensions, but they were all extensions of CWidget. I am looking at a helper file like CHtml to put my generic code. For example I have a .js for obscuring an email address from robots. I need to generate a span tag that calls the javascript. That part is easy. Insuring that the script tag to include the .js file as needed happens automatically is where I am getting lost.
I have the all of this code working. smtp2() is a JavaScript function in a .js file that replaces this text with a mailto: link.
My question is: In a static class (link CHtml) where/how do I register the script? I have it in genEmailLink() but that registers the script EVERY time I call the function. What if I have a contact page that has 30 email links? This call to registerXXX() will be called 30 times.
I guess I was looking at not having to create instances all over the place. CWidget doesn’t seem right, but the App component might work with an init() function. Any help to creating an app component?