Where communities thrive


  • Join over 1.5M+ people
  • Join over 100K+ communities
  • Free without limits
  • Create your own community
People
Activity
    Tom Butler
    @TRPB
    Hi all, I've added this chat for discussion about articles on my website. Often discussions I have via email would be useful to others to read so feel free to ask questions here rather than email me.
    sheripcit
    @sheripcit
    Hi friend. I'm glad that I can contact you now
    I'm doing web development. I have a couple of questions for you
    sheripcit
    @sheripcit
    send me an example of a small mvc site made
    sheripcit
    @sheripcit

    <?php

    class Model{
    //
    }

    class View{
    //
    }

    class Controller{

    public function action($name1, $name2, $name3){
        echo $name1 . '<br />';
        echo $name2 . '<br />';
        echo $name3;
    }

    }

    class Router{
    public $controller;
    public $action;
    public $parameter;

    public function start(){
        call_user_func_array(array($this->controller, $this->action) , $this->parameter);
    }

    }

    $router = new Router;
    $router->controller = 'Controller';
    $router->action = 'action';
    $router->parameter = ['Alex', 'Tom', 'Jasmina'];
    $router->start();

    I need a good router
    Fräntz Miccoli
    @frantzmiccoli

    Hi,

    Thanks for your work.

    I was wondering if Dice had any setting to set an interface implementation. I have seen that you can use constructParams to provide an implementation for specific cases but I would like a global implementation of my interface that will be injected everytime such an interface is required.

    Tom Butler
    @TRPB
    @sheripcit, take a look at https://r.je/immutable-mvc-crud-application which has a complete example of using MVC. The code is available here: https://github.com/TRPB/ImmutableMVC I'm in the process of creating an updated version of this article: https://r.je/mvc-php-router-dependency-injection to include a similar router in the immutable structure
    Tom Butler
    @TRPB

    Hi @frantzmiccoli it's possible using global substitutions.

    You can apply the same rule to every class with a wildcard class name. For example to make every class shared by default you could do this:

    $dice = $dice->addRules([
        '*' => [
            'shared' => true
        ]
    ]);

    For replacing a type hinted interface with a specific instance you can use substitutions in the default rule:

    $dice = $dice->addRules([
        '*' => [
            'substitutions' => [
                'SomeInterface' => 'SomeClass'
            ]
        ]
    ]);

    Of course if you want to use a specific instance you can create a named instance:

    $dice = $dice->addRules([
        '*' => [
            'substitutions' => [
                'Iterator' => '$HomeDirectoryIterator'
            ]
        ],
    
        '$HomeDirectoryIterator' => [
            'instanceOf' => 'DirectoryIterator',
            'constructParams' => ['/home']
        ]
    ]);

    Any time Dice sees a type hint for Iterator it will inject new DiretoryIterator('/home').

    Fräntz Miccoli
    @frantzmiccoli
    @TRPB super cool! I would recommend adding this in the doc (or maybe I have missed it, I don't remember reading anything about global rules). Thanks anyway!
    sheripcit
    @sheripcit
    Hello Friend!
    make me a nice router like this please
    такой . только лучший
    such only the best
    Thank you
    nirahiel
    @nirahiel
    Hello, there are some errors in the page https://r.je/mvc-php-front-controller :3
    Tom Butler
    @TRPB
    Hi, can you be more specif than "some errors"?
    nirahiel
    @nirahiel
    Sure, let me find them again
    so, @TRPB in the section starting by "For completeness, here are the related views and models:"
    In the class UserEditModel , the $user is never set
    In the class UserListView , the __construct method takes in a $model of type UserListView

    Also in the example before the title "Creating a front controller", you put

    $module = new UserController;
    
    $controller->showList(); //this would be redundant if the controller was related to a single view.
    
    echo $controller->output();

    Shouldn't it be $controller = new UserController; ?

    nirahiel
    @nirahiel
    @TRPB ?
    Taken from https://r.je/immutable-mvc-crud-application :
    In the next article I'll show you how to implement a better router into this code than the big if-else statement we have currently.
    What next article ?
    SAB
    @IamSAB
    I also wait for that article :D
    nirahiel
    @nirahiel
    Still nothing @TRPB ?
    I'm gonna yell at you ! (After all you gave permission to do so on your website)
    Tom Butler
    @TRPB
    Thanks, I'll fix the couple of issues on that page! The article is a work in progress unfortunately I am very busy with work at this time of year so may be a few weeks :(
    nirahiel
    @nirahiel
    Well I kinda needed it for my work. So for now i'll just do a router class with a static definition of routes, but yeah :/
    nirahiel
    @nirahiel
    @TRPB I have another question for you, regarding your immutable mvc system, how can I restrict the type of what's supposed to go in a route ( __construct(Model $model, etc...) ), creating a class Model { } for the sake of having a parent class feels like it falls under the same case as empty interfaces. If so, what can I do ?
    Tom Butler
    @TRPB
    You can type hint object: __consutrct(object $model)
    nirahiel
    @nirahiel
    An "object" type won't restrict what kind of object though. But I fixed my issue differently, thanks anyway :)
    treggi12
    @treggi12
    hello, I wanted to try a change to the code of your book (PHP & MySQL: novice to ninja) I tried to put the button for "edit" instead of the link. This change works before switching to OOP instructions; after it generates several errors, the first one is "Notice: Undefined index: joke in /srv/http/rewrite/classes/Ijdb/Controllers/Joke.php on line 66"
    line 66 is: $ joke = $ _POST ['joke'];
    I'm a beginner, but I don't understand why the "Delete" button works with the form and the "Edit" button no.
    this is the 2 button code:
    <? php if ($ userId == $ joke-> authorId):?>
    <form action = "/ joke / edit" method = "post">
    <input type = "hidden" name = "id" value = "<? = $ joke-> id?>">
    <input type = "submit" value = "Edit">
    </ Form>
            <form action = "/ joke / delete" method = "post">
                <input type = "hidden" name = "id" value = "<? = $ joke-> id?>">
                <input type = "submit" value = "Delete">
            </ Form>
        <? php endif; ?>
    treggi12
    @treggi12
    I solved ... it was enough to replace "method = post" with "method = get" in the form of the "edit" button; with "post" he took the wrong route
    Jan Jaworski
    @jaworek
    photo_2019-09-04 10.44.41.jpeg
    @TRPB Hi, I'm trying to use vje/min vagrant box with xdebug. When I try to connect to it using PHP Storm I get "EOF while reading packet". Did I miss something with the configuration?
    Jan Jaworski
    @jaworek

    I found a solution. I replaced provided xdebug.ini with this setup:

    zend_extension=xdebug.so
    xdebug.remote_enable=on
    xdebug.remote_connect_back = on
    xdebug.idekey = "vagrant"

    Now the problem is that it is only possible to debug website that is in "default" folder. So if I want to debug subdomain it does not seem to work.