diff --git a/app/AppKernel.php b/app/AppKernel.php
index a19c9c1..5c5413b 100644
--- a/app/AppKernel.php
+++ b/app/AppKernel.php
@@ -15,10 +15,13 @@ public function registerBundles()
new Symfony\Bundle\SwiftmailerBundle\SwiftmailerBundle(),
new Symfony\Bundle\AsseticBundle\AsseticBundle(),
new Doctrine\Bundle\DoctrineBundle\DoctrineBundle(),
+ new Doctrine\Bundle\FixturesBundle\DoctrineFixturesBundle(),
new Sensio\Bundle\FrameworkExtraBundle\SensioFrameworkExtraBundle(),
new JMS\AopBundle\JMSAopBundle(),
new JMS\DiExtraBundle\JMSDiExtraBundle($this),
new JMS\SecurityExtraBundle\JMSSecurityExtraBundle(),
+ new First\GodBundle\FirstGodBundle(),
+ new First\HellBundle\FirstHellBundle(),
);
if (in_array($this->getEnvironment(), array('dev', 'test'))) {
diff --git a/app/config/config.yml b/app/config/config.yml
index 4dd6560..8bcedaa 100644
--- a/app/config/config.yml
+++ b/app/config/config.yml
@@ -20,6 +20,11 @@ framework:
twig:
debug: %kernel.debug%
strict_variables: %kernel.debug%
+ globals:
+ google_consumer_code: ninja!
+ form:
+ resource:
+ - 'FirstGodBundle:Form:fields.html.twig'
# Assetic Configuration
assetic:
@@ -56,3 +61,9 @@ swiftmailer:
username: %mailer_user%
password: %mailer_password%
spool: { type: memory }
+
+sensio_framework_extra:
+ router: { annotations: true }
+ request: { converters: true }
+ view: { annotations: true }
+ cache: { annotations: true }
diff --git a/app/config/config_dev.yml b/app/config/config_dev.yml
index b7e675d..e1db637 100644
--- a/app/config/config_dev.yml
+++ b/app/config/config_dev.yml
@@ -4,6 +4,7 @@ imports:
framework:
router: { resource: "%kernel.root_dir%/config/routing_dev.yml" }
profiler: { only_exceptions: false }
+ validation: { enable_annotations: true }
web_profiler:
toolbar: true
@@ -21,6 +22,12 @@ monolog:
assetic:
use_controller: true
+
+services:
+ my.listener:
+ class: First\GodBundle\Listener\AddCategoryByUser
+ tags:
+ - { name: doctrine.event_listener, event: postPersist }
#swiftmailer:
# delivery_address: me@example.com
diff --git a/app/config/routing.yml b/app/config/routing.yml
index 684d364..bd168d2 100644
--- a/app/config/routing.yml
+++ b/app/config/routing.yml
@@ -1,3 +1,15 @@
+FirstHellBundle:
+ resource: "@FirstHellBundle/Resources/config/routing.yml"
+ prefix: /
+
+#FirstGodBundle:
+# resource: "@FirstGodBundle/Resources/config/routing.yml"
+# prefix: /
+
+Hello:
+ resource: "@FirstGodBundle/Controller/HelloController.php"
+ type: annotation
+
# Internal routing configuration to handle ESI
#_internal:
# resource: "@FrameworkBundle/Resources/config/routing/internal.xml"
diff --git a/composer.json b/composer.json
index 483de4d..d958c96 100644
--- a/composer.json
+++ b/composer.json
@@ -9,6 +9,7 @@
"symfony/symfony": "2.1.*",
"doctrine/orm": "2.2.*",
"doctrine/doctrine-bundle": "dev-master",
+ "doctrine/doctrine-fixtures-bundle": "*",
"twig/extensions": "dev-master",
"symfony/assetic-bundle": "dev-master",
"symfony/swiftmailer-bundle": "dev-master",
diff --git a/composer.lock b/composer.lock
index 7306f0b..e7d3300 100644
--- a/composer.lock
+++ b/composer.lock
@@ -1,5 +1,5 @@
{
- "hash": "64ef8edd92e0a1c3c3afc3d0c7f32697",
+ "hash": "4150fb26a3375a38a092208093ce0b76",
"packages": [
{
"package": "doctrine/common",
@@ -19,6 +19,11 @@
"version": "dev-master",
"source-reference": "5dad4a6ae187c6d345ec2b02be20ccc33779f53e"
},
+ {
+ "package": "doctrine/doctrine-fixtures-bundle",
+ "version": "dev-master",
+ "source-reference": "33b267d3068d6c2f8daa0b417285cf76e7f82fc4"
+ },
{
"package": "doctrine/orm",
"version": "2.2.x-dev",
@@ -82,13 +87,6 @@
"alias-pretty-version": "4.1.x-dev",
"alias-version": "4.1.9999999.9999999-dev"
},
- {
- "package": "swiftmailer/swiftmailer",
- "version": "dev-master",
- "source-reference": "57789082d1d53529dcf8cd3ca132d9787a59afee",
- "alias-pretty-version": "4.1.x-dev",
- "alias-version": "4.1.9999999.9999999-dev"
- },
{
"package": "swiftmailer/swiftmailer",
"version": "dev-master",
@@ -131,7 +129,14 @@
{
"package": "symfony/symfony",
"version": "dev-master",
- "source-reference": "18132c18b41637a05a3a13990651a4054cf0ce59"
+ "source-reference": "58b924533a15364226bf8321706b467b4a86ba07",
+ "alias-pretty-version": "2.1.x-dev",
+ "alias-version": "2.1.9999999.9999999-dev"
+ },
+ {
+ "package": "symfony/symfony",
+ "version": "dev-master",
+ "source-reference": "58b924533a15364226bf8321706b467b4a86ba07"
},
{
"package": "symfony/symfony",
@@ -148,12 +153,19 @@
{
"package": "twig/twig",
"version": "dev-master",
- "source-reference": "875fa010ce597edf97c04ce6490be950068e9372"
+ "source-reference": "875fa010ce597edf97c04ce6490be950068e9372",
+ "alias-pretty-version": "1.8.x-dev",
+ "alias-version": "1.8.9999999.9999999-dev"
},
{
"package": "twig/twig",
"version": "dev-master",
- "source-reference": "875fa010ce597edf97c04ce6490be950068e9372",
+ "source-reference": "e28663efd83d76ee36bf9e8a790f75bd880abbf2"
+ },
+ {
+ "package": "twig/twig",
+ "version": "dev-master",
+ "source-reference": "e28663efd83d76ee36bf9e8a790f75bd880abbf2",
"alias-pretty-version": "1.8.x-dev",
"alias-version": "1.8.9999999.9999999-dev"
}
diff --git a/src/First/GodBundle/Controller/HelloController.php b/src/First/GodBundle/Controller/HelloController.php
new file mode 100644
index 0000000..4b6def4
--- /dev/null
+++ b/src/First/GodBundle/Controller/HelloController.php
@@ -0,0 +1,184 @@
+getDoctrine()->getEntityManager();
+ $user = $this->getDoctrine()->getRepository( 'FirstGodBundle:User' );
+ $u_result = $user->find( 9 );
+ $u_result1 = $user->findAll();
+ $u_result2 = $user->findBy( array('name' => 'CP3', 'id' => 14) );
+ $u_result3 = $user->findOneBy( array('name' => 'CP3') );
+ $u_result4 = $user->findOneByName( 'CP3' );
+// var_dump( $u_result );
+// var_dump( $u_result1 );
+// var_dump( $u_result2 );
+// var_dump( $u_result3 );
+// var_dump( $u_result4 );
+ if ( ! $u_result)
+ {
+ throw $this->createNotFoundException( 'no user found for this id 9' ); //404
+ throw new \Exception( 'something get wrong' ); //500
+ }
+
+// var_dump($request->getAcceptableContentTypes());
+// var_dump($request->getBasePath()); // 返回目录路径 如 http://localhost/web/index.php => 'web'否则空
+// var_dump($request->getBaseUrl());
+// var_dump($request->getScriptName());
+// var_dump($request->getClientIp());
+// var_dump($request->getContent());
+// var_dump($request->getHost());
+// var_dump($request->getLanguages());
+// var_dump($request->getPathInfo()); ///wtfHello'
+// var_dump($request->getPort());
+// var_dump($request->getQueryString());
+// var_dump($request->getRequestFormat());
+// var_dump($request->getRequestUri()); ///wtfHello?gaga=nima
+// var_dump($request->getScheme()); //http...
+// var_dump($request->getScriptName()); // /app.php
+// var_dump($request->getUri()); //http://symfonytest.au/wtfHello?gaga=nima
+
+ $this->get( 'session' )->set( 'foo', 'bar' );
+ echo $session = $this->get( 'session' )->get( 'foo' );
+
+// $response = new Response(json_encode(array('name'=>'gaga')));
+// $response->headers->set('Content-Type', 'application/json');
+
+ echo $request->isSecure();
+ echo $request->isXmlHttpRequest();
+
+ $request->query->get( 'this is get query string' );
+ $request->request->get( 'this is post query string' );
+
+ $post = $this->getDoctrine()->getRepository( 'FirstGodBundle:Post' );
+ $repo_user = $post->findBy( array('body' => 'lorme category!!', 'title' => 'gaga'), array('title' => 'DESC') );
+ var_dump( $repo_user );
+
+ $dql = "SELECT sum(p.id) AS comments " .
+ "FROM FirstGodBundle:Post p";
+ $results = $em->createQuery( $dql )->getResult();
+ var_dump( $results );
+
+ $posts = $em->getRepository( 'FirstGodBundle:Post' )
+ ->findAllLager19();
+ var_dump( $posts );
+
+ $w_post = $post->find( 5 );
+ $which_user = $w_post->getAuthor()->getName();
+ var_dump( $which_user );
+ echo get_class( $w_post->getAuthor() );
+
+// $category = new Category();
+// $category->setName( 'Mainly' );
+// $product = new Product();
+// $product->setName( 'Foo' );
+// $product->setPrice( 19.99 );
+// $product->setDescription( '不行就切JJ' );
+// // relate this product to the category
+// $product->setCategory( $category );
+// $em->persist( $category );
+// $em->persist( $product );
+// $lifecircletest = new User( '我操啊' );
+// $em->persist( $lifecircletest );
+//
+// $em->flush();
+
+ $userModel = new User( 'Griffen' );
+ $form = $this->createFormBuilder( $userModel )
+ ->add( 'name', 'text', array('label' => 'wtf ur name?', 'required' => true, 'max_length' => 5) )
+ ->add( 'date', 'date' )
+ ->getForm();
+
+
+// return $this->render( 'FirstGodBundle:Hello:index.html.twig', array('form' => $form->createView(), 'users' => range( 1, 10 )) );
+ return array('form' => $form->createView(), 'users' => range( 1, 10 ));
+ }
+
+ /**
+ *
+ * @Route("/new", name="FirstGodBundle_new")
+ * @Method("POST")
+ */
+ public function createAction(Request $request)
+ {
+ $userModel = new User( '' );
+ $form = $this->createForm( new \First\GodBundle\Form\UserType(), $userModel );
+
+ if ($request->getMethod() == 'POST')
+ {
+// var_dump( $form );
+// exit();
+ $form->bindRequest( $request );
+
+ if ($form->isValid())
+ {
+ $em = $this->getDoctrine()->getEntityManager();
+ $em->persist( $userModel );
+ $em->flush();
+
+ $this->get( 'session' )->setFlash( 'note', 'You are succussful create a user!' );
+
+ return $this->redirect( $this->generateUrl( 'FirstGodBundle_homepage' ) );
+ }
+ }
+ }
+
+ public function productAction(Request $request)
+ {
+ $product = new Product();
+ $form = $this->createForm( new ProductType(), $product );
+
+
+ return $this->render( 'FirstGodBundle:Hello:new.html.twig', array('form' => $form->createView()) );
+ }
+
+ public function new_productAction(Request $request)
+ {
+ $product = new Product();
+ $form = $this->createForm( new ProductType(), $product );
+
+ if ($request->getMethod() == 'POST')
+ {
+ $form->bindRequest( $request );
+ if ($form->isValid())
+ {
+ $em = $this->getDoctrine()->getEntityManager();
+ $em->persist( $product );
+ $em->flush();
+
+ $this->get( 'session' )->setFlash( 'note', 'You are succussful create a product!' );
+
+ return $this->redirect( $this->generateUrl( 'FirstGodBundle_homepage' ) );
+ }
+ }
+// return $this->render( 'FirstGodBundle:Hello:new.html.twig', array('ret' => $ret) );
+ }
+
+}
diff --git a/src/First/GodBundle/Controller/UserController.php b/src/First/GodBundle/Controller/UserController.php
new file mode 100644
index 0000000..929054d
--- /dev/null
+++ b/src/First/GodBundle/Controller/UserController.php
@@ -0,0 +1,204 @@
+getDoctrine()->getManager();
+
+ $entities = $em->getRepository('FirstGodBundle:User')->findAll();
+
+ return array(
+ 'entities' => $entities,
+ );
+ }
+
+ /**
+ * Finds and displays a User entity.
+ *
+ * @Route("/{id}/show", name="first_user_show")
+ * @Template()
+ */
+ public function showAction($id)
+ {
+ $em = $this->getDoctrine()->getManager();
+
+ $entity = $em->getRepository('FirstGodBundle:User')->find($id);
+
+ if (!$entity) {
+ throw $this->createNotFoundException('Unable to find User entity.');
+ }
+
+ $deleteForm = $this->createDeleteForm($id);
+
+ return array(
+ 'entity' => $entity,
+ 'delete_form' => $deleteForm->createView(),
+ );
+ }
+
+ /**
+ * Displays a form to create a new User entity.
+ *
+ * @Route("/new", name="first_user_new")
+ * @Template()
+ */
+ public function newAction()
+ {
+ $entity = new User();
+ $form = $this->createForm(new UserType(), $entity);
+
+ return array(
+ 'entity' => $entity,
+ 'form' => $form->createView(),
+ );
+ }
+
+ /**
+ * Creates a new User entity.
+ *
+ * @Route("/create", name="first_user_create")
+ * @Method("post")
+ * @Template("FirstGodBundle:User:new.html.twig")
+ */
+ public function createAction()
+ {
+ $entity = new User();
+ $request = $this->getRequest();
+ $form = $this->createForm(new UserType(), $entity);
+ $form->bindRequest($request);
+
+ if ($form->isValid()) {
+ $em = $this->getDoctrine()->getManager();
+ $em->persist($entity);
+ $em->flush();
+
+ return $this->redirect($this->generateUrl('first_user_show', array('id' => $entity->getId())));
+ }
+
+ return array(
+ 'entity' => $entity,
+ 'form' => $form->createView(),
+ );
+ }
+
+ /**
+ * Displays a form to edit an existing User entity.
+ *
+ * @Route("/{id}/edit", name="first_user_edit")
+ * @Template()
+ */
+ public function editAction($id)
+ {
+ $em = $this->getDoctrine()->getManager();
+
+ $entity = $em->getRepository('FirstGodBundle:User')->find($id);
+
+ if (!$entity) {
+ throw $this->createNotFoundException('Unable to find User entity.');
+ }
+
+ $editForm = $this->createForm(new UserType(), $entity);
+ $deleteForm = $this->createDeleteForm($id);
+
+ return array(
+ 'entity' => $entity,
+ 'edit_form' => $editForm->createView(),
+ 'delete_form' => $deleteForm->createView(),
+ );
+ }
+
+ /**
+ * Edits an existing User entity.
+ *
+ * @Route("/{id}/update", name="first_user_update")
+ * @Method("post")
+ * @Template("FirstGodBundle:User:edit.html.twig")
+ */
+ public function updateAction($id)
+ {
+ $em = $this->getDoctrine()->getManager();
+
+ $entity = $em->getRepository('FirstGodBundle:User')->find($id);
+
+ if (!$entity) {
+ throw $this->createNotFoundException('Unable to find User entity.');
+ }
+
+ $editForm = $this->createForm(new UserType(), $entity);
+ $deleteForm = $this->createDeleteForm($id);
+
+ $request = $this->getRequest();
+
+ $editForm->bindRequest($request);
+
+ if ($editForm->isValid()) {
+ $em->persist($entity);
+ $em->flush();
+
+ return $this->redirect($this->generateUrl('first_user_edit', array('id' => $id)));
+ }
+
+ return array(
+ 'entity' => $entity,
+ 'edit_form' => $editForm->createView(),
+ 'delete_form' => $deleteForm->createView(),
+ );
+ }
+
+ /**
+ * Deletes a User entity.
+ *
+ * @Route("/{id}/delete", name="first_user_delete")
+ * @Method("post")
+ */
+ public function deleteAction($id)
+ {
+ $form = $this->createDeleteForm($id);
+ $request = $this->getRequest();
+
+ $form->bindRequest($request);
+
+ if ($form->isValid()) {
+ $em = $this->getDoctrine()->getManager();
+ $entity = $em->getRepository('FirstGodBundle:User')->find($id);
+
+ if (!$entity) {
+ throw $this->createNotFoundException('Unable to find User entity.');
+ }
+
+ $em->remove($entity);
+ $em->flush();
+ }
+
+ return $this->redirect($this->generateUrl('first_user'));
+ }
+
+ private function createDeleteForm($id)
+ {
+ return $this->createFormBuilder(array('id' => $id))
+ ->add('id', 'hidden')
+ ->getForm()
+ ;
+ }
+}
diff --git a/src/First/GodBundle/DataFixtures/ORM/FixturesLoader.php b/src/First/GodBundle/DataFixtures/ORM/FixturesLoader.php
new file mode 100644
index 0000000..1448a5e
--- /dev/null
+++ b/src/First/GodBundle/DataFixtures/ORM/FixturesLoader.php
@@ -0,0 +1,36 @@
+setTitle( 'wo ca' );
+ $post->setBody( 'lorme ri a !!' );
+
+ $post->addComment( "First.." );
+ $post->addComment( "Second!" );
+
+ $em->persist( $user );
+ $em->persist( $post );
+ }
+ $em->flush();
+ }
+
+}
diff --git a/src/First/GodBundle/DependencyInjection/Configuration.php b/src/First/GodBundle/DependencyInjection/Configuration.php
new file mode 100644
index 0000000..bf5be46
--- /dev/null
+++ b/src/First/GodBundle/DependencyInjection/Configuration.php
@@ -0,0 +1,29 @@
+root('first_god');
+
+ // Here you should define the parameters that are allowed to
+ // configure your bundle. See the documentation linked above for
+ // more information on that topic.
+
+ return $treeBuilder;
+ }
+}
diff --git a/src/First/GodBundle/DependencyInjection/FirstGodExtension.php b/src/First/GodBundle/DependencyInjection/FirstGodExtension.php
new file mode 100644
index 0000000..5eaed48
--- /dev/null
+++ b/src/First/GodBundle/DependencyInjection/FirstGodExtension.php
@@ -0,0 +1,28 @@
+processConfiguration($configuration, $configs);
+
+ $loader = new Loader\YamlFileLoader($container, new FileLocator(__DIR__.'/../Resources/config'));
+ $loader->load('services.yml');
+ }
+}
diff --git a/src/First/GodBundle/Entity/Category.php b/src/First/GodBundle/Entity/Category.php
new file mode 100644
index 0000000..95cc5ed
--- /dev/null
+++ b/src/First/GodBundle/Entity/Category.php
@@ -0,0 +1,75 @@
+products = new ArrayCollection();
+ }
+
+ /**
+ * Get id
+ *
+ * @return integer
+ */
+ public function getId()
+ {
+ return $this->id;
+ }
+
+ /**
+ * Set name
+ *
+ * @param string $name
+ */
+ public function setName($name)
+ {
+ $this->name = $name;
+ }
+
+ /**
+ * Get name
+ *
+ * @return string
+ */
+ public function getName()
+ {
+ return $this->name;
+ }
+
+
+}
\ No newline at end of file
diff --git a/src/First/GodBundle/Entity/Comment.php b/src/First/GodBundle/Entity/Comment.php
new file mode 100644
index 0000000..2222d33
--- /dev/null
+++ b/src/First/GodBundle/Entity/Comment.php
@@ -0,0 +1,86 @@
+post = $post;
+ $this->comment = $text;
+ }
+
+ /**
+ * Get id
+ *
+ * @return integer
+ */
+ public function getId()
+ {
+ return $this->id;
+ }
+
+ /**
+ * Set comment
+ *
+ * @param text $comment
+ */
+ public function setComment($comment)
+ {
+ $this->comment = $comment;
+ }
+
+ /**
+ * Get comment
+ *
+ * @return text
+ */
+ public function getComment()
+ {
+ return $this->comment;
+ }
+
+ /**
+ * Set post
+ *
+ * @param First\GodBundle\Entity\Post $post
+ */
+ public function setPost(\First\GodBundle\Entity\Post $post)
+ {
+ $this->post = $post;
+ }
+
+ /**
+ * Get post
+ *
+ * @return First\GodBundle\Entity\Post
+ */
+ public function getPost()
+ {
+ return $this->post;
+ }
+
+}
\ No newline at end of file
diff --git a/src/First/GodBundle/Entity/Post.php b/src/First/GodBundle/Entity/Post.php
new file mode 100644
index 0000000..6579bb8
--- /dev/null
+++ b/src/First/GodBundle/Entity/Post.php
@@ -0,0 +1,112 @@
+author = $author;
+ $this->posts = new ArrayCollection();
+ }
+
+ public function addComment($text)
+ {
+ $this->comments[] = new Comment( $this, $text );
+ }
+
+ public function getTitle()
+ {
+ return $this->title;
+ }
+
+ public function setTitle($title)
+ {
+ $this->title = $title;
+ }
+
+ public function getBody()
+ {
+ return $this->body;
+ }
+
+ public function setBody($body)
+ {
+ $this->body = $body;
+ }
+
+ /**
+ * Get id
+ *
+ * @return integer
+ */
+ public function getId()
+ {
+ return $this->id;
+ }
+
+ /**
+ * Set author
+ *
+ * @param First\GodBundle\Entity\User $author
+ */
+ public function setAuthor(\First\GodBundle\Entity\User $author)
+ {
+ $this->author = $author;
+ }
+
+ /**
+ * Get author
+ *
+ * @return First\GodBundle\Entity\User
+ */
+ public function getAuthor()
+ {
+ return $this->author;
+ }
+
+ /**
+ * Get comments
+ *
+ * @return Doctrine\Common\Collections\Collection
+ */
+ public function getComments()
+ {
+ return $this->comments;
+ }
+
+}
\ No newline at end of file
diff --git a/src/First/GodBundle/Entity/Product.php b/src/First/GodBundle/Entity/Product.php
new file mode 100644
index 0000000..2b0dcd0
--- /dev/null
+++ b/src/First/GodBundle/Entity/Product.php
@@ -0,0 +1,144 @@
+id;
+ }
+
+ /**
+ * Set name
+ *
+ * @param string $name
+ */
+ public function setName($name)
+ {
+ $this->name = $name;
+ }
+
+ /**
+ * Get name
+ *
+ * @return string
+ */
+ public function getName()
+ {
+ return $this->name;
+ }
+
+ /**
+ * Set price
+ *
+ * @param float $price
+ */
+ public function setPrice($price)
+ {
+ $this->price = $price;
+ }
+
+ /**
+ * Get price
+ *
+ * @return float
+ */
+ public function getPrice()
+ {
+ return $this->price;
+ }
+
+ /**
+ * Set description
+ *
+ * @param text $description
+ */
+ public function setDescription($description)
+ {
+ $this->description = $description;
+ }
+
+ /**
+ * Get description
+ *
+ * @return text
+ */
+ public function getDescription()
+ {
+ return $this->description;
+ }
+
+ /**
+ * Set category
+ *
+ * @param First\GodBundle\Entity\Category $category
+ */
+ public function setCategory(\First\GodBundle\Entity\Category $category)
+ {
+ $this->category = $category;
+ }
+
+ /**
+ * Get category
+ *
+ * @return First\GodBundle\Entity\Category
+ */
+ public function getCategory()
+ {
+ return $this->category;
+ }
+
+}
\ No newline at end of file
diff --git a/src/First/GodBundle/Entity/ProductRepository.php b/src/First/GodBundle/Entity/ProductRepository.php
new file mode 100644
index 0000000..645de75
--- /dev/null
+++ b/src/First/GodBundle/Entity/ProductRepository.php
@@ -0,0 +1,15 @@
+name = $name;
+ }
+
+ public function getName()
+ {
+ return $this->name;
+ }
+
+ public function setName($name)
+ {
+ $this->name = $name;
+ }
+
+ /**
+ * Get id
+ *
+ * @return integer
+ */
+ public function getId()
+ {
+ return $this->id;
+ }
+
+ /**
+ * Set date
+ *
+ * @param date $date
+ */
+ public function setDate($date)
+ {
+ $this->date = $date;
+ }
+
+ /**
+ * Get date
+ *
+ * @return date
+ */
+ public function getDate()
+ {
+ return $this->date;
+ }
+
+ /** @ORM\PrePersist */
+ public function setDateValue(\DateTime $date = null)
+ {
+ $this->date = $date; //可自动识别是date还是datetime类型
+ }
+
+}
\ No newline at end of file
diff --git a/src/First/GodBundle/FirstGodBundle.php b/src/First/GodBundle/FirstGodBundle.php
new file mode 100644
index 0000000..add1779
--- /dev/null
+++ b/src/First/GodBundle/FirstGodBundle.php
@@ -0,0 +1,9 @@
+add( 'name' )
+ ;
+ }
+
+ public function getDefaultOptions()
+ {
+ return array(
+ 'data_class' => 'First\GodBundle\Entity\Category',
+ );
+ }
+
+ public function getName()
+ {
+ return 'category';
+ }
+
+}
diff --git a/src/First/GodBundle/Form/ProductType.php b/src/First/GodBundle/Form/ProductType.php
new file mode 100644
index 0000000..da66eb4
--- /dev/null
+++ b/src/First/GodBundle/Form/ProductType.php
@@ -0,0 +1,33 @@
+add( 'name', null, array('label' => 'choose ur name') )
+ ->add( 'price', null, array('label' => 'choose ur price') )
+ ->add( 'description', null, array('label' => 'choose ur des') )
+ ->add( 'category', new CategoryType(), array('label' => 'choose ur category') )
+ ;
+ }
+
+ public function getDefaultOptions()
+ {
+ return array(
+ 'data_class' => 'First\GodBundle\Entity\Product',
+ );
+ }
+
+ public function getName()
+ {
+ return 'product';
+ }
+
+}
diff --git a/src/First/GodBundle/Form/UserType.php b/src/First/GodBundle/Form/UserType.php
new file mode 100644
index 0000000..b275a34
--- /dev/null
+++ b/src/First/GodBundle/Form/UserType.php
@@ -0,0 +1,31 @@
+add( 'name' )
+ ->add( 'date' )
+ ;
+ }
+
+ public function getDefaultOptions()
+ {
+ return array(
+ 'data_class' => 'First\GodBundle\Entity\User',
+ );
+ }
+
+ public function getName()
+ {
+ return 'user';
+ }
+
+}
diff --git a/src/First/GodBundle/Listener/AddCategoryByUser.php b/src/First/GodBundle/Listener/AddCategoryByUser.php
new file mode 100644
index 0000000..88acbee
--- /dev/null
+++ b/src/First/GodBundle/Listener/AddCategoryByUser.php
@@ -0,0 +1,33 @@
+getEntity();
+ $em = $args->getEntityManager();
+
+ if ($entity instanceof User)
+ {
+ $cat = new Category();
+ $cat->setName('监听器测试成功!');
+ $em->persist($cat);
+ $em->flush();
+ }
+ }
+
+}
+
+?>
\ No newline at end of file
diff --git a/src/First/GodBundle/Repository/PostRepository.php b/src/First/GodBundle/Repository/PostRepository.php
new file mode 100644
index 0000000..523ff8e
--- /dev/null
+++ b/src/First/GodBundle/Repository/PostRepository.php
@@ -0,0 +1,27 @@
+getEntityManager()->getRepository( 'FirstGodBundle:Post' )
+ ->createQueryBuilder( 'p' )
+ ->where( 'p.author > :author' )
+ ->setParameter( 'author', 19 )
+ ->orderBy( 'p.id', 'DESC' )
+ ->getQuery()
+ ->getArrayResult();
+ }
+
+}
\ No newline at end of file
diff --git a/src/First/GodBundle/Resources/config/routing.yml b/src/First/GodBundle/Resources/config/routing.yml
new file mode 100644
index 0000000..c65eb38
--- /dev/null
+++ b/src/First/GodBundle/Resources/config/routing.yml
@@ -0,0 +1,5 @@
+#-------------
+#God
+#-------------
+
+
diff --git a/src/First/GodBundle/Resources/config/services.yml b/src/First/GodBundle/Resources/config/services.yml
new file mode 100644
index 0000000..3a0b0c6
--- /dev/null
+++ b/src/First/GodBundle/Resources/config/services.yml
@@ -0,0 +1,7 @@
+parameters:
+# first_god.example.class: First\GodBundle\Example
+
+services:
+# first_god.example:
+# class: %first_god.example.class%
+# arguments: [@service_id, "plain_value", %parameter%]
diff --git a/src/First/GodBundle/Resources/doc/index.rst b/src/First/GodBundle/Resources/doc/index.rst
new file mode 100644
index 0000000..e69de29
diff --git a/src/First/GodBundle/Resources/translations/messages.fr.xliff b/src/First/GodBundle/Resources/translations/messages.fr.xliff
new file mode 100644
index 0000000..fd59e6c
--- /dev/null
+++ b/src/First/GodBundle/Resources/translations/messages.fr.xliff
@@ -0,0 +1,11 @@
+
+
+
+
+
+ Symfony2 is great
+ J'aime Symfony2
+
+
+
+
diff --git a/src/First/GodBundle/Resources/views/Form/fields.html.twig b/src/First/GodBundle/Resources/views/Form/fields.html.twig
new file mode 100644
index 0000000..1c93258
--- /dev/null
+++ b/src/First/GodBundle/Resources/views/Form/fields.html.twig
@@ -0,0 +1,10 @@
+
+{% block field_row %}
+{% spaceless %}
+
+ {{ form_label(form) }}
+ {{ form_errors(form) }}
+ {{ form_widget(form) }}
+
+{% endspaceless %}
+{% endblock field_row %}
\ No newline at end of file
diff --git a/src/First/GodBundle/Resources/views/Hello/index.html.twig b/src/First/GodBundle/Resources/views/Hello/index.html.twig
new file mode 100644
index 0000000..3d93b66
--- /dev/null
+++ b/src/First/GodBundle/Resources/views/Hello/index.html.twig
@@ -0,0 +1,43 @@
+{% extends '::base.html.twig' %}
+{% block body %}
+
+
+
+
+{% for i in 0..10 %}
+
+ haha
+
+{% endfor %}
+
+{% for user in users %}
+ NO.{{ user }}
+ {% else %}
+ no user available
+{% endfor %}
+
+{{ parent() }}
+
+{{ google_consumer_code }}
+
+{% endblock %}
+
+
diff --git a/src/First/GodBundle/Resources/views/Hello/new.html.twig b/src/First/GodBundle/Resources/views/Hello/new.html.twig
new file mode 100644
index 0000000..ddf2e08
--- /dev/null
+++ b/src/First/GodBundle/Resources/views/Hello/new.html.twig
@@ -0,0 +1,13 @@
+
+{% extends '::base.html.twig' %}
+
+{% block body %}
+
+
+
+{% endblock %}
\ No newline at end of file
diff --git a/src/First/GodBundle/Resources/views/User/edit.html.twig b/src/First/GodBundle/Resources/views/User/edit.html.twig
new file mode 100644
index 0000000..6be1057
--- /dev/null
+++ b/src/First/GodBundle/Resources/views/User/edit.html.twig
@@ -0,0 +1,22 @@
+User edit
+
+
+
+
diff --git a/src/First/GodBundle/Resources/views/User/index.html.twig b/src/First/GodBundle/Resources/views/User/index.html.twig
new file mode 100644
index 0000000..e72e619
--- /dev/null
+++ b/src/First/GodBundle/Resources/views/User/index.html.twig
@@ -0,0 +1,39 @@
+User list
+
+
+
+
+ Id |
+ Name |
+ Date |
+ Actions |
+
+
+
+ {% for entity in entities %}
+
+ {{ entity.id }} |
+ {{ entity.name }} |
+ {% if entity.date %}{{ entity.date|date('Y-m-d H:i:s') }}{% endif %} |
+
+
+ |
+
+ {% endfor %}
+
+
+
+
diff --git a/src/First/GodBundle/Resources/views/User/new.html.twig b/src/First/GodBundle/Resources/views/User/new.html.twig
new file mode 100644
index 0000000..3fe4af4
--- /dev/null
+++ b/src/First/GodBundle/Resources/views/User/new.html.twig
@@ -0,0 +1,16 @@
+User creation
+
+
+
+
diff --git a/src/First/GodBundle/Resources/views/User/show.html.twig b/src/First/GodBundle/Resources/views/User/show.html.twig
new file mode 100644
index 0000000..6917283
--- /dev/null
+++ b/src/First/GodBundle/Resources/views/User/show.html.twig
@@ -0,0 +1,37 @@
+User
+
+
+
+
+ Id |
+ {{ entity.id }} |
+
+
+ Name |
+ {{ entity.name }} |
+
+
+ Date |
+ {{ entity.date|date('Y-m-d H:i:s') }} |
+
+
+
+
+
diff --git a/src/First/GodBundle/Tests/Controller/DefaultControllerTest.php b/src/First/GodBundle/Tests/Controller/DefaultControllerTest.php
new file mode 100644
index 0000000..81136b1
--- /dev/null
+++ b/src/First/GodBundle/Tests/Controller/DefaultControllerTest.php
@@ -0,0 +1,17 @@
+request('GET', '/hello/Fabien');
+
+ $this->assertTrue($crawler->filter('html:contains("Hello Fabien")')->count() > 0);
+ }
+}
diff --git a/src/First/GodBundle/Tests/Controller/UserControllerTest.php b/src/First/GodBundle/Tests/Controller/UserControllerTest.php
new file mode 100644
index 0000000..2c94c18
--- /dev/null
+++ b/src/First/GodBundle/Tests/Controller/UserControllerTest.php
@@ -0,0 +1,54 @@
+request('GET', '/first_user/');
+ $this->assertTrue(200 === $client->getResponse()->getStatusCode());
+ $crawler = $client->click($crawler->selectLink('Create a new entry')->link());
+
+ // Fill in the form and submit it
+ $form = $crawler->selectButton('Create')->form(array(
+ 'user[field_name]' => 'Test',
+ // ... other fields to fill
+ ));
+
+ $client->submit($form);
+ $crawler = $client->followRedirect();
+
+ // Check data in the show view
+ $this->assertTrue($crawler->filter('td:contains("Test")')->count() > 0);
+
+ // Edit the entity
+ $crawler = $client->click($crawler->selectLink('Edit')->link());
+
+ $form = $crawler->selectButton('Edit')->form(array(
+ 'user[field_name]' => 'Foo',
+ // ... other fields to fill
+ ));
+
+ $client->submit($form);
+ $crawler = $client->followRedirect();
+
+ // Check the element contains an attribute with value equals "Foo"
+ $this->assertTrue($crawler->filter('[value="Foo"]')->count() > 0);
+
+ // Delete the entity
+ $client->submit($crawler->selectButton('Delete')->form());
+ $crawler = $client->followRedirect();
+
+ // Check the entity has been delete on the list
+ $this->assertNotRegExp('/Foo/', $client->getResponse()->getContent());
+ }
+ */
+}
\ No newline at end of file
diff --git a/src/First/HellBundle/Controller/DefaultController.php b/src/First/HellBundle/Controller/DefaultController.php
new file mode 100644
index 0000000..02d0a73
--- /dev/null
+++ b/src/First/HellBundle/Controller/DefaultController.php
@@ -0,0 +1,15 @@
+render('FirstHellBundle:Default:index.html.twig', array('name' => $name));
+ }
+}
diff --git a/src/First/HellBundle/DependencyInjection/Configuration.php b/src/First/HellBundle/DependencyInjection/Configuration.php
new file mode 100644
index 0000000..8057ee8
--- /dev/null
+++ b/src/First/HellBundle/DependencyInjection/Configuration.php
@@ -0,0 +1,29 @@
+root('first_hell');
+
+ // Here you should define the parameters that are allowed to
+ // configure your bundle. See the documentation linked above for
+ // more information on that topic.
+
+ return $treeBuilder;
+ }
+}
diff --git a/src/First/HellBundle/DependencyInjection/FirstHellExtension.php b/src/First/HellBundle/DependencyInjection/FirstHellExtension.php
new file mode 100644
index 0000000..e9c65b6
--- /dev/null
+++ b/src/First/HellBundle/DependencyInjection/FirstHellExtension.php
@@ -0,0 +1,28 @@
+processConfiguration($configuration, $configs);
+
+ $loader = new Loader\YamlFileLoader($container, new FileLocator(__DIR__.'/../Resources/config'));
+ $loader->load('services.yml');
+ }
+}
diff --git a/src/First/HellBundle/FirstHellBundle.php b/src/First/HellBundle/FirstHellBundle.php
new file mode 100644
index 0000000..4ca2d0c
--- /dev/null
+++ b/src/First/HellBundle/FirstHellBundle.php
@@ -0,0 +1,9 @@
+request('GET', '/hello/Fabien');
+
+ $this->assertTrue($crawler->filter('html:contains("Hello Fabien")')->count() > 0);
+ }
+}