I'm having troubles to compress my Javascript files using Asset Compress Plugin for CakePHP 2.X. I'm currently using CakePHP 2.2.2 over IIS 7.
It tries to add the compressed js file but it doesn't exist:
<script type="text/javascript" src="/cakephp/cache_js/jquery-combined.v1379067166.js">
I have downloaded and placed the plugin under app/Plugin/AssetCompress/
I have dowloaded YUI build tool and placed the file contained in lib/yuicompressor/yuicompressor-2.4.2 in vendors/yuicompressor/
I have made the folder webroot/cache_js/ writable.
This is my asset_compress.ini:
[General]
cacheConfig = false
[js]
timestamp = true
path = WEBROOT/js/*
cachePath = WEBROOT/cache_js/
filters[] = YuiJs
[jquery-combined.js]
files[] = jquery.tipsy.js
files[] = web.js
And I am adding the plugin in bootstrap like this with debug mode set to 0:
Configure::write('Dispatcher.filters', array(
'AssetDispatcher',
'CacheDispatcher'
));
CakePlugin::load('AssetCompress', array('bootstrap' => true));
Also, I'm loading it from the AppController:
var $helpers = array('AssetCompress.AssetCompress');
And using it on the layout template in this way:
echo $this->AssetCompress->script('jquery-combined');
The only error I'm getting on the error.log is the following one:
2013-09-13 14:16:10 Error: [MissingControllerException] Controller
class CacheJsController could not be found.
C:\inetpub\wwwroot\cakephp\app\webroot\index.php(92): Dispatcher-> dispatch(Object(CakeRequest), Object(CakeResponse))
C:\inetpub\wwwroot\cakephp\index.php(42): require('C:\inetpub\wwwr...')
{main}
Any clue about what can be happening?
Should I have Java SDK installed ? Am I picking the wrong .jar file from YUI?
Thanks.
Before you can set debug = 0 you need to use the CLI tool to build static versions of the assets. I'm pretty sure this is in the documentation.
Related
Pardon me as this is my first questions.
I tried to install a plugin for haml in cakephp 3 manually, and found this k-motoyan/cake-haml
I can't install it using composer because I use cakephp 3.3.*
k-motoyan/cake-haml dev-master requires cakephp/cakephp 3.0.*-dev ->
no matching package found.
So, I tried to install it manually, downloading the zip and put it in [app]/plugins/kmotoyan/cakephp
I follow the readme setup
Setup
Add plugin load line to config/bootstrap.php file:
diff
+ Plugin::load('CakeHaml', ['bootstrap' => true]);
Set the default ViewClass on the src/Controller/AppController.php
file:
```diff class AppController extends Controller {
public $viewClass = 'CakeHaml\View\CakeHamlView'; ```
You can use haml on all your view files with .haml extension.
and put this code below in my config/bootstrap.php
Plugin::load('kmotoyan/CakeHaml', ['bootstrap' => true]);
and this code below in my src/Controller/AppController.php
public $viewClass = 'CakeHaml\\View\\CakeHamlView';
when I load the server, i get this error
Error: Class 'CakeHaml\View\CakeHamlView' not found File
C:\xampp\htdocs\qolega\vendor\cakephp\cakephp\src\View\ViewBuilder.php
Line: 363
when I see line 363 there's this line
return new $className($request, $response, $events, $data);
what should I do?
I am unable to use Composer and thus have to install CakePDF plugin manually, but following examples from official CakePHP documentation does not seem to work.
So here is installation flow that I have followed:
1.) Copied the plugin to app/plugins/CakePdf
2.) Updated the app's composer.json file, like following:
"autoload": {
"psr-4": {
"CakePdf\\": "./plugins/CakePdf/src",
"CakePdf\\Test\\": "./plugins/CakePdf/tests"
}
},
"autoload-dev": {
"psr-4": {
"App\\Test\\": "tests",
"Cake\\Test\\": "./vendor/cakephp/cakephp/tests"
"CakePdf\\": "./plugins/CakePdf/src",
"CakePdf\\Test\\": "./plugins/CakePdf/tests"
}
}
3.) Loaded the plugin in bootstrap.php:
Plugin::load('CakePdf', ['bootstrap' => true, 'routes' => true, 'autoload' => true]);
4.) Added router extensions:
Router::extensions(['pdf']);
5.) Tried a very simple sample from plugin's doc:
$cakePdf = new CakePdf(array(
'engine' => 'CakePdf.DomPdf',
'pageSize' => 'A4',
'orientation' => 'portrait'
));
$html = '<html><head><body><p>Pdftest</p></body></head></html>';
$rawPdf = $CakePdf->output($html);
However the code breaks at the first line and the following error message is provided:
Class 'App\Controller\CakePdf' not found
I would really appreciate any help or guidance for how a plugin should be installed manually.
If there is any other information that I need to provide, just ask.
You are getting this error because inside vendor/composer/ you can see some autoload_*.php files. These files hold the paths to load your classes. I think no one can safely tell you what to update and where in these files.
So you have two solutions:
1 - Copy composer.json on a local machine and run composer update. Then move the files created inside your app. I would suggest to take a backup before. Most probably the things that you will have to move are:
vendor/
composer.json
composer.lock
2 - Start updating the files inside vendor/composer/autoload_*.php with the paths from the plugin. Most probably you will only need to update the following two files:
vendor/cakephp-plugins.php and vendor/composer/autoload_psr4.php. Personally I wouldn't choose the second solution I am just adding it as an alternative just in case.
I have read many docs, but failed to solve the problem:
Images in my existing project stored in $_SERVER['DOCUMENT_ROOT'].'/media/'
I want, but can't change in cakephp 2.4 default image folder from $_SERVER['DOCUMENT_ROOT'].'/app/webroot/img/' to any I desire.
lib/Cake/bootstrap.php contains constants:
/**
* Path to the public images directory.
*/
if (!defined('IMAGES')) {
define('IMAGES', WWW_ROOT . 'img' . DS);
}
/**
* Web path to the public images directory.
*/
if (!defined('IMAGES_URL')) {
define('IMAGES_URL', 'img/');
}
and
Configure::write('App.imageBaseUrl', IMAGES_URL);
I tried to change:
IMAGES to $_SERVER['DOCUMENT_ROOT'].'/media/'
IMAGES_URL to /
And it doesn't work at all. All image files still points to $_SERVER['DOCUMENT_ROOT'].'/app/webroot/img/' I see it when try to render image in view:
echo $this->Html->image('/img/ride_scheme/chema.jpg', array( 'width' => 300 ));
If I created in app/webroot/img/ride_scheme image file chema.jpg it rendered, but I changed the folder in IMAGES constant in lib/Cake/bootstrap.php !!!
In documentation I see:
Constants IMAGES_URL, JS_URL, CSS_URL have been deprecated and
replaced with config vari- ables App.imageBaseUrl, App.jsBaseUrl,
App.cssBaseUrl respectively.
Constants IMAGES, JS, CSS have been deprecated.
I gues that is the problem.
Please, show me how to change image folder
According to your description, I reckon IMAGES_URL should be media/ and not just /.
Alternatively, you could add a RewriteRule to your .htaccess (in the project root) to rewrite everything to the media folder (assuming you have an Apache web server with the Rewrite module enabled):
RewriteRule ^app/webroot/img/(.*) /media/$1
Or you could create a symbolic link that links the img/ folder to your media folder (assuming you're on Linux hosting and you have ssh/shell access to your server):
cd app/webroot
rm -rf img/
ln -s ../../media img
I'm using AssetCompress v0.5 from the 1.3 branch and the dynamic built is not working. I've done the following so far:
Downloaded and copied the asset_compress folder into my app/plugins folder
Copied the config.ini and renamed it to app/config/asset_compress.ini
Created 2 CSS and JS bundles named public and logged (so 4 in total)
Added AssetCompress.AssetCompress in my $helpers array in my AppController
Changed my default.ctp layout file to: echo $this->AssetCompress->css('public'); echo $this->AssetCompress->css('logged'); (same for ->script())
The output error is:
Error: The requested address '/asset_compress/assets/get/public.css' was not found on this server.
What am I missing?
Ok, I figured it out.
It was because I was using the CssMin filter and I did not download it and put it into the vendor folder. As the plugin seems to be turning the debug level to 0, I did not see the error, until I put a Configure::write('debug', 2); into the beforeFilter().
I am trying to use the Media Plugin (http://www.ohloh.net/p/cakephp-media)
I placed the media folder contents in app/plugins/media
then in bootstrap.php in the app/config/ folder added the following code.
Configure::load('media.core');
Now when i run any controller and any action am getting the following error.
Configure::load() - no variable $config found in core.php [CORE\cake\libs\configure.php, line 266]
I am using Cakephp 1.3.7
loading config files with cakes Configure::load() has a requirement that the configs be in a variable called $config
eg
<?php
$config['Meh'] = array('foo' => 'bar');
?>