Migrating from cakephp 1.3 to cakephp 2.4 - cakephp

I am migrating application code from cake 1.3 to cake 2.4. I am following cakephp migration guide.
After following the steps mentioned there I am sill unable to run my code and getting this error:
Controller class Controller could not be found.
I checked the error log in cakephp and found:
2014-06-10 18:37:56 Error: [MissingControllerException] Controller class Controller could not be found.
Exception Attributes: array (
'class' => 'Controller',
'plugin' => NULL,
)
I am trying to debug it but no results.

I have had the same issue today.
You need to have the following 2 lines in your app/Config/routes.php
CakePlugin::routes();
require CAKE . 'Config' . DS . 'routes.php';
Also, make sure you have updated the .htaccess files in /, app/, and app/webroot.

Related

Multiple prefix in cakephp 3.x

IN cakephp 2.x we can configure multiple prefixes in core.php file. like
Configure::write('Routing.prefixes', array('admin','blogger'));
But in cake php 3.X the structure of directory has been changed. There is no core.php file, So how we can configure multiple prefix in cakephp 3.x
Route prefixes get defined in the config/routes.php file in CakePHP 3 using Router::prefix(). So in your case you'd want something like this:-
Router::prefix('admin', function ($routes) {
$routes->fallbacks('DashedRoute');
});
Router::prefix('blogger', function ($routes) {
$routes->fallbacks('DashedRoute');
});
One other change you need to take into account from CakePHP 2.x to 3.x is that prefixes are mapped to sub-namespaces in your application’s Controller namespace. So for example, if you have a Pages model non-prefixed actions would go in PagesController and any actions prefixed admin would reside in Admin/PagesController.
Checkout the documentation on routes for more details.

Cakephp - Custom authentification (basicauth) in a plugin

I am currently developing an Restfull API for my website.
I decided to develop it as a plugin.
I am using a custom class that extends BasicAuthentification. It allows me to check the client-app credential, in order to limit the API use to only approved developers.
This file works perfectly when added in the CakePHP CORE : Cake/Controller/Component/Auth/DeviceAuthentification.php
Since I am developing a Plugin, I would like everything to be inside the same directory.
Therefore in my plugin directory called MyApi, I added my custom class in the following path :
MyApi/Controller/Auth/DeviceAuthentification.php
In order to load it, in my Plugin's controller MyApiAppController, I added the following code :
public $components = array(
'Auth' => array(
'authenticate' => 'Device', // I also tried MyApi.Device
'sessionKey' => false
)
);
It does not load, the error is the following :
Authentication adapter "Device" was not found.
Anybody has an idea ?
Well, after having a look in the core file AuthComponent, it seems that you need to have the following path :
MyApi/Controller/Component/Auth/DeviceAuthentification.php
instead of
MyApi/Controller/Auth/DeviceAuthentification.php
Therefore, whenever you are working in the Plugin directory, you need to add the directory Component

Drupal 7 intergrating with alfresco

Am having problems with integrating drupal and alfresco 4.2 and the cmis drupal modules.
what i have done up to now is .
1.Have a drupal 7.22 installed and running have the cmis modules installed and alfresco running in port 8000.
In the drupal settings.php i have this
$conf['cmis_repositories'] = array( 'default' => array( 'user' => 'admin', 'password' => 'nais',
'url' => 'http://localhost:8000/alfresco/service/cmis', ), );
2. On the browser tis http://127.0.0.1:8000/alfresco/service/cmis this downloads a cmis.xml file
that also contains the url within the xml file. this -> http://127.0.0.1:8000/alfresco/service/cmis
3. Moving to http://localhost/cmis/browser gives a 404 error
4 My drupal folder is called Tuna
5 Following the Readme.txt instruction to access the repository while both alfresco and drupal are
running and the module cmis is installed on the drupal by going to
http://localhost/cmis/browser or
http://localhost/Tuna/cmis/browser gives a 404 error .
6 how to i make it work and view the repository using drupal ?
7 how does the cmis view module work or does it work when the repository is able to viewed on the drupal part ?
.Please guide me am yet to be pro on drupal so a few guides and baby steps explanation would really help
localhost/cmis/browser
as you can see the above url it is assuming that you have installed in DOC_ROOT of your apache .. if you have created the drupal folder in docroot ... for example
localhost/drupal_folder
Then it doesn't work
You need to set the browser URL in cmis settings

CakePHP 2.x: Alaxos ACL Plugin- configure the admin route

i am a cakephp beginner , have not much exposure to cakephp.
I have followed installation step for Alaxos ACL plugin foe cakephp 2.0 from -alaxos site .. there second step is configuring admin routing .
that i have done by adding
Router::connect('/admin/acl', array('plugin' => 'acl', 'controller' => 'acl', 'action' => 'admin_index', 'admin' => true));
to my Cake/Routing/Router.php file and configuring app/Config/core.php: by adding following line
Configure::write('Routing.prefixes', array('admin'));
i am not sure whether this is the correct way of doing it...
On accessing the plugin http://localhost/cakeacl/admin/acl it gives error
**Private Method in AclController
Error: AclController::admin_index() cannot be accessed directly.**
Please help me ..Thanks in advance...
try to put only the following in the app/Config/core.php and remove the Router configurations.
Configure::write('Routing.prefixes', array('admin'));
Have you tried this guide http://book.cakephp.org/1.3/view/1543/Simple-Acl-controlled-Application from the official site yet?

Caching plugin and normal controllers with duplicate names

I'm running into a problem related to caching, plugins and duplicate model names in Cake 2.0. My application has several controllers containing only actions for public use (view, index and equivalents). The data is managed by a CMS which is added as a plugin, some names of the plugin's controller are the same.
For example, I have a PostsController in my application and a PostsController for the plugin. The plugin controller extends PluginAppController and the public controller extends AppController as per the manual. As soon as caching is kicked in (by setting debug to 0) the problems start. Cake tries to access a non-existing add action in the controller which extends AppController and the public application tries to access methods from the PluginAppController.
I don't understand why Cake would do this and it creates all kinds of errors (blank pages, lost sessions) which aren't logged properly as well. Everything was working well while the app still ran on Cake 1.3 and also in 2.0 production mode.
The file cake_core_file_map in the /tmp/cache/persistent/ directory seems to be causing the issue. As soon as I remove this and reload either of the views, it renders correctly. So the procedure is as follows:
Load http://www.example.com/admin/posts successfully;
Load http://www.example.com/posts (it fails to render);
Clear the cache (or just cake_core_file_map);
Load http://www.example.com/posts successfully;
Load http://www.example.com/admin/posts (which now fails to load properly).
My guess is Cake fails to save the correct references to the plugin and main application paths in cake_core_file_map, but I have no clue how to force Cake to behave nicely in that regard.
Does anybody know how to stop Cake from confusing the plugin's controllers with the other ones with duplicate names?
EDIT
This issue might be related to a bug in Cake, as this report mentions similar problems and cake_core_file_map as well. The fix mentioned here doesn't work unfortunately.
EDIT 2
There is indeed some custom routing going on, which was working normally in Cake 1.3. This is from routes.php:
Router::connect('/plugin_name', array('plugin' => 'plugin_name', 'controller' => 'users', 'action' => 'login'));
Router::connect('/admin/*', array('plugin' => 'plugin_name', 'controller' => 'posts', 'action' => 'index'));
May be it would be helpfull to override Cake' standard cache file names for Plugin to make Cache engine keep it separately.
In main bootstrap file while loading plugin:
CakePlugin::loadAll(array('Plugin' => array('bootstrap' => true));
In Plugin direcrory
/app/Plugin/Plugin/Config/bootstrap.php
<?php
Cache::config('_cake_core_', array(
'engine' => 'File',
'prefix' => 'cake_core_plugin_',
'path' => CACHE . 'persistent' . DS,
'serialize' => true,
'duration' => '+999 days',
));
?>
Are there conflicting routes between the main app and the plugin? This sounds like you may need to create a route for your /posts and another for /admin/posts in your main app. This should override the routes from the plugin causing any conflict. Of course, clear your cache before trying the change.
//main app posts route
Router::connect(
'/posts',
array(
'controller' => 'Posts'
'action' => 'index'
)
);
//plugin posts route
Router::connect(
'/admin/posts',
array(
'controller' => 'Posts'
'action' => 'index',
'plugin' => 'CmsPlugin'
)
);
This turns out to be a known issue (which doesn't make it less annoying) and will only be fixed in a next major release, as per this Cake bug report.
PHP 5.2 doesn't have namespace support which is apparently needed for Cake to support duplicate classnames. PHP 5.3 has namespace support and Cake 3.0 will require that version.

Resources