Skip to content

Instantly share code, notes, and snippets.

@Bolinha1
Last active December 24, 2015 01:29
Show Gist options
  • Select an option

  • Save Bolinha1/6723429 to your computer and use it in GitHub Desktop.

Select an option

Save Bolinha1/6723429 to your computer and use it in GitHub Desktop.
Index com as rotas
<?pphp
require_once 'vendor/autoload.php';
require_once 'src/controllers/Site/ControllerApp.php';
require_once 'src/controllers/Painel/ControllerPainel.php';
use Silex\Application;
use Site\ControllerApp;
use Painel\ControllerPainel;
$app = new Application();
$app->register(new Silex\Provider\ServiceControllerServiceProvider());
//registro o controller referente a navegação do site
$app['controller'] = $app->share(function () use ($app){
return new ControllerApp;
});
// fim registro controller
// rotas referentes a navegação do site
$app->get('/', "controller:index");
$app->get('/quem-somos', "controller:quemSomos");
$app->get('/nossos-trabalhos', "controller:nossosTrabalhos");
$app->get('/produtos', "controller:produtos");
$app->get('/contatos', "controller:contatos");
$app->post('/enviar', "controller:enviar");
// fim rotas navegação site.
$app['debug'] = 'true';
$app->run();
<?php
namespace Site;
include __DIR__.'/../../library/view/Site/View/View.php';
include __DIR__.'/../../helper/enviarEmail.php';
use Symfony\Component\HttpFoundation\Request;
use Site\View\View;
class ControllerApp
{
private $view;
public function __construct()
{
$this->view = new View;
}
public function index()
{
return $this->view->load('index');
}
public function quemSomos()
{
return $this->view->load('quemSomos');
}
public function produtos()
{
return $this->view->load('produtos');
}
public function nossosTrabalhos()
{
return $this->view->load('trabalhos');
}
public function contatos()
{
return $this->view->load('contato');
}
public function enviar(Request $request)
{
$nome = $request->get('nome');
$email = $request->get('email');
$assunto = $request->get('assunto');
$mensagem = $request->get('mensagem');
$enviar = enviar($nome,$email,$assunto, $mensagem);
return $enviar;
}
}
<?php
namespace Painel\View;
use Symfony\Component\Templating\PhpEngine;
use Symfony\Component\Templating\TemplateNameParser;
use Symfony\Component\Templating\Loader\FilesystemLoader;
class View
{
public function load($view, $content = array())
{
$loader = new FilesystemLoader(__DIR__.'/../../../../view/site/%name%');
$templating = new PhpEngine(new TemplateNameParser(), $loader);
return $templating->render("$view.php", $content);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment