What's the best way to use CakePHP to control the Expires headers for image and CSS files?
My host unfortunately doesn't support mod_expires or mod_headers, so I can't simply set these values in an .htaccess file. Right now there's no cache control for my files and a lot of unnecessary requests are made.
What's the most elegant way to pipe requests for asset files through Cake and set the appropriate headers via header()?
I guess the best, not even necessarily Cake-specific way, is to create a script in /webroot that adds the headers, then use .htaccess directives to pipe requests for ./css/* and ./img/* through that file. I was just hoping there might be some functionality like this built into Cake already. :)
I would suggest writing a helper which takes the filename and then returns a URL to a PHP script which fetches the file and adds the necessary header. You can see an example of a basic helper here: http://bakery.cakephp.org/articles/view/image-resize-helper
Related
Click here to see a picture of what I mean
I haven't tried anything yet because I'm not sure how to even approach this problem. I'm not even sure what to Google. I do, however, have a pretty good handle on React. Thanks!
Update: The folders will not be storing files, just hyperlinks.
You need to model the problem space first. i.e. models for folders, and files. Each having properties (name, etc.) and associations (folders can have many files and subfolders).
To store the physical files you can use a third-party service like Amazon S3.
This would get you started at least.
I am trying to use the Configure class in CakePHP, but I'm not sure if I am using it correctly. I have read through the cook book and the API, but I can't seem to do what I want.
I have created a configuration file: app/config/config.php. I can directly edit this file and set variables in there and access them using Configure::read().
Is it possible to update the values of the configuration file from the application itself, i.e., from a controller? I have tried using Configure::write(), but this does not seem to change the value.
app/config/config.php isn't a file that's automatically loaded by Cake. Either move these variables into app/config/bootstrap.php or tell your bootstrap.php file to load your custom file. You could also put your variables in app/config/core.php, but I'd recommend against that. I tend to like leaving that file alone and adding/overwriting values in bootstrap.php.
According to the API, Configure is supposed to be used "for managing runtime configuration information".
You can use its methods to create, read, update and delete (CRUD) configuration variables at runtime. The Configure class is available everywhere in your CakePHP application and therefore CRUD operations performed on its data in any place, including a controller.
If you are looking for persistent storage, you could consider a database (SQL or NoSQL). I would not recommend using a text file, as it raises a lot of security concerns. Even if security is not an issue, a database is propably a more fitting solution.
More on the Configure class in the Cookbook.
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.
I've created a dotnetnuke. I have two files named index.ascx and index.html that as you know index.ascx is made after the parsing of DNN.
Question: Do I still need the index.html after the skin is parsed by dotnetnuke?
You do not need the .html file on the webserver, it is not used for anything after the skin has been converted to .ascx.
You probably want to keep it on your local machine however. It depends on how you plan to implement any changes to your skin. If you want to change the .ascx directly then you don't need the .html any more. If you want to make changes in the .html and then regenerate the .ascx, yes of course you still need it.
Personally I always create skins in .ascx straight away and skip the .html step - then you don't have to worry about the converter getting it wrong.
you do not need the html unless you intend to access the file on your server and edit it. Once you edited the html file, you can then parse the skin again to reproduce the ASCX. other than that it serves no purpose sitting on the server
.HTML files usually aids a skin designer. You can keep it local and open it on normal browser to get the idea of the layout. On other hand .ascx file is everything
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