Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- // ****************** index.php ****************** //
- //*** DEFINE TIMEZONE ***\\
- date_default_timezone_set('America/Recife');
- //*** CHARSET PHP ***\\
- header('Content-type: text/html; charset=utf-8');
- /* ......[código]...... */
- /* AUTOLOAD & BOOTSTRAP */
- require_once('vendor/autoload.php');
- require_once('bootstrap.php');
- /*****************************************************************/
- /*****************************************************************/
- /*****************************************************************/
- // ****************** bootstrap.php ****************** //
- // o Doctrine utiliza namespaces em sua estrutura, por isto estes uses
- use Doctrine\ORM\Tools\Setup;
- use Doctrine\ORM\EntityManager;
- // Criar uma configuração simples ["default"] de Doctrine ORM para Annotations
- $isDevMode = true;
- $pathEntitys = array(__DIR__."/src/Projeto/Core/Model", __DIR__."/src/Projeto/App/Model");
- $config = Setup::createAnnotationMetadataConfiguration($pathEntitys, $isDevMode);
- // Parâmetros de Configuração do Banco de Dasdos
- require_once(DBCONFIG.'dbconfig.php');
- // Obtendo o Entity Manager com base nas configurações anteriores
- $entityManager = EntityManager::create($dbParams, $config);
- // dando um var_dump no $entityManager, confirma-se sua instância criada
- Projeto\FrontController::run();
- /*****************************************************************/
- /*****************************************************************/
- /*****************************************************************/
- // ****************** GruposController.php ****************** //
- namespace Projeto\Core\Controller;
- class GruposController extends Controller
- {
- public function index()
- {
- //$grupoModel = new \Core\Model\Grupos();
- //$grupoDAO = new \Core\DAO\GruposDao();
- //$dadosToView[\Projeto\FrontController::getController()] = $grupoDAO->listarAll($grupoModel);
- // essas linhas de cima é a forma antiga que funcionava antes da adaptação para o Doctrine
- // E a parte de baixo é a nova forma com Doctrine (listar todos os grupos)
- $gruposRepository = $entityManager->getRepository('Grupos');
- // porém $entityManager não é reconhecido dando o seguinte erro de log do apache:
- /* Fatal error: Call to a member function getRepository() on a non-object in
- /var/www/html/projetoTeste/src/Projeto/Core/Controller/GruposController.php on line 12 */
- $grupos = $gruposRepository->findAll();
- parent::view($dadosToView);
- }
- // [Outros métodos] .......
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement