Adding pages feature see #5848
parent
36875ee42b
commit
05b2c15388
@ -0,0 +1,154 @@ |
||||
<?php |
||||
|
||||
namespace Entity; |
||||
use Doctrine\Mapping as ORM; |
||||
|
||||
/** |
||||
* EntityPages |
||||
* |
||||
* @Table(name="pages") |
||||
* @Entity(repositoryClass="Entity\Repository\PagesRepository") |
||||
* @HasLifecycleCallbacks() |
||||
*/ |
||||
class EntityPages |
||||
{ |
||||
/** |
||||
* @var integer |
||||
* |
||||
* @Column(name="id", type="integer", precision=0, scale=0, nullable=false, unique=false) |
||||
* @Id |
||||
* @GeneratedValue(strategy="IDENTITY") |
||||
*/ |
||||
private $id; |
||||
|
||||
/** |
||||
* @var string |
||||
* |
||||
* @Column(name="title", type="string", length=255, precision=0, scale=0, nullable=false, unique=false) |
||||
*/ |
||||
private $title; |
||||
|
||||
/** |
||||
* @var string |
||||
* |
||||
* @Column(name="slug", type="string", length=255, precision=0, scale=0, nullable=false, unique=false) |
||||
*/ |
||||
private $slug; |
||||
|
||||
/** |
||||
* @var string |
||||
* |
||||
* @Column(name="content", type="text", precision=0, scale=0, nullable=false, unique=false) |
||||
*/ |
||||
private $content; |
||||
|
||||
|
||||
/** |
||||
* @var \DateTime |
||||
* @Column(type="datetime") |
||||
*/ |
||||
private $created; |
||||
|
||||
/** |
||||
* @var \DateTime |
||||
* @Column(type="datetime") |
||||
*/ |
||||
private $updated; |
||||
|
||||
public function __construct() |
||||
{ |
||||
$this->setCreated(); |
||||
$this->setUpdated(); |
||||
} |
||||
|
||||
/** |
||||
* @preUpdate |
||||
*/ |
||||
public function setUpdated() |
||||
{ |
||||
$this->updated = new \DateTime(); |
||||
} |
||||
|
||||
public function setCreated() |
||||
{ |
||||
$this->created = new \DateTime(); |
||||
} |
||||
|
||||
/** |
||||
* Get id |
||||
* |
||||
* @return integer |
||||
*/ |
||||
public function getId() |
||||
{ |
||||
return $this->id; |
||||
} |
||||
|
||||
/** |
||||
* Set title |
||||
* |
||||
* @param string $title |
||||
* @return EntityPages |
||||
*/ |
||||
public function setTitle($title) |
||||
{ |
||||
$this->title = $title; |
||||
|
||||
return $this; |
||||
} |
||||
|
||||
/** |
||||
* Get title |
||||
* |
||||
* @return string |
||||
*/ |
||||
public function getTitle() |
||||
{ |
||||
return $this->title; |
||||
} |
||||
|
||||
/** |
||||
* Set slug |
||||
* |
||||
* @param string $slug |
||||
* @return EntityPages |
||||
*/ |
||||
public function setSlug($slug) |
||||
{ |
||||
$this->slug = $slug; |
||||
return $this; |
||||
} |
||||
|
||||
/** |
||||
* Get slug |
||||
* |
||||
* @return string |
||||
*/ |
||||
public function getSlug() |
||||
{ |
||||
return $this->slug; |
||||
} |
||||
|
||||
/** |
||||
* Set content |
||||
* |
||||
* @param string $content |
||||
* @return EntityPages |
||||
*/ |
||||
public function setContent($content) |
||||
{ |
||||
$this->content = $content; |
||||
|
||||
return $this; |
||||
} |
||||
|
||||
/** |
||||
* Get content |
||||
* |
||||
* @return string |
||||
*/ |
||||
public function getContent() |
||||
{ |
||||
return $this->content; |
||||
} |
||||
} |
@ -0,0 +1,28 @@ |
||||
<?php |
||||
|
||||
namespace Entity\Repository; |
||||
|
||||
use Doctrine\ORM\EntityRepository; |
||||
|
||||
|
||||
/** |
||||
* PagesRepository |
||||
* |
||||
* This class was generated by the Doctrine ORM. Add your own custom |
||||
* repository methods below. |
||||
*/ |
||||
class PagesRepository extends EntityRepository |
||||
{ |
||||
public function getLatestPages($limit = null) |
||||
{ |
||||
$qb = $this->createQueryBuilder('b') |
||||
->select('b') |
||||
->addOrderBy('b.created', 'DESC'); |
||||
return $qb; |
||||
if (false === is_null($limit)) |
||||
$qb->setMaxResults($limit); |
||||
|
||||
return $qb->getQuery() |
||||
->getResult(); |
||||
} |
||||
} |
@ -0,0 +1,8 @@ |
||||
{% extends "default/layout/layout_1_col.tpl" %} |
||||
|
||||
{% block content %} |
||||
<form action="#" method="post"> |
||||
{{ form_widget(form) }} |
||||
<input class="btn" type="submit" name="submit" value="{{ "Send" | get_lang }}" /> |
||||
</form> |
||||
{% endblock %} |
@ -0,0 +1,12 @@ |
||||
{% extends "default/layout/layout_1_col.tpl" %} |
||||
|
||||
{% block content %} |
||||
{% for page in pages %} |
||||
{{ page.title }} - |
||||
{{ page.slug }} - |
||||
{{ page.description }} - <a href="{{ url('edit', {id: page.id}) }}">Edit</a> <a href="{{ url('delete', {id: page.id}) }}">Delete</a> |
||||
{{ loop.index }}/{{ loop.length }} |
||||
<br /> |
||||
{% endfor %} |
||||
{{ pagination }} |
||||
{% endblock %} |
@ -0,0 +1,8 @@ |
||||
{% extends 'default/layout/layout_1_col.tpl' %} |
||||
|
||||
{% block content %} |
||||
{{ page|var_dump}} |
||||
{{ page.title }} |
||||
{{ page.slug }} |
||||
{{ page.content }} |
||||
{% endblock %} |
@ -0,0 +1,38 @@ |
||||
<?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', 'integer', array("unsigned" => true, 'autoincrement' => 'true')); |
||||
$table->addColumn('title', 'string'); |
||||
$table->addColumn('slug', 'string'); |
||||
$table->addColumn('content', 'text'); |
||||
$table->addColumn('created', 'datetime'); |
||||
$table->addColumn('updated', 'datetime'); |
||||
$table->addOption('engine' , 'MyISAM'); |
||||
$table->setPrimaryKey(array('id')); |
||||
} |
||||
|
||||
public function down(Schema $schema) |
||||
{ |
||||
//$this->addSql('DROP TABLE pages'); |
||||
$schema->dropTable('pages'); |
||||
} |
||||
} |
Loading…
Reference in new issue