Hi All,
I’ve started to study 3.x version. I use 2.x version few years and keep some buisness logick in my classes in Lib folder.
Where is Lib folder in 3.x version, where I have to keep my classes in Cake way?
Thank you.
I would worry about “cake way” as long as it’s modern php way. I have my own helpers folder and a Service Folder with special classes for certain things. The key is make sure anything is properly namespaced.
I built my own cakephp plugin - “Commons” and package that up as a composer library on an internal git server.
I can then use the plugin in other projects by adding it as a dependency in composer.json
jimgwhit > Could you show me example? (Folder place and NameSpace)
A Helper folder for example:
cake40up\src\Helpers
<?php
namespace App\Helpers;
use Cake\Network\Session;
// other use statements as needed
class SomeClass
{
// rest of class
Cake provides the App
namespace per default:
// composer.json
"psr-4": {
"App\\": "src/"
}
So if you want to use that and add an Lib
directory to src
// src/Lib/MyClass.php
namespace App\Lib;
class MyClass { ...
Use your class somewhere else:
use App\Lib\MyClass;
But you can add your own namespace and location in composer.json.
Here difucult to say: Thank you!
need type 20 chars at least