Skip to content

Instantly share code, notes, and snippets.

@ribafs
Created October 28, 2016 15:06
Show Gist options
  • Save ribafs/2fb218eef79eda9c4cbb53bd3df6e5c4 to your computer and use it in GitHub Desktop.
Save ribafs/2fb218eef79eda9c4cbb53bd3df6e5c4 to your computer and use it in GitHub Desktop.
Criando Uma Classe customizada e Usando num Aplicativo em CakePHP 3
Criar a classe em:
vendor/ribafs/CakeLib/RibaLib.php
Contendo:
<?php
namespace RibaCake;
class RibaCake{
public function myMethod(){
$my = 'My Method';
return $my;
}
}
Para usar em um Controller:
Adicione ao início do ClientesController.php, logo após os use:
use App\Controller\AppController;
require_once(ROOT.DS.'vendor'.DS.'ribafs'.DS.'CakeLib'.DS.'RibaCake.php');
use RibaCake\RibaCake;
Dentro de um método qualquer:
...
$obj = new RibaCake();
print $obj->myMethod();exit;
...
Créditos
http://stackoverflow.com/questions/28518238/how-can-i-use-my-own-external-class-in-cakephp-3-0
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment