and (being a yii newbie) I wonder what would be the right way to use it. I could set and “id” for textarea and then hook it up to jQuery. However, I don’t know how to include this jQuery plugin and where to place the “hook” code.
I assume I could put the jquery.charcounter.js in “assets” directory, but I don’t know how to tell Yii to load it. I could place <script> tag in view manually, but something tells me there’s a “yii-way” to do it.
The other thing I don’t know is where to place jQuery code, you know, the document-ready and all the stuff inside. I could do it in view file, but somehow I feel there’s more to it with Yii. Of course, the coolest thing would be just to be able to say “create a textarea with 250 character limit imposed by jQuery” but I don’t see anything like that in Yii? Is there maybe some extension that does this already?
you can put it in your controller or layout/views. You should put it where it best works for your application. (I would recommend putting it in your layout/views). you can put your js file wherever is accessible through your web browser. for organizational purposes i create a folder under assets called js. It’s not recommended that you add to core directories or modify the core unless you really need to. The name of the directory of scripts for core js functionality is produced by this method from CAssetManager
protected function hash($path)
. You do not need to use that mechanism for scripts that you add. you can look into framework/web/CAssetManager for some info.
Guys, you are giving me contradictory advises. Why is it not recommended to put manually in assets? I’d like to learn what’s the benefit of publishing?
Also, placing in "protected/js" means I have to create "js" there. If I decide to do that, what is the "path/to/script"? Is it "protected/js/jquery.charcounter.js". One thing I find lacking in Yii documentation is lack of preciseness. In many functions, argument is $path, without saying what is this path relative to, web url, application url, yii folder url? Should one use absolute or relative path?
Is there really no convention or best-practice here? I fear what will happen if more developers join me and start adding stuff all around the place. Does this mean my development team needs to setup some conventions first, before using Yii as a framework?
P.S. Spyros, some of the issues I raised are obviously not your fault, but I hope some of Yii developers are reading this forum.
Some framework components require images and CSS/JS files to be publicly accessible. Since the framework code is not accessible from web (and doesn’t even have to be located in your webfolder), these files need to be “published” before. That’s what the assets folder is for. But it is solely managed by CAssetManager. You shouldn’t put files manually in there. And you can even delete it’s content - it will be automatically regenerated.
Same is of course true for your own components. You might want to reuse them in different applications and keep their code + images + js + css on one place. So you can publish the required assets from your component code and users will be able to "see" them.
Hey guys, know the post is a bit old but I need hel p implementing this lol. Im a complete noob when it comes to this, id never even looked at php till a week ago and im trying to learn how to use that and Yii together.
My question is how do I get this to work, im trying to limit the textarea to 5 characters as a test yet it wont work with what I have above. Any help would be greatly appreciated,my next step is to bang my head off a wall ha!. Cheers
Cheers again Tommy but I seem to be getting an error, im sure its something to do with the syntax however for the life of me I cant seem to find it, I keep getting Unexpected String error. Maybe I need a new set of eyes or a lot of coffee haha.