Adding pages feature (index.php and htaccess) see #5848

skala
Julio Montoya 13 years ago
parent c71810f3d3
commit dd5f3fef8f
  1. 56
      composer.lock
  2. 8
      main/pages/.htaccess
  3. 160
      main/pages/index.php
  4. 38
      resources/migrations/Version20121220233847.php

56
composer.lock generated

@ -143,19 +143,19 @@
"source": {
"type": "git",
"url": "https://github.com/doctrine/dbal",
"reference": "6ace93c92ebfa2411b7c763607057baf069fb0d6"
"reference": "63b7ef12a51fab0df4588dbd21bd1a3613bc0362"
},
"dist": {
"type": "zip",
"url": "https://github.com/doctrine/dbal/archive/6ace93c92ebfa2411b7c763607057baf069fb0d6.zip",
"reference": "6ace93c92ebfa2411b7c763607057baf069fb0d6",
"url": "https://github.com/doctrine/dbal/archive/63b7ef12a51fab0df4588dbd21bd1a3613bc0362.zip",
"reference": "63b7ef12a51fab0df4588dbd21bd1a3613bc0362",
"shasum": ""
},
"require": {
"php": ">=5.3.2",
"doctrine/common": ">=2.3-dev,<2.5-dev"
},
"time": "2012-12-17 11:53:37",
"time": "2012-12-23 21:25:15",
"type": "library",
"extra": {
"branch-alias": {
@ -207,12 +207,12 @@
"source": {
"type": "git",
"url": "https://github.com/doctrine/migrations",
"reference": "c1d875ce7d092dd1bc7508c3867b5c6b97431e43"
"reference": "6e916d8e39b4963d6fd52622fd9ac797dce82837"
},
"dist": {
"type": "zip",
"url": "https://github.com/doctrine/migrations/archive/c1d875ce7d092dd1bc7508c3867b5c6b97431e43.zip",
"reference": "c1d875ce7d092dd1bc7508c3867b5c6b97431e43",
"url": "https://github.com/doctrine/migrations/archive/6e916d8e39b4963d6fd52622fd9ac797dce82837.zip",
"reference": "6e916d8e39b4963d6fd52622fd9ac797dce82837",
"shasum": ""
},
"require": {
@ -226,7 +226,7 @@
"suggest": {
"symfony/console": "to run the migration from the console"
},
"time": "2012-10-19 10:37:24",
"time": "2012-12-26 14:01:23",
"type": "library",
"installation-source": "source",
"autoload": {
@ -262,12 +262,12 @@
"source": {
"type": "git",
"url": "git://github.com/doctrine/doctrine2.git",
"reference": "8b5e4a9a52670992b85e7223d255b98cf77a35a3"
"reference": "90b6d5e293147a0268ca005362ff50343bc6dc0f"
},
"dist": {
"type": "zip",
"url": "https://github.com/doctrine/doctrine2/archive/8b5e4a9a52670992b85e7223d255b98cf77a35a3.zip",
"reference": "8b5e4a9a52670992b85e7223d255b98cf77a35a3",
"url": "https://github.com/doctrine/doctrine2/archive/90b6d5e293147a0268ca005362ff50343bc6dc0f.zip",
"reference": "90b6d5e293147a0268ca005362ff50343bc6dc0f",
"shasum": ""
},
"require": {
@ -279,7 +279,7 @@
"suggest": {
"symfony/yaml": "If you want to use YAML Metadata Mapping Driver"
},
"time": "2012-12-21 11:45:07",
"time": "2012-12-24 09:40:52",
"bin": [
"bin/doctrine",
"bin/doctrine.php"
@ -767,12 +767,12 @@
"source": {
"type": "git",
"url": "https://github.com/symfony/EventDispatcher",
"reference": "v2.1.6"
"reference": "0e9d69646306e11d03dde4a29e79cd09d9567cb9"
},
"dist": {
"type": "zip",
"url": "https://github.com/symfony/EventDispatcher/archive/v2.1.6.zip",
"reference": "v2.1.6",
"url": "https://github.com/symfony/EventDispatcher/archive/0e9d69646306e11d03dde4a29e79cd09d9567cb9.zip",
"reference": "0e9d69646306e11d03dde4a29e79cd09d9567cb9",
"shasum": ""
},
"require": {
@ -785,7 +785,7 @@
"symfony/dependency-injection": "2.1.*",
"symfony/http-kernel": "2.1.*"
},
"time": "2012-12-06 10:00:55",
"time": "2012-12-27 08:21:49",
"type": "library",
"installation-source": "source",
"autoload": {
@ -817,12 +817,12 @@
"source": {
"type": "git",
"url": "https://github.com/symfony/Form",
"reference": "v2.1.6"
"reference": "2cc2a32b6567e974d63f5ac6514db33b1b265dde"
},
"dist": {
"type": "zip",
"url": "https://github.com/symfony/Form/archive/v2.1.6.zip",
"reference": "v2.1.6",
"url": "https://github.com/symfony/Form/archive/2cc2a32b6567e974d63f5ac6514db33b1b265dde.zip",
"reference": "2cc2a32b6567e974d63f5ac6514db33b1b265dde",
"shasum": ""
},
"require": {
@ -839,7 +839,7 @@
"symfony/validator": "2.1.*",
"symfony/http-foundation": "2.1.*"
},
"time": "2012-12-15 17:20:34",
"time": "2012-12-20 17:52:51",
"type": "library",
"installation-source": "source",
"autoload": {
@ -1243,12 +1243,12 @@
"source": {
"type": "git",
"url": "https://github.com/symfony/TwigBridge",
"reference": "8e744c833f1fdee779a9e747a2feb795a655d869"
"reference": "5f83b3f000eedc25e5fa538bd2ff928e21e2327c"
},
"dist": {
"type": "zip",
"url": "https://github.com/symfony/TwigBridge/archive/8e744c833f1fdee779a9e747a2feb795a655d869.zip",
"reference": "8e744c833f1fdee779a9e747a2feb795a655d869",
"url": "https://github.com/symfony/TwigBridge/archive/5f83b3f000eedc25e5fa538bd2ff928e21e2327c.zip",
"reference": "5f83b3f000eedc25e5fa538bd2ff928e21e2327c",
"shasum": ""
},
"require": {
@ -1273,7 +1273,7 @@
"symfony/security": "2.2.*",
"symfony/http-kernel": "2.2.*"
},
"time": "2012-12-20 07:31:14",
"time": "2012-12-22 14:51:06",
"type": "symfony-bridge",
"extra": {
"branch-alias": {
@ -1405,18 +1405,18 @@
"source": {
"type": "git",
"url": "git://github.com/fabpot/Twig.git",
"reference": "f095f3a1777431412954e478f92e8a10cb7b6495"
"reference": "a65e7e4e2e5726a42a29e609fad008f8a9600594"
},
"dist": {
"type": "zip",
"url": "https://github.com/fabpot/Twig/archive/f095f3a1777431412954e478f92e8a10cb7b6495.zip",
"reference": "f095f3a1777431412954e478f92e8a10cb7b6495",
"url": "https://github.com/fabpot/Twig/archive/a65e7e4e2e5726a42a29e609fad008f8a9600594.zip",
"reference": "a65e7e4e2e5726a42a29e609fad008f8a9600594",
"shasum": ""
},
"require": {
"php": ">=5.2.4"
},
"time": "2012-12-18 10:01:32",
"time": "2012-12-25 10:06:30",
"type": "library",
"extra": {
"branch-alias": {

@ -0,0 +1,8 @@
<IfModule mod_rewrite.c>
Options -MultiViews
RewriteEngine On
#RewriteBase /path/to/app
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^ index.php [L]
</IfModule>

@ -0,0 +1,160 @@
<?php
require_once '../inc/global.inc.php';
use Silex\Application;
use Symfony\Component\Validator\Constraints as Assert;
use Doctrine\ORM\Tools\Pagination\Paginator;
use Pagerfanta\Pagerfanta;
use Pagerfanta\Adapter\DoctrineORMAdapter;
use Pagerfanta\View\TwitterBootstrapView;
//use Pagerfanta\View\DefaultView;
//use Pages\PagesAdmin;
class PagesController {
/*
function indexAction(Application $app, $page) {
return $this->listAction($app, $page);
}*/
function addAction(Application $app) {
$request = $app['request'];
$form = $this->getForm($app);
if ('POST' == $request->getMethod()) {
$form->bindRequest($request);
if ($form->isValid()) {
$page = $form->getData();
$em = $app['orm.em'];
/*$page_data = $form->getData();
$page->setContent($page_data['content']);
$page->setSlug($page_data['slug']);
$page->setTitle($page_data['title']);
$em->persist($page);*/
$em->persist($page);
$em->flush();
return $app->redirect($app['url_generator']->generate('show', array('id'=> $page->getId())), 201);
}
}
return $app['template']->render_template('pages/add.tpl', array('form' => $form->createView()));
}
function editAction(Application $app, $id) {
$request = $app['request'];
$page = $app['orm.em']->find('Entity\EntityPages', $id);
if (empty($page)) {
$app->abort(404, "Page $id does not exist.");
}
$form = $this->getForm($app, $page);
if ('POST' == $request->getMethod()) {
$form->bind($request);
if ($form->isValid()) {
$em = $app['orm.em'];
//$page = $form->getData();
$em->persist($page);
$em->flush();
return $app->redirect($app['url_generator']->generate('show', array('id'=> $page->getId())), 201);
}
}
return $app['template']->render_template('pages/add.tpl', array('form' => $form->createView()));
}
function showAction(Application $app, $id) {
$page = $app['orm.em']->find('Entity\EntityPages', $id);
$actions = Display::url(Display::return_icon('list.png', get_lang('Listing'), array(), ICON_SIZE_MEDIUM), $app['url_generator']->generate('index'));
return $app['template']->render_template('pages/show.tpl', array(
'page' => $page,
'actions' => $actions,
));
}
function deleteAction(Application $app, $id) {
$em = $app['orm.em'];
$page = $em->find('Entity\EntityPages', $id);
$em->remove($page);
$em->flush();
return $app->redirect($app['url_generator']->generate('index'), 201);
}
function listAction(Application $app, $page = 1) {
/*$app['sonata.crud_controller']->listAction();
require_once 'pageadmin.php';
$pages_admin = new PagesAdmin('a', 'b', 'Controller');
$html = $pages_admin->getDatagrid();
var_dump($html);*/
$em = $app['orm.em'];
$dql = 'SELECT a FROM Entity\EntityPages a';
$query = $em->createQuery($dql)->setFirstResult(0)
->setMaxResults(100);
//or using the repository
//
//$query = $em->getRepository('Entity\EntityPages')->getLatestPages();
$adapter = new DoctrineORMAdapter($query);
$pagerfanta = new Pagerfanta($adapter);
$routeGenerator = function($page) use ($app) {
return $app['url_generator']->generate('list', array('page' => $page));
};
$pagerfanta->setMaxPerPage(2); // 10 by default
$pagerfanta->setCurrentPage($page);
//$view = new DefaultView();
$view = new TwitterBootstrapView();
$pagination = $view->render($pagerfanta, $routeGenerator, array(
'proximity' => 3,
));
$actions = Display::url(Display::return_icon('add.png', get_lang('Add'), array(), ICON_SIZE_MEDIUM), $app['url_generator']->generate('add'));
//$paginator = new Paginator($query, $fetchJoinCollection = true);
return $app['template']->render_template('pages/listing.tpl', array(
//'pages' => $paginator->getIterator(),
'pages' => $pagerfanta,
'pagination' => $pagination,
'actions' => $actions
));
}
function getForm(Application $app, $entity = null) {
if (empty($entity)) {
$entity = new Entity\EntityPages();
}
$form = $app['form.factory']->createBuilder('form', $entity);
$form->add('title', 'text', array(
'constraints' => array(new Assert\NotBlank(), new Assert\MinLength(5))
));
$form->add('slug', 'text', array(
//'constraints' => array(new Assert\NotBlank())
));
$form->add('content', 'textarea', array(
// 'constraints' => array()
));
return $form->getForm();
}
}
//$app->match('/{page}', 'PagesController::indexAction')->bind('index');
$app->get('/', 'PagesController::listAction')->bind('index');
$app->get('/page', 'PagesController::listAction')->bind('list');
$app->get('/show/{id}', 'PagesController::showAction')
->bind('show')
->assert('id', '\d+');
$app->get('/delete/{id}', 'PagesController::deleteAction')
->bind('delete')
->assert('id', '\d+');
$app->match('/edit/{id}', 'PagesController::editAction', 'GET|POST')
->bind('edit')
->assert('id', '\d+');
$app->match('/add', 'PagesController::addAction', 'GET|POST')->bind('add');
$app->run();

@ -1,38 +0,0 @@
<?php
namespace DoctrineMigrations;
use Doctrine\DBAL\Migrations\AbstractMigration,
Doctrine\DBAL\Schema\Schema;
/**
* Auto-generated Migration: Please modify to your need!
*/
class Version20121220233847 extends AbstractMigration
{
public function up(Schema $schema)
{
/*$this->addSql('CREATE TABLE pages (
id INTEGER NOT NULL AUTO_INCREMENT,
title VARCHAR(255) NOT NULL,
slug VARCHAR(255) NOT NULL,
content TEXT NOT NULL,
PRIMARY KEY (id)
)');*/
$table = $schema->createTable('pages');
$table->addColumn('id', 'string');
$table->addColumn('title', 'string');
$table->addColumn('slug', 'string');
$table->addColumn('content', 'text');
$table->addColumn('created', 'datetime');
$table->addColumn('updated', 'datetime');
$table->setPrimaryKey('id');
}
public function down(Schema $schema)
{
//$this->addSql('DROP TABLE pages');
$schema->dropTable('pages');
}
}
Loading…
Cancel
Save