« first day    last day (37 days later) » 

12:03 AM
For example:
this link:
This author it seems is famouse because now it teaches online in udemy, but I hate his sample project,.. for example at first he creates one DBConnection at each Model (or Mapper) class. Then he retracts, and creates the DBConnection inside the constructor of "each" Controller and then passing the DBConn in each time he instantiates each Model in each method (he creates the same Model in each method, that's horrible!!).
Besides these points, he mixes Entity with Model, all of them accesing the DB (Horrible!!!)
:(
 
12:18 AM
This is my introduction of myself, I am just starting, so many questions to do... I have my project and I've started creating my config.php (DB settings), my Mappers (CRUD, passing in the constructor the DBConn object), my Entities (only properties mapping the corresponding table columns names),
and starting coding my Services (passing in the constructor the Mappers instances the service will use in the methods of the Service, and in the methods of the Service putting the business logic of my application).
 
12:32 AM
In this way, just one DBConn instance used during the whole Request. The DBConn passed to the Mappers, and no to Services nor Controllers as the link (I copied before) does. So Services should not know if the modell are against an Oracle o MySql or even a WebService to store/retrieve data.
 
 
5 hours later…
5:29 AM
Hi
 
6:08 AM
It is recommended to use english for class/method/etc names. No need to define a query builder. Nor a PDO wrapper. No need for singletons. Nor for static methods/classes.
 
6:36 AM
This is a very good project sample, which, IMHO, implements the mvc pattern in the correct way.
The controller just updates the model. Only the view retrieves data from the model (by itself). So, you don't need a controller at all when it's about presenting some data to the app user.
 
6:53 AM
What you've developed so far seems right.
Did you (plan to) put your project on github?
 
 
11 hours later…
6:06 PM
Yes I just created my github account, so I can create a little project to show you and have your opinion about the best patterns and arquiecture.
Teresko project:
I have navigated around it all morning, it is similiar to my project in the model layer (services, mappers, entities classes).
But his project uses Symfony in order to the instantiation or creation of objects.
I would like to do it in scratch, so to know what it is all behind.
I am a little bit stucked about creating my Controllers and View classes as I am new in PHP.
 
6:31 PM
I am searching through google and some github projects in order to understand a bit more.
 
7:25 PM
Yes, he's using various libraries offered by Symfony: the dependency injection container, the (.yml & .php) config files loader, the router and their HTTP message abstraction (e.g. the whole handling of the request/response stuff).
I am not quite sure what you mean by "I would like to do it in scratch, so to know what it is all behind."? Don't try to implement a DI container. And, also, don't try to make a project using factories instead of a DI container.
The sample project shows you the beautiful way of developing a web application based on MVC, without making use of any framework, but of external or self-developed libraries.
So, for example, for your project you can choose to use PHP-DI as the DI container, zend-diactoros as the implementation of the HTTP message interfaces, FastRoute as the router component, etc.
Here's a controller sample (AddUser.php):
<?php

namespace MyMvc\UI\Web\Controller\Users;

use MyMvc\Domain\Service\Users;
use Psr\Http\Message\ServerRequestInterface;

/**
 * Add a user.
 *
 * @author me
 */
class AddUser {

    /**
     * User service.
     *
     * @var Users
     */
    private $userService;

    /**
     *
     * @param Users $userService User service.
     */
    public function __construct(Users $userService) {
        $this->userService = $userService;
    }

    /**
     * Invoke.
     *
     * @param ServerRequestInterface $request Request.
Here's a view sample:
<?php

namespace MyMvc\UI\Web\View\Users;

use MyMvc\Domain\Service\Users;
use MyMvc\UI\Web\View\MainMenuView;
use MyLib\Template\TemplateInterface;
use Psr\Http\Message\ResponseInterface;
use Psr\Http\Message\ResponseFactoryInterface;
use MyMvc\UI\Web\Components\Service\MainNavigation;

/**
 * Add a user.
 *
 * @author me
 */
class AddUser extends MainMenuView {

    /**
     * User service.
     *
     * @var Users
     */
    private $userService;

    /**
     *
     * @param ResponseFactoryInterface $responseFactory Response factory.
<?php

namespace MyMvc\UI\Web\View;

use MyMvc\UI\Web\View\View;
use MyLib\Template\TemplateInterface;
use Psr\Http\Message\ResponseFactoryInterface;
use MyMvc\UI\Web\Components\Service\MainNavigation;

/**
 * View with main menu.
 *
 * @author ale
 */
abstract class MainMenuView extends View {

    /**
     * Main navigation service.
     *
     * @var MainNavigation
     */
    protected $mainNavigationService;

    /**
     *
     * @param ResponseFactoryInterface $responseFactory Response factory.
<?php

namespace MyMvc\UI\Web\View;

use MyLib\Template\TemplateInterface;
use Psr\Http\Message\ResponseFactoryInterface;

/**
 * View.
 *
 * @author me
 */
abstract class View {

    /**
     * Template.
     *
     * @var TemplateInterface
     */
    protected $template;

    /**
     * Response factory.
     *
     * @var ResponseFactoryInterface
     */
    protected $responseFactory;

    /**
     *
     * @param ResponseFactoryInterface $responseFactory Response factory.
     * @param TemplateInterface $template Template.
 
8:07 PM
Here's the template class sample:
<?php

namespace MyLib\Template\Twig;

use Twig_Environment;
use MyLib\Template\BaseTemplate;
use MyLib\Template\TemplateInterface;
use MyLib\Template\ContextCollectionInterface;

/**
 * Twig template.
 *
 * @author me
 */
class Template extends BaseTemplate implements TemplateInterface {

    /**
     * Twig environment.
     *
     * @var Twig_Environment
     */
    private $environment;

    /**
     *
     * @param Twig_Environment $environment Twig environment.
     * @param ContextCollectionInterface $context A collection of parameters to pass to the template.
<?php

namespace MyLib\Template;

use MyLib\Template\ContextCollectionInterface;

/**
 * Base template.
 *
 * @author me
 */
abstract class BaseTemplate {

    /**
     * A collection of parameters to pass to the template.
     *
     * @var ContextCollectionInterface
     */
    private $context;

    /**
     *
     * @param ContextCollectionInterface $context A collection of parameters to pass to the template.
     */
    public function __construct(ContextCollectionInterface $context) {
        $this->context = $context;
And here's the template file:
{% extends '@Layout/main.html.twig' %}

{% block mainTitle %}
    Add User
{% endblock %}

{% block mainPageTitle %}
    Add a user
{% endblock %}

{% block mainPageSubtitle %}
    Lorem ipsum dolor sit amet, consetetur sadipscing elitr, sed diam nonumy eirmod tempor
{% endblock %}

{% block mainPageContent %}
    <div class="container">
        <div class="row mb-4">
            <div class="col">
                <div class="card">
                    <h5 class="card-header bg-secondary text-white">
As you see, I am using Twig as template engine.
A short description of the codes above:
The app user receives a form. He has to fill the "username" textbox and to submit the form.
The method "_invoke" of the AddUser controller is called. It uses the "Users" service to add a new user (with the filled-in username) to the model layer.
 
8:37 PM
Then the method "addUser" of the view class "AddUser" is called. It renders the template file "add-user.html.twig" (by adding a "User successfully added." message to it) and it writes its content into a newly created PSR-7 response object. In the end, the method returns the response object (whose body will be finaly displayed to the app user).
 
Thanks for the code you show me.
 
Wait a second, please. I'll finish the text.
...
In the view class "AddUser" you could also use the "Users" service (which is injected into the constructor) to display a list of user details or users from the model.
I forgot: In the beginning, in order for the app user to receive the form, the "index" method of the view class "AddUser" is called.
Hopefully, the codes above will help you better understand the controller, view & template part.
...
 
Unfortunately as I am new to PHP, many things that it's in your code as for example using Factorys, Template Engine, and behind your code the use of libraries that implement DI and routing, makes it more complex to me to understand.
 
Now we can talk a bit.
I understand.
 
Ok I better read your code and try to find out the use of Factorys, that Template Engine, and investigate how to use symfony for the DI.
and the Response Factory you mention
 
8:49 PM
For a better understanding I'd suggest to use PHP-DI, not Symfony's DI.
 
I will copy here my classes so you better get an idea of what I want to do, just a simple project everything with my hands (not framework) and understand the main concepts of MVC.
Please just give me 1 or 2 hours to make a little project, to copy paste here.
 
No, please, not here.
 
In my github? I just created one but I would like to do it without being so explicit if the code would run, just like if it where pseudocode.
 
It would be too much for this chat room. I'll give you my email and I will delete it in one minute. Ok? You can send me there whatever you want.
 
ok
send it now
ok copied, can delete the message
 
8:54 PM
Ok
So send me whatever you have and maybe a link to your github. I will take a look in the next days.
 
Ok will send you the email in around 1 hour
Or perhaps less time, my classes are very simple
 
Here is 22:56, so I will see your mesage(s) tomorrow. Ok?
 
Ok
perfect
 
Ok. Good night.
 
good night
 

« first day    last day (37 days later) »