Cakephp: Include php script in .ctp file - cakephp

I want to add captcha in myfile.ctp. For this i found source for captcha along with some resource files includs(js, php).
I know the folder for js files & include this file using <?php echo $javascript->link(array('ajax_captcha.js'));?>. But I don't know where to place .php file &
also how to include it in myfile.ctp
Or if anybody help me to implement Captcha in Cakephp.

For your js, use $javascript->link('ajax_captcha',false); Not the omission of the extension. false will place it in the section of the HTML. This will look for the script in webroot/js
Personally, I would just use a standard php include directive for the php side of things, bearing in mind that the location will be relative to webroot, i.e. '/myPHP/captcha.php'will be webroot/myPHP/captcha.php.
Don't forget, CakePHP is PHP.

I'd use a plugin or component, http://bakery.cakephp.org/articles/view/captcha-component-with-phpcaptcha
This works very well with PHPCaptcha for all your Human vs Computer shenanigans. Feel free to google around for your preferred plugin/component.

There is another article in the bakery - Integrate CakePHP with Kcaptcha (read the comments there too). I have successfully implemented kcaptcha in my application.

Elements are a good way to pull code that gets sprinkled over and over around various views:
http://book.cakephp.org/2.0/en/views.html#elements

Related

Is cakephp support file upload without plugin?

As the title, is cakephp support file upload without uses of plugin or not ?
**I means any code that made by cakephp developers not include pure php code.
Not really, for a full implementation you will need a plugin or create your own logic. Cake does offer convenience methods based on the base PHP functions. The File & Folder utility is an example.
You can use component instead of plugin like this one and it should do the job, but I'm not sure is this what you are looking for.
OK, Cakephp is support file upload, I just have to set the name of form to use it.

CakePHP 2.2.2 Asset Compress CssMinFilter Comments Issue

I am using JsMinFilter & CssMinFilter to compress all my CSS and JS files into one output file. This works fine for both, however the JS filter that I found a modified copy of somewhere, lets you keep important comments, e.g. copyright notices.
I know that there is a filter option for the CssMinFilter that can set the RemoveComments to false. However I can't seem to find any information about where I set that option when I am using this with CakePHP (ver 2.2.2), any one know where? Do I put it in my AppController or is it another config file I have to make for it?
Also I do have access to SASS and I know that there should be a filter for the Asset Compress to use to build my SASS files into css and then output as one file again. The Wiki on the plugin page for the Asset Compress is not detailed about where I can get this or how to plug it into my site, like the CssMinFilter?
Many Thanks
Glenn.
OK got a answer to some of it! Still do not know about how to important a SASS filter into CakePHP, so I will keep looking at that.
I have now moved to the YUI Compressor to do my CSS, which keeps all '!' marked comments within the file.
I also know that you can use this for the JavaScript, however when I do, it processes 6 errors when you add the Jquery and Jquery UI to the build, so for now I am still using the JsMinFilter.
I will repost a new question about eh YUI Compressor issue with my Jquery build.
Many Thanks
Glenn.

cakephp disable routing for specific URLs

I have a CakePHP 1.3.10 app which I'm trying to make it do the following:
I want to embed a mp3 file in some views, using Google's reader flash audio player. If I put the mp3 file in the webroot directory of my app, there's no problem. However, I would like to have those files in a directory called AUDIO at the same level of my app directory. Like:
[public_html]
[app]
[cake]
[AUDIO]
...
The problem is that if I put my mp3 files there, when I link to them from my view, Cake looks for the controller audio, which doesn't exist, instead of just linking my file. I believe this has something to do with routing, so I was wondering if I can disable automatic routing for a specific folder (**audio in this case).
I want to do this in this way because in the future I might have to access those mp3 from other websites, so I don't want to put them deep into cake's directory system.
Thanks so much in advance for any tips!
Files that should be directly served by the web server without going through Cake should be put in the /app/webroot directory. You can create such a /webroot directory in plugins as well (see here), which technically will use routing, but behaves the same as the general webroot directory.
If you place them anywhere else you're going against Cake conventions, which I wouldn't recommend. Not because it's not possible, you're just making your life harder than it needs to be. You can edit the /app/webroot/.htaccess file to rewrite certain URLs to wherever you stored your files or use Media Views (as pointed out by #Ivo) if you really want to do this.
CakePHP won't be able to automatically find files in folders that it doesn't know about.
I'd suggest using Media Views to serve files from a custom directory.
If you want them to be freely downloadable, you can do this using MediaView also, or put them in a custom folder inside webroot. You'll need to include that folder in paths etc, though.

CakePHP include external php file in plugin

I'm making a main app in CakePHP 1.3.10 that has a couple of plugins. In one of them, I need to use a very big array ($array_test) populated "manually".
The way I have it now (which works perfectly) is that I declare the array in the controller of the plugin that I want to use it in (plugin1_home_controller.php for example), doing something like var $array_test = array(1,2,3,4,5...), and I can access it perfectly from the views in that controller.
The thing is that I would prefer having the array declared somewhere else in the plugin, since it's too big, and then load it when I need it.
So I'm trying to create a array_test.php file with the array declared in it, put in /app/plugins/plugin1/webroot/php/array_test.php, and then load it from the view using include "/php/array_test.php" (I also tried include "/plugin1/php/array_test.php" as the CakeBook says in the plugins assets section), but none of them work.
How can I get the right path? Or is there any good alternative to what I want to do? Thank you so much in advance!
If your plugin is in the app's directory use:
APP_PATH.'plugins'.DS.'plugin1'.DS.'webroot'.DS.'php'.DS.'array_test.php'
If your plugin is installed in the common cake directory:
CORE_PATH.'plugins'.DS.'plugin1'.DS.'webroot'.DS.'php'.DS.'array_test.php'

Why there is a field named "language" in the CakePHP's config file

Well, I was going through an application where a find a variable named as "language" in the config file of the Cake application.Then I also found the same thing in the Bootstrap,where it called the same thing from config file.Could anyone explain me what does this thing do from the config file.Is there any rule Globalization behind this...???
please explain...!!!
The documents explain it pretty well:
http://book.cakephp.org/view/162/Internationalizing-Your-Application
You basically setup your language files, then the configuration setting in the core.php file decides which language you are going to display.
The neat thing about Cake Localization is that all you have to do is wrap all of your content in __('') which will automatically localize your content.

Resources