Cakephp -Minify 400 Bad request -


i working on cakephp 2.3.. worked minify using plugin

https://github.com/maurymmarques/minify-cakephp

but not able seem worked .. website not correctly loading css , js ..

i copied folder app/plugins directory , importing css , js in default.php file in layouts folder doing

echo $this->minify->css(array('reset', 'style','colors')); 

and in browser url becomes

<link rel="stylesheet" type="text/css" href="/cakephp/min-css?f=cakephp/css/reset.css,cakephp/css/style.css,cakephp/css/colors.css 

when click url error

  400 bad request   please see http://code.google.com/p/minify/wiki/debugging. 

i calling helper in appcontroller

 class appcontroller extends controller {  public $helpers = array('minify.minify'); 

i've tried setup similar yours, ie cakephp 2.3 in subfolder, , setup 400 error (including error messages in firephp!).

after digging through sources found 2 culprits, 1 being asset::getassetfile() in minify/utility/routing/asset.php, proper webroot path assets generated, , asset urls being "converted" asset file paths. these values used in minifiers config file (minify/vendor/minify/config.php) overwrite values passed in f url variable , overwrite $_server['document_root'] variable, later on used minifier locate asset file. problem here theme , plugin assets converts paths folder separator / ds, led \ being used on windows systems, causing minifier fail because doesn't allow backslashes. fix that, exchange implode(ds, $parts) implode('/', $parts).

https://gist.github.com/ndm2/6192506

another problem method can handle assets 1 location, ie either normal assets, plugin assets, or theme assets. more of feature limitation rather bug.

the other culprit minify helper. when cakephp located in , accessed via subfolder path, subfolder path prepended asset urls generated html helper being utilized in minify helper. problem in minifier $_server['document_root'] path directly concatenated asset file path (both being prepared asset::getassetfile() mentioned before), resulting in file paths /cakephp/app/webroot/cakephp/css/style.css, /cakephp/app/webroot/ webroot file path, , cakephp/css/style.css asset file path (where in fact it's still url fragment), , of course these files not exist. quick , maybe dirty fix 1 exchange

array_push($files, substr($this->asseturl($asset, $options), 1)); 

for

array_push($files, mb_substr($this->asseturl($asset, $options), mb_strlen($this->request->webroot))); 

in minifyhelper::_path() method located in minify/view/helper/minifyhelper.php. strip subfolder part paths, resulting in correct file paths being generated

https://gist.github.com/ndm2/6192504

please have in mind both of these possible fixes need testing make sure there no side effects!

now if don't use windows system and/or not use theme and/or plugin assets, can ditch first fix, , go on subfolder problem. mentioned possible fix needs further testing, if unsure that, solution move cakephp installation out of /cakephp/ subfolder document root (or change document root subfolder cakephp installation located in case applicable).

now long write, hope i've found same problem experiencing. on side note, might worth reporting issues plugin developer anyways.


Comments

Popular posts from this blog

image - ClassNotFoundException when add a prebuilt apk into system.img in android -

I need to import mysql 5.1 to 5.5? -

Java, Hibernate, MySQL - store UTC date-time -