Created
October 28, 2016 15:06
-
-
Save ribafs/2fb218eef79eda9c4cbb53bd3df6e5c4 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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