From 9efdc931860e8a05d5d8b9f6c97ab34e3bb47973 Mon Sep 17 00:00:00 2001 From: "mahmoud.hussien@camelcasetech.com" Date: Mon, 2 Jul 2018 15:33:39 +0200 Subject: [PATCH 1/5] Dummy Change --- README.md | 2 ++ 1 file changed, 2 insertions(+) diff --git a/README.md b/README.md index fceb16f..c265cc0 100644 --- a/README.md +++ b/README.md @@ -18,3 +18,5 @@ images it requires. For subsequent runs, the start up time should be much faster 3. View the test page: http://localhost:8080/ + +4. Dummy Chnage From 05a604eb45675be5c940c3a191c1989958f5d828 Mon Sep 17 00:00:00 2001 From: "mahmoud.hussien@camelcasetech.com" Date: Tue, 3 Jul 2018 19:55:01 +0200 Subject: [PATCH 2/5] create Category and Product Modules and set Doctrine and Entity --- Dockerfile | 1 + composer.json | 11 +- config/autoload/doctrine.docker.php | 18 +++ config/autoload/doctrine.global.php | 29 +++++ config/modules.config.php | 8 +- docker-compose.yml | 2 +- module/Category/config/module.config.php | 60 ++++++++++ .../src/Controller/CategoryController.php | 39 +++++++ module/Category/src/Entity/Category.php | 92 +++++++++++++++ module/Category/src/Model/Category.php | 22 ++++ module/Category/src/Module.php | 11 ++ .../Controller/CategoryControllerTest.php | 48 ++++++++ module/Product/config/module.config.php | 45 ++++++++ .../src/Controller/ProductController.php | 31 ++++++ module/Product/src/Entity/Product.php | 37 ++++++ module/Product/src/Module.php | 11 ++ module/Product/src/model/Product.php | 15 +++ .../test/Controller/ProductControllerTest.php | 48 ++++++++ view/category/index/index.phtml | 3 + view/category/index/new.phtml | 3 + view/error/404.phtml | 105 ++++++++++++++++++ view/error/index.phtml | 63 +++++++++++ view/layout/layout.phtml | 54 +++++++++ view/product/index/index.phtml | 3 + 24 files changed, 754 insertions(+), 5 deletions(-) create mode 100644 config/autoload/doctrine.docker.php create mode 100644 config/autoload/doctrine.global.php create mode 100644 module/Category/config/module.config.php create mode 100644 module/Category/src/Controller/CategoryController.php create mode 100644 module/Category/src/Entity/Category.php create mode 100644 module/Category/src/Model/Category.php create mode 100644 module/Category/src/Module.php create mode 100644 module/Category/test/Controller/CategoryControllerTest.php create mode 100644 module/Product/config/module.config.php create mode 100644 module/Product/src/Controller/ProductController.php create mode 100644 module/Product/src/Entity/Product.php create mode 100644 module/Product/src/Module.php create mode 100644 module/Product/src/model/Product.php create mode 100644 module/Product/test/Controller/ProductControllerTest.php create mode 100644 view/category/index/index.phtml create mode 100644 view/category/index/new.phtml create mode 100644 view/error/404.phtml create mode 100644 view/error/index.phtml create mode 100644 view/layout/layout.phtml create mode 100644 view/product/index/index.phtml diff --git a/Dockerfile b/Dockerfile index fae3669..82860ec 100644 --- a/Dockerfile +++ b/Dockerfile @@ -3,6 +3,7 @@ FROM php:7.0-apache RUN apt-get update \ && apt-get install -y git zlib1g-dev \ && docker-php-ext-install zip \ + && docker-php-ext-install pdo_mysql \ && a2enmod rewrite \ && sed -i 's!/var/www/html!/var/www/public!g' /etc/apache2/sites-available/000-default.conf \ && mv /var/www/html /var/www/public \ diff --git a/composer.json b/composer.json index a65fe86..f4b01f7 100644 --- a/composer.json +++ b/composer.json @@ -10,12 +10,16 @@ }, "autoload": { "psr-4": { - "Application\\": "module/Application/src/" + "Application\\": "module/Application/src/", + "Category\\": "module/Category/src/", + "Product\\": "module/Product/src/" } }, "autoload-dev": { "psr-4": { - "ApplicationTest\\": "module/Application/test/" + "ApplicationTest\\": "module/Application/test/", + "CategoryTest\\":"module/Category/test/", + "ProductTest\\":"module/Product/test/" } }, "extra": [], @@ -28,5 +32,8 @@ "phpunit/phpunit": "^6.5", "zendframework/zend-test": "^3.2", "squizlabs/php_codesniffer": "^3.3" + }, + "require": { + "doctrine/doctrine-orm-module": "^1.1" } } diff --git a/config/autoload/doctrine.docker.php b/config/autoload/doctrine.docker.php new file mode 100644 index 0000000..9bcb5f8 --- /dev/null +++ b/config/autoload/doctrine.docker.php @@ -0,0 +1,18 @@ + [ + 'connection' => [ + // default connection name + 'orm_default' => [ + 'driverClass' => \Doctrine\DBAL\Driver\PDOMySql\Driver::class, + 'params' => [ + 'host' => 'db', + 'port' => '3306', + 'user' => 'app', + 'password' => 'app', + 'dbname' => 'app', + ], + ], + ], +], +]; \ No newline at end of file diff --git a/config/autoload/doctrine.global.php b/config/autoload/doctrine.global.php new file mode 100644 index 0000000..eae2b82 --- /dev/null +++ b/config/autoload/doctrine.global.php @@ -0,0 +1,29 @@ + [ + 'driver' => [ + // defines an annotation driver, named `annotation_driver` + 'annotation_driver' => [ + 'class' => \Doctrine\ORM\Mapping\Driver\AnnotationDriver::class, + 'cache' => 'array', + 'paths' => [ + realpath(__DIR__ . '/../../module/Category/src/Entity'), + realpath(__DIR__ . '/../../module/Product/src/Entity'), + ], + ], + // default metadata driver, aggregates all other drivers into a single one. + // Override `orm_default` only if you know what you're doing + 'orm_default' => [ + 'drivers' => [ + // register `annotation_driver` for any entity under namespace `\Entity` + 'Category\Entity' => 'annotation_driver', + 'Product\Entity' => 'annotation_driver', + ], + ], + ], +], +]; \ No newline at end of file diff --git a/config/modules.config.php b/config/modules.config.php index 81b5749..e6eed7b 100644 --- a/config/modules.config.php +++ b/config/modules.config.php @@ -1,12 +1,16 @@ [ + 'aliases' => array( + 'category' => 'Category\Controller\CategoryController', + ), + 'factories' => array( + EntityManager::class => EntityManagerFactory::class, + ), + ], + 'router' => [ + 'routes' => [ + 'categories' => [ + 'type' => Segment::class, + 'options' => [ + 'route' => '/categories[/:action]', + 'defaults' => [ + 'controller' => Controller\CategoryController::class, + 'action' => 'index', + ], + ], + ], + + ], + ], + 'controllers' => [ + 'factories' => [ + Controller\CategoryController::class => InvokableFactory::class, + ], + ], + 'view_manager' => [ + 'display_not_found_reason' => true, + 'display_exceptions' => true, + 'doctype' => 'HTML5', + 'not_found_template' => 'error/404', + 'exception_template' => 'error/index', + 'template_map' => [ + 'layout/layout' => __DIR__ . '/../../../view/layout/layout.phtml', + 'category/category/index' => __DIR__ . '/../../../view/category/index/index.phtml', + 'category/category/new' => __DIR__ . '/../../../view/category/index/new.phtml', + 'category/category/edit' => __DIR__ . '/../../../view/category/index/edit.phtml', + 'category/category/show' => __DIR__ . '/../../../view/category/index/show.phtml', + 'category/category/delete' => __DIR__ . '/../../../view/category/index/delete.phtml', + 'error/404' => __DIR__ . '/../../../view/error/404.phtml', + 'error/index' => __DIR__ . '/../../../view/error/index.phtml', + ], + 'template_path_stack' => [ + __DIR__ . '/../view', + ], + ], +]; diff --git a/module/Category/src/Controller/CategoryController.php b/module/Category/src/Controller/CategoryController.php new file mode 100644 index 0000000..d350c33 --- /dev/null +++ b/module/Category/src/Controller/CategoryController.php @@ -0,0 +1,39 @@ +getCategories($serviceManager->get(EntityManager::class)); + return new ViewModel(); + } + public function editAction() + { + return new ViewModel(); + } + public function showAction() + { + return new ViewModel(); + } + public function deleteAction() + { + return new ViewModel(); + } +} diff --git a/module/Category/src/Entity/Category.php b/module/Category/src/Entity/Category.php new file mode 100644 index 0000000..557ac22 --- /dev/null +++ b/module/Category/src/Entity/Category.php @@ -0,0 +1,92 @@ +name = $name; + } + + /** + * @param string $description + */ + public function setDescription(string $description) + { + $this->description = $description; + } + + /** + * @param mixed $products + */ + public function setProducts($products) + { + $this->products = $products; + } + + /** + * @return string + */ + public function getName(): string + { + return $this->name; + } + + /** + * @return string + */ + public function getDescription(): string + { + return $this->description; + } + + /** + * @return int + */ + public function getId(): int + { + return $this->id; + } + + /** + * @return mixed + */ + public function getProducts() + { + return $this->products; + } +} \ No newline at end of file diff --git a/module/Category/src/Model/Category.php b/module/Category/src/Model/Category.php new file mode 100644 index 0000000..d91a9e3 --- /dev/null +++ b/module/Category/src/Model/Category.php @@ -0,0 +1,22 @@ +setName("dumy name"); + $categoryEntity->setDescription("dumy description"); + $entityManager->flush($categoryEntity); + } +} \ No newline at end of file diff --git a/module/Category/src/Module.php b/module/Category/src/Module.php new file mode 100644 index 0000000..a57301f --- /dev/null +++ b/module/Category/src/Module.php @@ -0,0 +1,11 @@ +setApplicationConfig(ArrayUtils::merge( + include __DIR__ . '/../../../../config/application.config.php', + $configOverrides + )); + + parent::setUp(); + } + + public function testIndexActionCanBeAccessed() + { + $this->dispatch('/', 'GET'); + $this->assertResponseStatusCode(200); + $this->assertModuleName('product'); + $this->assertControllerName(ProductController::class); // as specified in router's controller name alias + $this->assertControllerClass('ProductController'); + $this->assertMatchedRouteName('home'); + } + + public function testIndexActionViewModelTemplateRenderedWithinLayout() + { + $this->dispatch('/', 'GET'); + $this->assertQuery('.container .jumbotron'); + } + + public function testInvalidRouteDoesNotCrash() + { + $this->dispatch('/invalid/route', 'GET'); + $this->assertResponseStatusCode(404); + } +} diff --git a/module/Product/config/module.config.php b/module/Product/config/module.config.php new file mode 100644 index 0000000..202e3c3 --- /dev/null +++ b/module/Product/config/module.config.php @@ -0,0 +1,45 @@ + [ + 'routes' => [ + 'products' => [ + 'type' => Segment::class, + 'options' => [ + 'route' => '/products[/:action]', + 'defaults' => [ + 'controller' => \Product\Controller\ProductController::class, + 'action' => 'index', + ], + ], + ], + ], + ], + 'controllers' => [ + 'factories' => [ + \Product\Controller\ProductController::class => InvokableFactory::class, + ], + ], + 'view_manager' => [ + 'display_not_found_reason' => true, + 'display_exceptions' => true, + 'doctype' => 'HTML5', + 'not_found_template' => 'error/404', + 'exception_template' => 'error/index', + 'template_map' => [ + 'layout/layout' => __DIR__ . '/../../../view/layout/layout.phtml', + 'product/product/index' => __DIR__ . '/../../../view/product/index/index.phtml', + 'error/404' => __DIR__ . '/../../../view/error/404.phtml', + 'error/index' => __DIR__ . '/../../../view/error/index.phtml', + ], + 'template_path_stack' => [ + __DIR__ . '/../view', + ], + ], +]; diff --git a/module/Product/src/Controller/ProductController.php b/module/Product/src/Controller/ProductController.php new file mode 100644 index 0000000..65968bd --- /dev/null +++ b/module/Product/src/Controller/ProductController.php @@ -0,0 +1,31 @@ +setApplicationConfig(ArrayUtils::merge( + include __DIR__ . '/../../../../config/application.config.php', + $configOverrides + )); + + parent::setUp(); + } + + public function testIndexActionCanBeAccessed() + { + $this->dispatch('/', 'GET'); + $this->assertResponseStatusCode(200); + $this->assertModuleName('product'); + $this->assertControllerName(ProductController::class); // as specified in router's controller name alias + $this->assertControllerClass('ProductController'); + $this->assertMatchedRouteName('home'); + } + + public function testIndexActionViewModelTemplateRenderedWithinLayout() + { + $this->dispatch('/', 'GET'); + $this->assertQuery('.container .jumbotron'); + } + + public function testInvalidRouteDoesNotCrash() + { + $this->dispatch('/invalid/route', 'GET'); + $this->assertResponseStatusCode(404); + } +} diff --git a/view/category/index/index.phtml b/view/category/index/index.phtml new file mode 100644 index 0000000..e8c50a7 --- /dev/null +++ b/view/category/index/index.phtml @@ -0,0 +1,3 @@ +
+

Category Index

+
diff --git a/view/category/index/new.phtml b/view/category/index/new.phtml new file mode 100644 index 0000000..c0d9974 --- /dev/null +++ b/view/category/index/new.phtml @@ -0,0 +1,3 @@ +
+

Category new

+
diff --git a/view/error/404.phtml b/view/error/404.phtml new file mode 100644 index 0000000..1b4ebca --- /dev/null +++ b/view/error/404.phtml @@ -0,0 +1,105 @@ + +

A 404 error occurred

+

message ?>

+ +reason)) : + switch ($this->reason) { + case Application::ERROR_CONTROLLER_CANNOT_DISPATCH: + $reasonMessage = 'The requested controller was unable to dispatch the request.'; + break; + case Application::ERROR_MIDDLEWARE_CANNOT_DISPATCH: + $reasonMessage = 'The requested middleware was unable to dispatch the request.'; + break; + case Application::ERROR_CONTROLLER_NOT_FOUND: + $reasonMessage = 'The requested controller could not be mapped to an existing controller class.'; + break; + case Application::ERROR_CONTROLLER_INVALID: + $reasonMessage = 'The requested controller was not dispatchable.'; + break; + case Application::ERROR_ROUTER_NO_MATCH: + $reasonMessage = 'The requested URL could not be matched by routing.'; + break; + default: + $reasonMessage = 'We cannot determine at this time why a 404 was generated.'; + break; + } + ?> +

+ + +controller)) : ?> +
+
Controller:
+
+ escapeHtml($this->controller) ?> + controller_class) && $this->controller_class != $this->controller) { + printf('(resolves to %s)', $this->escapeHtml($this->controller_class)); + } + ?> +
+
+ + +display_exceptions)) : ?> + exception) + && ($this->exception instanceof \Exception || $this->exception instanceof \Error)) : ?> +
+ +

Additional information:

+

exception) ?>

+
+
File:
+
+
exception->getFile() ?>:exception->getLine() ?>
+
+
Message:
+
+
escapeHtml($this->exception->getMessage()) ?>
+
+
Stack trace:
+
+
escapeHtml($this->exception->getTraceAsString()) ?>
+
+
+ + exception->getPrevious()) : ?> +
+ +

Previous exceptions:

+ + + +

No Exception available

+ + diff --git a/view/error/index.phtml b/view/error/index.phtml new file mode 100644 index 0000000..1b28a21 --- /dev/null +++ b/view/error/index.phtml @@ -0,0 +1,63 @@ +

An error occurred

+

message ?>

+ +display_exceptions)) : ?> + exception) + && ($this->exception instanceof \Exception || $this->exception instanceof \Error)) : ?> +
+ +

Additional information:

+

exception) ?>

+
+
File:
+
+
exception->getFile() ?>:exception->getLine() ?>
+
+
Message:
+
+
escapeHtml($this->exception->getMessage()) ?>
+
+
Stack trace:
+
+
escapeHtml($this->exception->getTraceAsString()) ?>
+
+
+ + exception->getPrevious()) : ?> +
+ +

Previous exceptions:

+ + + +

No Exception available

+ + diff --git a/view/layout/layout.phtml b/view/layout/layout.phtml new file mode 100644 index 0000000..db661c8 --- /dev/null +++ b/view/layout/layout.phtml @@ -0,0 +1,54 @@ +doctype() ?> + + + + headTitle('Category')->setSeparator(' - ')->setAutoEscape(false) ?> + + headMeta() + ->appendName('viewport', 'width=device-width, initial-scale=1.0') + ->appendHttpEquiv('X-UA-Compatible', 'IE=edge') + ?> + + + headLink(['rel' => 'shortcut icon', 'type' => 'image/vnd.microsoft.icon', 'href' => $this->basePath() . '/img/favicon.ico']) + ->prependStylesheet($this->basePath('css/style.css')) + ->prependStylesheet($this->basePath('css/bootstrap-theme.min.css')) + ->prependStylesheet($this->basePath('css/bootstrap.min.css')) + ?> + + + headScript() + ->prependFile($this->basePath('js/bootstrap.min.js')) + ->prependFile($this->basePath('js/jquery-3.1.0.min.js')) + ?> + + + +
+ content ?> +
+ inlineScript() ?> + + diff --git a/view/product/index/index.phtml b/view/product/index/index.phtml new file mode 100644 index 0000000..4915e5d --- /dev/null +++ b/view/product/index/index.phtml @@ -0,0 +1,3 @@ +
+

Product Index

+
From e503f46ee4998ec83a479cdf872da28c51affbe6 Mon Sep 17 00:00:00 2001 From: "mahmoud.hussien@camelcasetech.com" Date: Wed, 4 Jul 2018 13:15:34 +0200 Subject: [PATCH 3/5] create instance from EntityManager and use it --- module/Category/config/module.config.php | 5 ++- .../src/Controller/CategoryController.php | 15 ++++++- .../Controller/CategoryControllerFactory.php | 40 +++++++++++++++++++ module/Category/src/Model/Category.php | 1 + 4 files changed, 57 insertions(+), 4 deletions(-) create mode 100644 module/Category/src/Controller/CategoryControllerFactory.php diff --git a/module/Category/config/module.config.php b/module/Category/config/module.config.php index 9f82ecd..11936b9 100644 --- a/module/Category/config/module.config.php +++ b/module/Category/config/module.config.php @@ -3,6 +3,7 @@ namespace Category; use Doctrine\ORM\EntityManager; +use DoctrineORMModule\Service\EntityManagerAliasCompatFactory; use DoctrineORMModule\Service\EntityManagerFactory; use Zend\Router\Http\Literal; use Zend\Router\Http\Segment; @@ -14,7 +15,7 @@ 'category' => 'Category\Controller\CategoryController', ), 'factories' => array( - EntityManager::class => EntityManagerFactory::class, + ), ], 'router' => [ @@ -34,7 +35,7 @@ ], 'controllers' => [ 'factories' => [ - Controller\CategoryController::class => InvokableFactory::class, + Controller\CategoryController::class => Controller\CategoryControllerFactory::class, ], ], 'view_manager' => [ diff --git a/module/Category/src/Controller/CategoryController.php b/module/Category/src/Controller/CategoryController.php index d350c33..a2bdab8 100644 --- a/module/Category/src/Controller/CategoryController.php +++ b/module/Category/src/Controller/CategoryController.php @@ -4,6 +4,7 @@ use Doctrine\ORM\EntityManager; use DoctrineORMModule\Service\EntityManagerFactory; +use Psr\Container\ContainerInterface; use Zend\Mvc\Controller\AbstractActionController; use Zend\ServiceManager\Factory\InvokableFactory; use Zend\ServiceManager\ServiceManager; @@ -11,6 +12,16 @@ use Category\Model\Category as CategoryModel; class CategoryController extends AbstractActionController { + /** + * Entity manager. + * @var Doctrine\ORM\EntityManager + */ + private $entityManager; + + public function __construct($entityManager) + { + $this->entityManager = $entityManager; + } public function indexAction() { $viewModel = new ViewModel(); @@ -19,9 +30,9 @@ public function indexAction() public function newAction() { - $serviceManager = new ServiceManager(); $categoryModel = new CategoryModel(); - //$categoryModel->getCategories($serviceManager->get(EntityManager::class)); + $categoryModel->getCategories($this->entityManager); + return new ViewModel(); } public function editAction() diff --git a/module/Category/src/Controller/CategoryControllerFactory.php b/module/Category/src/Controller/CategoryControllerFactory.php new file mode 100644 index 0000000..d94605c --- /dev/null +++ b/module/Category/src/Controller/CategoryControllerFactory.php @@ -0,0 +1,40 @@ +get('doctrine.entitymanager.orm_default'); + + // Instantiate the controller and inject dependencies + return new CategoryController($entityManager); + } +} \ No newline at end of file diff --git a/module/Category/src/Model/Category.php b/module/Category/src/Model/Category.php index d91a9e3..c40945a 100644 --- a/module/Category/src/Model/Category.php +++ b/module/Category/src/Model/Category.php @@ -17,6 +17,7 @@ public function getCategories(EntityManager $entityManager) $categoryEntity = new CategoryEntity(); $categoryEntity->setName("dumy name"); $categoryEntity->setDescription("dumy description"); + $entityManager->persist($categoryEntity); $entityManager->flush($categoryEntity); } } \ No newline at end of file From f39e5fe9a6ce3767797ddf8fb17ec7d7386b2803 Mon Sep 17 00:00:00 2001 From: "mahmoud.hussien@camelcasetech.com" Date: Wed, 4 Jul 2018 19:28:13 +0200 Subject: [PATCH 4/5] categories and proucts done except query relation --- config/autoload/docker.php | 9 +++ config/autoload/doctrine.global.php | 2 +- module/Category/config/module.config.php | 43 ++++++++++++- .../src/Controller/CategoryController.php | 47 ++++++++++---- .../Controller/CategoryControllerFactory.php | 9 ++- module/Category/src/Entity/Category.php | 8 +++ module/Category/src/Model/Category.php | 45 +++++++++++-- module/Product/config/module.config.php | 51 ++++++++++++++- .../src/Controller/ProductController.php | 51 +++++++++++++-- .../Controller/ProductControllerFactory.php | 40 ++++++++++++ module/Product/src/Entity/Product.php | 64 +++++++++++++++++++ module/Product/src/model/Product.php | 44 +++++++++++++ view/category/index/edit.phtml | 20 ++++++ view/category/index/index.phtml | 34 +++++++++- view/category/index/new.phtml | 19 +++++- view/category/index/show.phtml | 7 ++ view/product/index/edit.phtml | 20 ++++++ view/product/index/index.phtml | 34 +++++++++- view/product/index/new.phtml | 20 ++++++ view/product/index/show.phtml | 7 ++ 20 files changed, 539 insertions(+), 35 deletions(-) create mode 100644 module/Product/src/Controller/ProductControllerFactory.php create mode 100644 view/category/index/edit.phtml create mode 100644 view/category/index/show.phtml create mode 100644 view/product/index/edit.phtml create mode 100644 view/product/index/new.phtml create mode 100644 view/product/index/show.phtml diff --git a/config/autoload/docker.php b/config/autoload/docker.php index 2909593..c52c3be 100644 --- a/config/autoload/docker.php +++ b/config/autoload/docker.php @@ -2,9 +2,18 @@ /** * Docker Environment Configuration */ +use Zend\ServiceManager\Factory; return [ 'view_manager' => [ 'display_exceptions' => true, ], + 'service_manager' => [ + 'factories' => [ + 'stdClass' => InvokableFactory::class + ], + 'aliases' => [ + 'entityManager' => 'stdClass', + ] + ], ]; diff --git a/config/autoload/doctrine.global.php b/config/autoload/doctrine.global.php index eae2b82..331cb28 100644 --- a/config/autoload/doctrine.global.php +++ b/config/autoload/doctrine.global.php @@ -22,7 +22,7 @@ // register `annotation_driver` for any entity under namespace `\Entity` 'Category\Entity' => 'annotation_driver', 'Product\Entity' => 'annotation_driver', - ], + ] , ], ], ], diff --git a/module/Category/config/module.config.php b/module/Category/config/module.config.php index 11936b9..afcf260 100644 --- a/module/Category/config/module.config.php +++ b/module/Category/config/module.config.php @@ -23,14 +23,53 @@ 'categories' => [ 'type' => Segment::class, 'options' => [ - 'route' => '/categories[/:action]', + 'route' => '/categories', 'defaults' => [ 'controller' => Controller\CategoryController::class, 'action' => 'index', ], ], ], - + 'createCategories' => [ + 'type' => Segment::class, + 'options' => [ + 'route' => '/categories/new', + 'defaults' => [ + 'controller' => Controller\CategoryController::class, + 'action' => 'new', + ], + ], + ], + 'editCategories' => [ + 'type' => Segment::class, + 'options' => [ + 'route' => '/categories/edit/[:id]', + 'defaults' => [ + 'controller' => Controller\CategoryController::class, + 'action' => 'edit', + ], + ], + ], + 'showCategory' => [ + 'type' => Segment::class, + 'options' => [ + 'route' => '/categories/show/[:id]', + 'defaults' => [ + 'controller' => Controller\CategoryController::class, + 'action' => 'show', + ], + ], + ], + 'deleteCategory' => [ + 'type' => Segment::class, + 'options' => [ + 'route' => '/categories/delete/[:id]', + 'defaults' => [ + 'controller' => Controller\CategoryController::class, + 'action' => 'delete', + ], + ], + ], ], ], 'controllers' => [ diff --git a/module/Category/src/Controller/CategoryController.php b/module/Category/src/Controller/CategoryController.php index a2bdab8..30a9107 100644 --- a/module/Category/src/Controller/CategoryController.php +++ b/module/Category/src/Controller/CategoryController.php @@ -2,12 +2,9 @@ namespace Category\Controller; +use Category\Model\Category; use Doctrine\ORM\EntityManager; -use DoctrineORMModule\Service\EntityManagerFactory; -use Psr\Container\ContainerInterface; use Zend\Mvc\Controller\AbstractActionController; -use Zend\ServiceManager\Factory\InvokableFactory; -use Zend\ServiceManager\ServiceManager; use Zend\View\Model\ViewModel; use Category\Model\Category as CategoryModel; class CategoryController extends AbstractActionController @@ -18,33 +15,57 @@ class CategoryController extends AbstractActionController */ private $entityManager; - public function __construct($entityManager) + public function __construct($serviceManager) { - $this->entityManager = $entityManager; + $this->entityManager = $serviceManager->get(EntityManager::class); } + public function indexAction() { - $viewModel = new ViewModel(); - return new $viewModel; + $categoryModel = new CategoryModel($this->entityManager); + $categories = $categoryModel->getCategories(); + return new ViewModel(["categories"=>$categories]); } public function newAction() { - $categoryModel = new CategoryModel(); - $categoryModel->getCategories($this->entityManager); + if ($this->getRequest()->isPost()){ + $data = $this->params()->fromPost(); + $categoryModel = new CategoryModel($this->entityManager); + $categoryModel->createCategory($data["name"], $data["description"]); + $this->redirect()->toUrl("/categories"); + } return new ViewModel(); } public function editAction() { - return new ViewModel(); + $id = $this->params("id"); + $categoryModel = new CategoryModel($this->entityManager); + $categoryEntity = $categoryModel->getCategory($id); + if ($this->getRequest()->isPost()) { + $data = $this->params()->fromPost(); + $categoryModel->editCategory($id, $data["name"], $data["description"]); + $this->redirect()->toUrl("/categories"); + } + return new ViewModel(["category"=>$categoryEntity]); } public function showAction() { - return new ViewModel(); + $id = $this->params("id"); + + $categoryModel = new CategoryModel($this->entityManager); + $categoryEntity = $categoryModel->getCategory($id); + + return new ViewModel(["category"=>$categoryEntity]); } public function deleteAction() { - return new ViewModel(); + $id = $this->params("id"); + + $categoryModel = new CategoryModel($this->entityManager); + $categoryEntity = $categoryModel->deleteCategory($id); + + $this->redirect()->toUrl("/categories"); } } diff --git a/module/Category/src/Controller/CategoryControllerFactory.php b/module/Category/src/Controller/CategoryControllerFactory.php index d94605c..1236cb3 100644 --- a/module/Category/src/Controller/CategoryControllerFactory.php +++ b/module/Category/src/Controller/CategoryControllerFactory.php @@ -32,9 +32,14 @@ class CategoryControllerFactory implements FactoryInterface */ public function __invoke(ContainerInterface $container, $requestedName, array $options = null) { - $entityManager = $container->get('doctrine.entitymanager.orm_default'); + +// $entityManager = $container->get('doctrine.entitymanager.orm_default'); +// var_dump(get_class($entityManager));exit; // Instantiate the controller and inject dependencies - return new CategoryController($entityManager); + return new CategoryController($container); +// $service = (null === $options) ? new $requestedName : new $requestedName($options); +// return $service->setServiceManager($container); + } } \ No newline at end of file diff --git a/module/Category/src/Entity/Category.php b/module/Category/src/Entity/Category.php index 557ac22..698172e 100644 --- a/module/Category/src/Entity/Category.php +++ b/module/Category/src/Entity/Category.php @@ -50,6 +50,14 @@ public function setDescription(string $description) $this->description = $description; } + /** + * @param int $id + */ + public function setId(int $id) + { + $this->id = $id; + } + /** * @param mixed $products */ diff --git a/module/Category/src/Model/Category.php b/module/Category/src/Model/Category.php index c40945a..eeecf70 100644 --- a/module/Category/src/Model/Category.php +++ b/module/Category/src/Model/Category.php @@ -12,12 +12,47 @@ class Category { - public function getCategories(EntityManager $entityManager) + private $entityManager; + + public function __construct(EntityManager $entityManager) + { + $this->entityManager = $entityManager; + } + + public function createCategory($name, $description) + { + $categoryEntity = new CategoryEntity(); + $categoryEntity->setName($name); + $categoryEntity->setDescription($description); + + $this->entityManager->persist($categoryEntity); + $this->entityManager->flush($categoryEntity); + } + + public function editCategory($id, $name, $description) { $categoryEntity = new CategoryEntity(); - $categoryEntity->setName("dumy name"); - $categoryEntity->setDescription("dumy description"); - $entityManager->persist($categoryEntity); - $entityManager->flush($categoryEntity); + $categoryEntity->setId($id); + $categoryEntity->setName($name); + $categoryEntity->setDescription($description); + $this->entityManager->merge($categoryEntity); + $this->entityManager->flush(); + } + + public function getCategories() + { + return $this->entityManager->getRepository(CategoryEntity::class)->findAll(); + } + + public function getCategory($id) + { + return $this->entityManager->find(CategoryEntity::class, $id); + } + + public function deleteCategory($id) + { + $categoryEntity = $this->entityManager->find(CategoryEntity::class, $id); + $this->entityManager->remove($categoryEntity); + $this->entityManager->flush(); } } \ No newline at end of file diff --git a/module/Product/config/module.config.php b/module/Product/config/module.config.php index 202e3c3..6e059fb 100644 --- a/module/Product/config/module.config.php +++ b/module/Product/config/module.config.php @@ -7,23 +7,64 @@ use Zend\ServiceManager\Factory\InvokableFactory; return [ + 'router' => [ 'routes' => [ 'products' => [ 'type' => Segment::class, 'options' => [ - 'route' => '/products[/:action]', + 'route' => '/products', 'defaults' => [ - 'controller' => \Product\Controller\ProductController::class, + 'controller' => Controller\ProductController::class, 'action' => 'index', ], ], ], + 'createProducts' => [ + 'type' => Segment::class, + 'options' => [ + 'route' => '/products/new', + 'defaults' => [ + 'controller' => Controller\ProductController::class, + 'action' => 'new', + ], + ], + ], + 'editProducts' => [ + 'type' => Segment::class, + 'options' => [ + 'route' => '/products/edit/[:id]', + 'defaults' => [ + 'controller' => Controller\ProductController::class, + 'action' => 'edit', + ], + ], + ], + 'showProduct' => [ + 'type' => Segment::class, + 'options' => [ + 'route' => '/products/show/[:id]', + 'defaults' => [ + 'controller' => Controller\ProductController::class, + 'action' => 'show', + ], + ], + ], + 'deleteProduct' => [ + 'type' => Segment::class, + 'options' => [ + 'route' => '/products/delete/[:id]', + 'defaults' => [ + 'controller' => Controller\ProductController::class, + 'action' => 'delete', + ], + ], + ], ], ], 'controllers' => [ 'factories' => [ - \Product\Controller\ProductController::class => InvokableFactory::class, + Controller\ProductController::class => Controller\ProductControllerFactory::class, ], ], 'view_manager' => [ @@ -35,6 +76,10 @@ 'template_map' => [ 'layout/layout' => __DIR__ . '/../../../view/layout/layout.phtml', 'product/product/index' => __DIR__ . '/../../../view/product/index/index.phtml', + 'product/product/new' => __DIR__ . '/../../../view/product/index/new.phtml', + 'product/product/edit' => __DIR__ . '/../../../view/product/index/edit.phtml', + 'product/product/show' => __DIR__ . '/../../../view/product/index/show.phtml', + 'product/product/delete' => __DIR__ . '/../../../view/product/index/delete.phtml', 'error/404' => __DIR__ . '/../../../view/error/404.phtml', 'error/index' => __DIR__ . '/../../../view/error/index.phtml', ], diff --git a/module/Product/src/Controller/ProductController.php b/module/Product/src/Controller/ProductController.php index 65968bd..13f2db1 100644 --- a/module/Product/src/Controller/ProductController.php +++ b/module/Product/src/Controller/ProductController.php @@ -2,30 +2,69 @@ namespace Product\Controller; +use Category\Model\Category as CategoryModel; use Zend\Mvc\Controller\AbstractActionController; use Zend\View\Model\ViewModel; - +use Doctrine\ORM\EntityManager; +use Product\model\Product as ProductModel; class ProductController extends AbstractActionController { + /** + * Entity manager. + * @var Doctrine\ORM\EntityManager + */ + private $entityManager; + + public function __construct($serviceManager) + { + $this->entityManager = $serviceManager->get(EntityManager::class); + } public function indexAction() { - return new ViewModel(); + $productModel = new ProductModel($this->entityManager); + $products = $productModel->getProducts(); + return new ViewModel(["products"=>$products]); } public function newAction() { - return new ViewModel(); + if ($this->getRequest()->isPost()){ + $data = $this->params()->fromPost(); + $productModel = new ProductModel($this->entityManager); + $productModel->createProduct($data["name"], $data["description"]); + $this->redirect()->toUrl("/products"); + } + $categoryModel = new CategoryModel($this->entityManager); + return new ViewModel(["categories" => $categoryModel->getCategories()]); } public function editAction() { - return new ViewModel(); + $id = $this->params("id"); + $productModel = new ProductModel($this->entityManager); + $productEntity = $productModel->getProduct($id); + if ($this->getRequest()->isPost()) { + $data = $this->params()->fromPost(); + $productModel->editProduct($id, $data["name"], $data["description"]); + $this->redirect()->toUrl("/products"); + } + return new ViewModel(["product"=>$productEntity]); } public function showAction() { - return new ViewModel(); + $id = $this->params("id"); + + $productModel = new ProductModel($this->entityManager); + $productEntity = $productModel->getProduct($id); + + return new ViewModel(["product"=>$productEntity]); } public function deleteAction() { - return new ViewModel(); + $id = $this->params("id"); + + $productModel = new ProductModel($this->entityManager); + $productEntity = $productModel->deleteProduct($id); + + $this->redirect()->toUrl("/products"); } } diff --git a/module/Product/src/Controller/ProductControllerFactory.php b/module/Product/src/Controller/ProductControllerFactory.php new file mode 100644 index 0000000..3e5b6b9 --- /dev/null +++ b/module/Product/src/Controller/ProductControllerFactory.php @@ -0,0 +1,40 @@ +get('doctrine.entitymanager.orm_default'); +// var_dump(get_class($entityManager));exit; + // Instantiate the controller and inject dependencies + return new ProductController($container); +// $service = (null === $options) ? new $requestedName : new $requestedName($options); +// return $service->setServiceManager($container); + + } +} \ No newline at end of file diff --git a/module/Product/src/Entity/Product.php b/module/Product/src/Entity/Product.php index 76c82e4..9c69d6f 100644 --- a/module/Product/src/Entity/Product.php +++ b/module/Product/src/Entity/Product.php @@ -34,4 +34,68 @@ class Product * @ORM\JoinColumn(name="category_id", referencedColumnName="id") */ private $category; + + /** + * @param string $name + */ + public function setName(string $name) + { + $this->name = $name; + } + + /** + * @param string $description + */ + public function setDescription(string $description) + { + $this->description = $description; + } + + /** + * @param int $id + */ + public function setId(int $id) + { + $this->id = $id; + } + + /** + * @param mixed $category + */ + public function setCategory($category) + { + $this->category = $category; + } + + /** + * @return string + */ + public function getName(): string + { + return $this->name; + } + + /** + * @return string + */ + public function getDescription(): string + { + return $this->description; + } + + /** + * @return int + */ + public function getId(): int + { + return $this->id; + } + + /** + * @return mixed + */ + public function getCategory() + { + return $this->category; + } } \ No newline at end of file diff --git a/module/Product/src/model/Product.php b/module/Product/src/model/Product.php index 2503717..82f10e4 100644 --- a/module/Product/src/model/Product.php +++ b/module/Product/src/model/Product.php @@ -9,7 +9,51 @@ namespace Product\model; +use Doctrine\ORM\EntityManager; +use Product\Entity\Product as ProductEntity; class Product { + private $entityManager; + public function __construct(EntityManager $entityManager) + { + $this->entityManager = $entityManager; + } + + public function createProduct($name, $description) + { + $productEntity = new ProductEntity(); + $productEntity->setName($name); + $productEntity->setDescription($description); + + $this->entityManager->persist($productEntity); + $this->entityManager->flush($productEntity); + } + + public function editProduct($id, $name, $description) + { + $productEntity = new ProductEntity(); + $productEntity->setId($id); + $productEntity->setName($name); + $productEntity->setDescription($description); + $this->entityManager->merge($productEntity); + $this->entityManager->flush(); + } + + public function getProducts() + { + return $this->entityManager->getRepository(ProductEntity::class)->findAll(); + } + + public function getProduct($id) + { + return $this->entityManager->find(ProductEntity::class, $id); + } + + public function deleteProduct($id) + { + $productEntity = $this->entityManager->find(ProductEntity::class, $id); + $this->entityManager->remove($productEntity); + $this->entityManager->flush(); + } } \ No newline at end of file diff --git a/view/category/index/edit.phtml b/view/category/index/edit.phtml new file mode 100644 index 0000000..411350d --- /dev/null +++ b/view/category/index/edit.phtml @@ -0,0 +1,20 @@ +
+

Edit Category

+
+
+
+
+ + +
+ +
+ + +
+ +
+ +
+
+
diff --git a/view/category/index/index.phtml b/view/category/index/index.phtml index e8c50a7..2725cfa 100644 --- a/view/category/index/index.phtml +++ b/view/category/index/index.phtml @@ -1,3 +1,35 @@
-

Category Index

+

Categories

+
+ Create New Category +
+
+ + + + + + + + + + "; + echo ""; + echo ""; + echo ""; + echo ""; + } + ?> + +
NameDescriptionAction
".$category->getName()."".$category->getDescription()." show "; + echo " edit "; + echo " delete ". + "
+
\ No newline at end of file diff --git a/view/category/index/new.phtml b/view/category/index/new.phtml index c0d9974..a718810 100644 --- a/view/category/index/new.phtml +++ b/view/category/index/new.phtml @@ -1,3 +1,20 @@
-

Category new

+

Create New Category

+
+
+
+
+ + +
+ +
+ + +
+ +
+ +
+
diff --git a/view/category/index/show.phtml b/view/category/index/show.phtml new file mode 100644 index 0000000..90b6dd2 --- /dev/null +++ b/view/category/index/show.phtml @@ -0,0 +1,7 @@ +
+

getName(); ?> Category

+
+
+
getDescription(); ?>
+ Edit this Category +
diff --git a/view/product/index/edit.phtml b/view/product/index/edit.phtml new file mode 100644 index 0000000..94e070f --- /dev/null +++ b/view/product/index/edit.phtml @@ -0,0 +1,20 @@ +
+

Edit Product

+
+
+
+
+ + +
+ +
+ + +
+ +
+ +
+
+
diff --git a/view/product/index/index.phtml b/view/product/index/index.phtml index 4915e5d..8d1ebbf 100644 --- a/view/product/index/index.phtml +++ b/view/product/index/index.phtml @@ -1,3 +1,35 @@
-

Product Index

+

Products

+
+ Create New Product +
+
+ + + + + + + + + + "; + echo ""; + echo ""; + echo ""; + echo ""; + } + ?> + +
NameDescriptionAction
".$product->getName()."".$product->getDescription()." show "; + echo " edit "; + echo " delete ". + "
+
\ No newline at end of file diff --git a/view/product/index/new.phtml b/view/product/index/new.phtml new file mode 100644 index 0000000..40e1ca1 --- /dev/null +++ b/view/product/index/new.phtml @@ -0,0 +1,20 @@ +
+

Create New Product

+
+
+
+
+ + +
+ +
+ + +
+ +
+ +
+
+
diff --git a/view/product/index/show.phtml b/view/product/index/show.phtml new file mode 100644 index 0000000..8ee7217 --- /dev/null +++ b/view/product/index/show.phtml @@ -0,0 +1,7 @@ +
+

getName(); ?> Product

+
+
+
getDescription(); ?>
+ Edit this Product +
From e9c8661b595af5b7a7cce5659cc95b0f2f5ce439 Mon Sep 17 00:00:00 2001 From: "mahmoud.hussien@camelcasetech.com" Date: Thu, 5 Jul 2018 19:22:44 +0200 Subject: [PATCH 5/5] relation done --- config/autoload/doctrine.docker.php | 6 ++++ deploy.sh | 1 + .../src/Controller/CategoryController.php | 6 +++- .../src/Controller/ProductController.php | 9 +++-- module/Product/src/Entity/Product.php | 21 +++++++++++ module/Product/src/model/Product.php | 20 ++++++++--- view/category/index/edit.phtml | 2 +- view/category/index/index.phtml | 4 +-- view/category/index/new.phtml | 2 +- view/category/index/show.phtml | 36 +++++++++++++++++-- view/product/index/edit.phtml | 22 +++++++++++- view/product/index/index.phtml | 8 +++-- view/product/index/new.phtml | 19 ++++++++-- view/product/index/show.phtml | 6 ++-- 14 files changed, 140 insertions(+), 22 deletions(-) create mode 100755 deploy.sh diff --git a/config/autoload/doctrine.docker.php b/config/autoload/doctrine.docker.php index 9bcb5f8..1fd9dcb 100644 --- a/config/autoload/doctrine.docker.php +++ b/config/autoload/doctrine.docker.php @@ -1,6 +1,12 @@ [ + 'configuration' => [ + 'orm_default' => [ + 'proxy_dir' => __DIR__.'/../../data/DoctrineORMModule/Proxy', + 'proxy_namespace' => 'DoctrineORMModule\Proxy', + ] + ], 'connection' => [ // default connection name 'orm_default' => [ diff --git a/deploy.sh b/deploy.sh new file mode 100755 index 0000000..6d2f36c --- /dev/null +++ b/deploy.sh @@ -0,0 +1 @@ +chmod -Rf 777 data/DoctrineORMModule/Proxy \ No newline at end of file diff --git a/module/Category/src/Controller/CategoryController.php b/module/Category/src/Controller/CategoryController.php index 30a9107..3393859 100644 --- a/module/Category/src/Controller/CategoryController.php +++ b/module/Category/src/Controller/CategoryController.php @@ -4,6 +4,7 @@ use Category\Model\Category; use Doctrine\ORM\EntityManager; +use Product\model\Product as ProductModel; use Zend\Mvc\Controller\AbstractActionController; use Zend\View\Model\ViewModel; use Category\Model\Category as CategoryModel; @@ -55,9 +56,12 @@ public function showAction() $id = $this->params("id"); $categoryModel = new CategoryModel($this->entityManager); + $productModel = new ProductModel($this->entityManager); + $categoryEntity = $categoryModel->getCategory($id); + $productEntities = $productModel->getProductsByCategory($id); - return new ViewModel(["category"=>$categoryEntity]); + return new ViewModel(["category"=>$categoryEntity, "products"=>$productEntities]); } public function deleteAction() { diff --git a/module/Product/src/Controller/ProductController.php b/module/Product/src/Controller/ProductController.php index 13f2db1..82c9a07 100644 --- a/module/Product/src/Controller/ProductController.php +++ b/module/Product/src/Controller/ProductController.php @@ -31,7 +31,7 @@ public function newAction() if ($this->getRequest()->isPost()){ $data = $this->params()->fromPost(); $productModel = new ProductModel($this->entityManager); - $productModel->createProduct($data["name"], $data["description"]); + $productModel->createProduct($data["name"], $data["description"], $data["price"], $data["category"]); $this->redirect()->toUrl("/products"); } $categoryModel = new CategoryModel($this->entityManager); @@ -44,10 +44,13 @@ public function editAction() $productEntity = $productModel->getProduct($id); if ($this->getRequest()->isPost()) { $data = $this->params()->fromPost(); - $productModel->editProduct($id, $data["name"], $data["description"]); + $productModel->editProduct($id, $data["name"], $data["description"], $data["price"], $data["category"]); $this->redirect()->toUrl("/products"); } - return new ViewModel(["product"=>$productEntity]); + $categoryModel = new CategoryModel($this->entityManager); + return new ViewModel([ + "product"=>$productEntity, + "categories" => $categoryModel->getCategories()]); } public function showAction() { diff --git a/module/Product/src/Entity/Product.php b/module/Product/src/Entity/Product.php index 9c69d6f..065149f 100644 --- a/module/Product/src/Entity/Product.php +++ b/module/Product/src/Entity/Product.php @@ -29,6 +29,11 @@ class Product * @var string */ private $description; + /** + * @ORM\Column(type="float"); + * @var float + */ + private $price; /** * @ORM\ManyToOne(targetEntity="Category\Entity\Category", inversedBy="products") * @ORM\JoinColumn(name="category_id", referencedColumnName="id") @@ -51,6 +56,14 @@ public function setDescription(string $description) $this->description = $description; } + /** + * @param float $price + */ + public function setPrice(float $price) + { + $this->price = $price; + } + /** * @param int $id */ @@ -83,6 +96,14 @@ public function getDescription(): string return $this->description; } + /** + * @return float + */ + public function getPrice(): float + { + return $this->price; + } + /** * @return int */ diff --git a/module/Product/src/model/Product.php b/module/Product/src/model/Product.php index 82f10e4..6cf4932 100644 --- a/module/Product/src/model/Product.php +++ b/module/Product/src/model/Product.php @@ -11,6 +11,7 @@ use Doctrine\ORM\EntityManager; use Product\Entity\Product as ProductEntity; +use Category\Entity\Category as CategoryEntity; class Product { private $entityManager; @@ -20,29 +21,35 @@ public function __construct(EntityManager $entityManager) $this->entityManager = $entityManager; } - public function createProduct($name, $description) + public function createProduct($name, $description, $price, $categoryId) { + $category = $this->entityManager->find(CategoryEntity::class, $categoryId); $productEntity = new ProductEntity(); $productEntity->setName($name); + $productEntity->setPrice($price); $productEntity->setDescription($description); - + $productEntity->setCategory($category); $this->entityManager->persist($productEntity); $this->entityManager->flush($productEntity); } - public function editProduct($id, $name, $description) + public function editProduct($id, $name, $description, $price, $categoryId) { + $category = $this->entityManager->find(CategoryEntity::class, $categoryId); $productEntity = new ProductEntity(); $productEntity->setId($id); $productEntity->setName($name); + $productEntity->setPrice($price); $productEntity->setDescription($description); + $productEntity->setCategory($category); $this->entityManager->merge($productEntity); $this->entityManager->flush(); } public function getProducts() { - return $this->entityManager->getRepository(ProductEntity::class)->findAll(); + $categories = $this->entityManager->getRepository(ProductEntity::class)->findAll(); + return $categories; } public function getProduct($id) @@ -50,6 +57,11 @@ public function getProduct($id) return $this->entityManager->find(ProductEntity::class, $id); } + public function getProductsByCategory($id) + { + return $this->entityManager->getRepository(ProductEntity::class)->findBy(["category" => $id]); + } + public function deleteProduct($id) { $productEntity = $this->entityManager->find(ProductEntity::class, $id); diff --git a/view/category/index/edit.phtml b/view/category/index/edit.phtml index 411350d..2d6f35c 100644 --- a/view/category/index/edit.phtml +++ b/view/category/index/edit.phtml @@ -1,5 +1,5 @@
-

Edit Category

+

Edit Category

diff --git a/view/category/index/index.phtml b/view/category/index/index.phtml index 2725cfa..e641646 100644 --- a/view/category/index/index.phtml +++ b/view/category/index/index.phtml @@ -1,5 +1,5 @@
-

Categories

+

Categories

Create New Category @@ -21,7 +21,7 @@ echo "".$category->getName().""; echo "".$category->getDescription().""; echo " show "; + "'> show "; echo " edit "; echo "getId() ?>' class="btn btn-success">Edit this Category + Edit this Category +

Our Products

+ + + + + + + + + + + + "; + echo ""; + echo ""; + echo ""; + echo ""; + echo ""; + echo ""; + } + ?> + +
NamePriceDescriptionCategoryAction
".$product->getName()."".$product->getPrice()."".$product->getDescription()."".$product->getCategory()->getName()." show "; + echo " edit "; + echo " Remove from Category ". + "
diff --git a/view/product/index/edit.phtml b/view/product/index/edit.phtml index 94e070f..313f193 100644 --- a/view/product/index/edit.phtml +++ b/view/product/index/edit.phtml @@ -1,5 +1,5 @@
-

Edit Product

+

Edit Product

@@ -12,7 +12,27 @@
+
+ + +
+
+ + +
diff --git a/view/product/index/index.phtml b/view/product/index/index.phtml index 8d1ebbf..15c4aae 100644 --- a/view/product/index/index.phtml +++ b/view/product/index/index.phtml @@ -1,5 +1,5 @@
-

Products

+

Products

Create New Product @@ -9,7 +9,9 @@ Name + Price Description + Category Action @@ -19,9 +21,11 @@ { echo ""; echo "".$product->getName().""; + echo "".$product->getPrice().""; echo "".$product->getDescription().""; + echo "".$product->getCategory()->getName().""; echo " show "; + "'> show "; echo " edit "; echo "getId()."'>".$category->getName().""; + } + ?> + +
diff --git a/view/product/index/show.phtml b/view/product/index/show.phtml index 8ee7217..69a553e 100644 --- a/view/product/index/show.phtml +++ b/view/product/index/show.phtml @@ -1,7 +1,9 @@
-

getName(); ?> Product

+

getName(); ?>