Skip to content
This repository has been archived by the owner on Jan 29, 2020. It is now read-only.

Wrong namespace in "Introducing the Blog Module" #109

Closed
WinterSilence opened this issue Apr 21, 2019 · 8 comments · Fixed by #110
Closed

Wrong namespace in "Introducing the Blog Module" #109

WinterSilence opened this issue Apr 21, 2019 · 8 comments · Fixed by #110

Comments

@WinterSilence
Copy link

WinterSilence commented Apr 21, 2019

<h1>Blog\ListController::indexAction()</h1>

template page with Blog\ListController::indexAction() as the header

Missing directory Controller: Blog\Controller\ListController::indexAction.
Also i dont understand why classes use postfix Controller? Does using Blog\Controller\List add any problems?

/tutorials/in-depth-guide/first-module/

@michalbundyra
Copy link
Member

@WinterSilence

Also i dont understand why classes use postfix Controller? Does using Blog\Controller\List add any problems?

Yes. list is restricted word in PHP so you cannot define class with name List.
See:

@WinterSilence
Copy link
Author

WinterSilence commented Apr 21, 2019

@webimpress bad example for question :) Ok, take other controller: AlbumController in first tutorial too have postfix. It's no more readable or useful. What is postfix for?

@froschdesign
Copy link
Member

@WinterSilence

It's no more readable or useful.

The choice is yours: it's a framework, and you can choose the option that you prefer and that works for you.

One option is to create an alias:

use Album\Model\Album;
use Album\Controller\Album as AlbumController;

$model = new Album();
$controller = new AlbumController();

Or import the namespace:

use Album\Model\Album;
use Album\Controller;

$model = new Album();
$controller = new Controller\Album();

Or use a postifx:

use Album\Model\Album;
use Album\Controller\AlbumController;

$model = new Album();
$controller = new AlbumController();

@WinterSilence
Copy link
Author

WinterSilence commented Apr 21, 2019

@froschdesign

The choice is yours: it's a framework, and you can choose the option that you prefer and that works for you.

yes, but i cant find other cases in tutorials + I recently started learning ZF. I don't know what problems may arise in other cases. maybe its alias for extending in application/other modules :)

@WinterSilence
Copy link
Author

@weierophinney
Copy link
Member

@WinterSilence

We tend to use suffixes within the examples for several reasons:

  • When referring to the class later in the example, you can immediately grasp its context (controller, versus validator, versus data table gateway) without needing to look at the import statements.
  • When importing several classes related to the same domain, but different responsibilities within the domain, you will not need to alias (e.g., AlbumValidator vs AlbumTable vs AlbumController).
  • By having a suffix, you can group classes by domain instead of responsibility:
    Album/
        AlbumController.php
        AlbumTable.php
        AlbumValidator.php
    

As others have noted, you can achieve some of the same effects by using aliasing when importing classes.

Ultimately, the choice of how you organize the code is up to you and your team. Our goals in creating tutorials are to make clear what class does what, and we have chosen suffixing generally to meet that goal.

@WinterSilence
Copy link
Author

WinterSilence commented Apr 23, 2019

@weierophinney pls, add this at begin tutorials, because namespace Foo\Controller; class Album .. more readable and shorten than this way.

By having a suffix, you can group classes by domain instead of responsibility:

yes, but i cant see this in tutorials

Our goals in creating tutorials are to make clear what class does what, and we have chosen suffixing generally to meet that goal.

its not only tutorial practice

@WinterSilence
Copy link
Author

WinterSilence commented Apr 23, 2019

i try say: make tutorial more transparent for beginners. traditions are good, but without explanation they only lead to copying without understanding the meaning.

michalbundyra added a commit that referenced this issue Sep 4, 2019
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants