Visualizzazione dei risultati da 1 a 10 su 15

Discussione: MVC php-login project

Hybrid View

  1. #1
    Scusa, ma a me sinceramente rivedere per l'ennesima volta la ricreazione di un framework da 0 stomaca alquanto. Partendo dal presupposto che l'MVC è un pattern abbastanza semplice da capire, la sua implementazione fatta come si deve richiede parecchio lavoro. Soprattutto quando parli di "M", li le cose si complicano alquanto. Quindi ti suggerirei alcune strade:

    1) Usi un framework serio e completo (Symfony ad esempio) che ha tutto quello che ti serve per sviluppare e per capire quello che stai facendo

    2) Usi vari framework per realizzarne uno tuo fatto a mano, in maniera da andare proprio dentro all'implementazione di un MVC ma con della roba già pronta

    http://fabien.potencier.org/article/...ponents-part-1
    http://twig.sensiolabs.org/
    http://www.doctrine-project.org/

    3) Parti da 0 proprio senza prendere spunto da script strani dal nome improbabile e ti scrivi tutto a manella (buona fortuna)

    Anche perchè per implementare la M ci sono mille modi diversi:

    http://www.oracle.com/technetwork/ja...ct-138824.html
    http://msdn.microsoft.com/en-us/library/ff649690.aspx
    http://martinfowler.com/eaaCatalog/index.html

    etc etc etc per ogni punto del framework che andrai a vedere. L'approccio che piu preferisco è il repository pattern, dove hai il model che è una classe POJO semplice semplice con le relazioni uno/molti, molti/molti, etc con gli altri models, e poi hai i repository che forniscono i metodi per interrogare i singoli model (ad esempio nel tuo caso avresi uno ShopRepository col metodo "findAll" che ritorna una collezione di model Shop)
    IP-PBX management: http://www.easypbx.it

    Old account: 2126 messages
    Oldest account: 3559 messages

  2. #2
    Utente di HTML.it L'avatar di Fractals87
    Registrato dal
    Apr 2008
    Messaggi
    1,202
    Quote Originariamente inviata da Santino83_02 Visualizza il messaggio
    Scusa, ma a me sinceramente rivedere per l'ennesima volta la ricreazione di un framework da 0 stomaca alquanto. Partendo dal presupposto che l'MVC è un pattern abbastanza semplice da capire, la sua implementazione fatta come si deve richiede parecchio lavoro. Soprattutto quando parli di "M", li le cose si complicano alquanto.
    Capisco perfettamente, ma il mio intento era di iniziare a capire mvc da un piccolo progetto.
    A questo punto mi viene da pensare che per come è costruita la logica mvc in questo mini framework sia un pò errata, e tanto vale utilizzarlo.
    Proverò allora ad utilizzare subito symfony sperando di capirci e non andare a casaccio.

    NO... è impossibile che il programma giri se il codice non è scritto!!
    non ti sto prendendo in giro :

    Codice PHP:
    <?php

    /**
     * Class View
     *
     * Provides the methods all views will have
     */
    class View
    {
        
    /**
         * simply includes (=shows) the view. this is done from the controller. In the controller, you usually say
         * $this->view->render('help/index'); to show (in this example) the view index.php in the folder help.
         * Usually the Class and the method are the same like the view, but sometimes you need to show different views.
         * @param string $filename Path of the to-be-rendered view, usually folder/file(.php)
         * @param boolean $render_without_header_and_footer Optional: Set this to true if you don't want to include header and footer
         */
        
    public function render($filename$render_without_header_and_footer false)
        {
            
    // page without header and footer, for whatever reason
            
    if ($render_without_header_and_footer == true) {
                require 
    VIEWS_PATH $filename '.php';
            } else {
                require 
    VIEWS_PATH '_templates/header.php';
                require 
    VIEWS_PATH $filename '.php';
                require 
    VIEWS_PATH '_templates/footer.php';
            }
        }

        
    /**
         * renders the feedback messages into the view
         */
        
    public function renderFeedbackMessages()
        {
            
    // echo out the feedback messages (errors and success messages etc.),
            // they are in $_SESSION["feedback_positive"] and $_SESSION["feedback_negative"]
            
    require VIEWS_PATH '_templates/feedback.php';

            
    // delete these messages (as they are not needed anymore and we want to avoid to show them twice
            
    Session::set('feedback_positive'null);
            
    Session::set('feedback_negative'null);
        }

        
    /**
         * Checks if the passed string is the currently active controller.
         * Useful for handling the navigation's active/non-active link.
         * @param string $filename
         * @param string $navigation_controller
         * @return bool Shows if the controller is used or not
         */
        
    private function checkForActiveController($filename$navigation_controller)
        {
            
    $split_filename explode("/"$filename);
            
    $active_controller $split_filename[0];

            if (
    $active_controller == $navigation_controller) {
                return 
    true;
            }
            
    // default return
            
    return false;
        }

        
    /**
         * Checks if the passed string is the currently active controller-action (=method).
         * Useful for handling the navigation's active/non-active link.
         * @param string $filename
         * @param string $navigation_action
         * @return bool Shows if the action/method is used or not
         */
        
    private function checkForActiveAction($filename$navigation_action)
        {
            
    $split_filename explode("/"$filename);
            
    $active_action $split_filename[1];

            if (
    $active_action == $navigation_action) {
                return 
    true;
            }
            
    // default return of not true
            
    return false;
        }

        
    /**
         * Checks if the passed string is the currently active controller and controller-action.
         * Useful for handling the navigation's active/non-active link.
         * @param string $filename
         * @param string $navigation_controller_and_action
         * @return bool
         */
        
    private function checkForActiveControllerAndAction($filename$navigation_controller_and_action)
        {
            
    $split_filename explode("/"$filename);
            
    $active_controller $split_filename[0];
            
    $active_action $split_filename[1];

            
    $split_filename explode("/"$navigation_controller_and_action);
            
    $navigation_controller $split_filename[0];
            
    $navigation_action $split_filename[1];

            if (
    $active_controller == $navigation_controller AND $active_action == $navigation_action) {
                return 
    true;
            }
            
    // default return of not true
            
    return false;
        }
    }
    Che mestiere difficile.....essere da soli ancora di più

Permessi di invio

  • Non puoi inserire discussioni
  • Non puoi inserire repliche
  • Non puoi inserire allegati
  • Non puoi modificare i tuoi messaggi
  •  
Powered by vBulletin® Version 4.2.1
Copyright © 2026 vBulletin Solutions, Inc. All rights reserved.