PHP code example of ozee31 / cakephp-override

1. Go to this page and download the library: Download ozee31/cakephp-override library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

ozee31 / cakephp-override example snippets


Plugin::load('Override', ['bootstrap' => true]);

 return ['Overrides' => [
    'routes' => [
        /*
         * (!) You must also add the model override
         */
    ],
    'models' => [
        /*
         * (!) Always redeclare entityClass when overriding className otherwise cakephp does not use it
         */
    ],
    'helpers' => []
]];



// Use Override class
use Override\Routing\Override;


Router::scope('/', function (RouteBuilder $routes) {
    // In Router scope add this code
    Override::connect($routes);

    // ... other routes
});

// Plugin routes must be declared after Override::connect()
Plugin::routes();

public function initialize()
{
    parent::initialize();

    $this->loadComponent('Override.Override');
}

$routes->connect(
    '/user/:username', 
    ['controller' => 'Users', 'action' => 'view'],
    ['pass' => ['username']]
);

'routes' => [
    '/user/:username' => [
        'route' => ['controller' => 'Users', 'action' => 'view', 'plugin' => false],
        'options' => ['pass' => ['username']]
    ],
],

'models' => [
    'MyPlugin.Users' => ['entityClass' => 'App\Model\Entity\User'],
],

'models' => [
    'MyPlugin.Users' => [
        'className' => 'App\Model\Table\UsersTable', 
        'entityClass' => 'App\Model\Entity\User'
    ],
],

'models' => [
    'MyPlugin.Users' => [
        'className' => 'App\Model\Table\UsersTable', 
        'entityClass' => 'MyPlugin\Model\Entity\User'
    ],
],

'helpers' => [
        'MyPlugin.Tests' => [
            'className' => 'Tests', // must be the same name of original
            'controllers' => true, // true if you want override for all Controllers, an array or a string otherwise
        ]
    ]

 return ['Overrides' => [
    'routes' => [
        '/myplugin/users' => [
            'route' => ['controller' => 'Users', 'action' => 'index', 'plugin' => false],
        ],
    ],
    'models' => [
        'MyPlugin.Users' => [
            'className' => 'MyPlugin\Model\Table\UsersTable',
            'entityClass' => 'MyPlugin\Model\Entity\User'
        ],
    ],
    'helpers' => []
]];