Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Training mahdy #3

Open
wants to merge 18 commits into
base: master
Choose a base branch
from
Open

Training mahdy #3

wants to merge 18 commits into from

Conversation

mohamedMahdyCc
Copy link
Collaborator

No description provided.

Copy link
Member

@zhibek zhibek left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is looking good overall!

I've listed some review points - I want you to check these, but mostly you're doing things the right way.

'orm_default' => [
// directory where proxies will be stored. By default, this is in
// the `data` directory of your application
'proxy_dir' => 'data/DoctrineORMModule/Proxy',
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's not mandatory to set this (system temporary directories are used by default, which have the correct permissions) and in our Docker environment we want to keep things simple.

When we do set paths in our config, we should use realpath(__DIR__ . ...) to make sure the path to the directory is correct regardless of how the application is run.

@@ -0,0 +1,269 @@
<?php
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Usually we'd .gitignore auto-generated files like this.

@@ -43,7 +43,7 @@
'not_found_template' => 'error/404',
'exception_template' => 'error/index',
'template_map' => [
'layout/layout' => __DIR__ . '/../view/layout/layout.phtml',
'layout/layout' => __DIR__ . '/../../../view/layout/layout.phtml',
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Generally we'll use the Application module to hold site-wide files (including the layout template, error templates, etc). There's no need to move the layout file out of the Application module.

],
],
'view_manager' => [
'display_not_found_reason' => true,
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There is no need to duplicate keys here that we already have declared in the Application module. The keys from config of each module get merged together (they're not kept separately for each module). This applies to most of the keys in this view_manager config - you should remove them all, apart from the ones which are specific to the Category module, such as the 3 template_map files and the template_path_stack (which is specific to the Category module as it uses __DIR__ to refer to the Category module directory).

{
private $entityManager;

public function __construct($serviceManager)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Rather than injecting the $serviceManager, you should inject directly the services you need - in this case $entityManager, although really you should create your own service in this module and inject that (with $entityManager injected into that service, instead of into this controller).

Injecting the $serviceManager is considered to be an anti-pattern.

Controller\ProductController::class => Controller\ProductControllerFactory::class,
],
],
'view_manager' => [
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

See review for module.config.php for Category module. We don't need to repeat keys that exist in the Application module as all modules configs are merged together.

@@ -0,0 +1,85 @@
<?php
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

See reviews for controllers in Category module.

@@ -0,0 +1,40 @@
<?php
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

See reviews in Category module - same issue applies here.

* @ORM\Column(type="integer")
* @var integer
*/
public $category_id;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Use camelCase ($categoryId) for Doctrine entity properties.

return $this->id;
}

public function setCategoryId($category_id)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Use camelcase ($categoryId) for arguments.

Copy link
Member

@zhibek zhibek left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Some more review points based on functional tests. Adding categories is working fine, but adding products is hitting an error.

// Fill in the form with POST data
$data = $this->params()->fromPost();
//var_dump($data); die;
$product->create($data);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm seeing a 500 error here when I run this. It appears the category isn't being set correctly.

'product-add-ajax' => [
'type' => Segment::class,
'options' => [
'route' => '/product/post',
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

To keep things simple/obvious, it's usually best to name routes and actions the same way (i.e. either use addAjax for both the route name and the action -or- us post for both the route name and the action, not a mix of both).

Sometimes we'll need to break this rule for SEO or other reasons, but this isn't one of those times.

@@ -0,0 +1 @@
chmod -Rf 777 data/DoctrineORMModule/Proxy
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Having a deploy.sh (or doctrine-init.sh) file to automate setup/deployment is good. But it makes sense to include everything that's needed to setup the system, so adding the following line would be good too:

vendor/bin/doctrine-module orm:schema-tool:update --force

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants