I have a problem configuring Josegonzalez plugin, i get an error as below
Josegonzalez/Upload.UploadBehavior could not be found.
Make sure your plugin Josegonzalez/Upload is in the C:\xampp\htdocs\sunelex\plugins\ directory and was loaded.
Error: Create the class UploadBehavior below in file: C:\xampp\htdocs\sunelex\plugins\Josegonzalez/Upload\src\Model\Behavior\UploadBehavior.php
<?php
namespace Josegonzalez\Upload\Model\Behavior;
use Cake\ORM\Behavior;
class UploadBehavior extends Behavior
{
}
I managed to get the plugin via composer into the plugins folder. I then enabled the plugin in the boostrap.php like Plugin::loadAll(); My table class behavior code looks as follows.
$this->addBehavior('Josegonzalez/Upload.Upload', [
'survey_step3_asbestos_pic' => [
'fields' => [
// if these fields or their defaults exist
// the values will be set.
'dir' => 'photo_dir', // defaults to `dir`
'size' => 'photo_size', // defaults to `size`
'type' => 'photo_type', // defaults to `type`
],
],
]);
Everything is in its place but for some reason I am getting the error above. Could you please help. Thanks.
Using cmd install below command.
composer require josegonzalez/cakephp-upload
You need to enable the plugin your config/bootstrap.php file:
<?php
Plugin::load('Josegonzalez/Upload');
If you are already using Plugin::loadAll();, then this is not necessary.
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?
Using Cake 2.x I am trying to route RESTful traffic to my Users controller to my UserManagement plugin.
My routes are as follows:
// re-redirect root traffic to login
Router::connect('/', array('plugin'=>'UserManagement','controller' => 'Users', 'action' => 'login'));
CakePlugin::routes();
Router::mapResources(['users']);
Router::parseExtensions();
I also tried:
Router::mapResources(['UserManagement']);
When I call the resful url I get the following error:
users/1.json
{
"code": 404,
"name": "Action UsersController::51() could not be found.",
"message": "Action UsersController::51() could not be found.",
"url": "\/users\/51.json"
}
Thanks in advance.
Following CakePHPs convention over configuration approach, you specify plugins like you do anywhere else, using the plugin syntax, ie prepend the plugin name and separate it with a dot from the controller name
Router::mapResources('UserManagement.Users');
This will of course also require you to use the plugin name in the request URL, ie
/user_management/users/51.json
instead of only
/users/51.json
If you'd wanted to use the latter, but still connect to the plugin, then you could try the prefix option trick, that is, supply the default value of /, which stops the router from using the plugin name as the prefix (not to be confused with actual prefix routing).
Router::mapResources('UserManagement.Users', array(
'prefix' => '/'
));
See also
Cookbook > Plugins > Using a Plugin
Cookbook > Appendencies > Glossary > Plugin Syntax
I'm working with cakephp v3 and want to install the application in two different environments, one for development and one for production use. Both installations should consist of exactly the same files (and file contents), so I could use 'git' or 'svn' to easily deploy the application.
If both environments are hosted on the same machine, I need different database settings (so that the development env uses its own 'testing' DB). I thought of configuring two 'Datasources' in app.php, the 'default' one for production and a `development'.
But how can I switch between both sources?
To be more specific: Currently I define the following environment variable in my Apache config for the development environment:
SetEnv CAKEPHP_DEBUG 1
Then I changed the definition of 'debug' in the app.php file like this:
'debug' => (bool)getenv('CAKEPHP_DEBUG'),
This enables DEBUG mode only on the development machine. Now I also want to switch database configuration in the same easy way.
(I already found some solutions for cakephp v2, but all of them are pretty old and I'm not sure what's the best way to do it in cakephp v3.)
The manual says
You can define as many connections as you want in your configuration
file. You can also define additional connections at runtime using
Cake\Datasource\ConnectionManager::config().
So I guess you can check the value of debug in AppController beforeFilter and change the default database connection
AppController.php
if(Configure::read('debug') == 1)
{
ConnectionManager::config('default', [
'className' => 'Cake\Database\Connection',
'driver' => 'Cake\Database\Driver\Mysql',
'persistent' => false,
'host' => 'dev_server',
'username' => 'dev_username',
'password' => 'dev_passwd',
'database' => 'development',
'encoding' => 'utf8',
'timezone' => 'UTC',
'cacheMetadata' => true,
]);
}
I think you can do something similar in app.php using the ternary operator
app.php
'Datasources' => [
'default' => getenv('CAKEPHP_DEBUG')== 1 ? [ /* debug params */ ] : [ /* default params */]
...
]
But somehow it don't seem the 'clean' way to do it
I think that a cleaner way would be to set both configurations in app.php and then in appController choose what configurations to use
app.php
'Datasources' => [
'debug' => [ /* debug params */ ],
'default' => [ /* default params */]
]
Table file
public static function defaultConnectionName() {
if(Configure::read('debug') == 1)
return 'debug';
return 'default';
}
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 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');
?>