SitePoint Sponsor

User Tag List

Page 4 of 4 FirstFirst 1234
Results 76 to 86 of 86

Thread: MVC in PHP

  1. #76
    We're from teh basements.
    Join Date
    Apr 2007
    Posts
    1,205
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by ionix5891 View Post
    the registry lets me avoid globals and helps simplify testing, which is well why people use them
    I inferred that much. Just curious as to why that particular arrangement. I know one fellow who made his Database singleton a child node of his Session singleton because he thought that was "the most logical place for it." I didn't think so because the Session was dependent on the Database, not the other way around.

  2. #77
    SitePoint Guru
    Join Date
    Nov 2004
    Location
    Plano
    Posts
    643
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by ionix5891 View Post
    manys of time do i curse at zend studio for being very lacking and slow
    zend studio for eclipse? that program is AMAZING. it's packed full of features and blazing fast, at least from my experience.

    Quote Originally Posted by ionix5891 View Post
    tho i have to admit i hate the lack of proper autocomplete in all PHP IDE's i tested
    again...i have never had a single problem with zend studio not autocompleting my registry's.

    not trying to turn this into an IDE war, but i find it strange that you're complaining about a lack of features that i'm pretty sure zend has. are you using an older version? i know the version pre-eclipse wasn't near as good...

  3. #78
    SitePoint Addict
    Join Date
    Jan 2008
    Posts
    203
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by XtrEM3 View Post
    zend studio for eclipse? that program is AMAZING. it's packed full of features and blazing fast, at least from my experience.
    .
    no im stuck with old one for while


    Quote Originally Posted by XtrEM3 View Post

    again...i have never had a single problem with zend studio not autocompleting my registry's.

    not trying to turn this into an IDE war, but i find it strange that you're complaining about a lack of features that i'm pretty sure zend has. are you using an older version? i know the version pre-eclipse wasn't near as good...
    I havent tested a php IDE that does a good job at autocomplete anything 2-3 levels deep (something like visual studio intellisense would be perfecte)

    such as $this->Registry->bLAH->bLEH

    and yes i tried early versions of zend studio 6 eclipse (but its sooooo slow on large projects), unless they added it since

    php developer comes close but it just puts every combination into the autocomplete which is annoying, but anyways thats going off on a tangent back to this thread


    I didn't think so because the Session was dependent on the Database, not the other way around.
    yes its same here, to scale across few servers the session are stored in memory table in DB, i use several filters (defined in each action as action properties and executed by the main controller before the action itself is run) so a database connection filter runs first before session filter


    i should have pasted more of the action controller code earlier, would have been clearer (i have to be careful due to non disclosure agreement)

    PHP Code:
    <?php
    class _default extends Blocks_Action {
        private 
    $Registry; public function __constructBlocks_Registry $Registry ){ $this->Registry $Registry; }
        
        
        
        
        
    //action filters, executed in this order, otherwise you might endup with exeption, Session dependant on DB, ACL dependant on Session and so on
        
    public   $filters    =    array(
        
            
    'HttpResponse'    =>    array(),
            
    'Locale'        =>    array(),
            
    'Theme'            =>    array(),
            
    'DB'            =>    array(),
            
    'Session'        =>    array(),
            
    'CommonView'    =>    array(),
                    
    'Acl' => array('admin'),
        );
        
        
        
        
        

        
    /**
         * action execution starts here
         * @throws Exception
         */
        
    public function main(){
            
            
            
            
    //create item object
            
    $Item = new Item
                new 
    ItemDatabase$this->Registry->DB ),
                
    $this->Registry->Settings->items
            
    );
            
            
            
            
            
    //fetch the hotlist
            
    try {
                
                
    $hotlist     =    $Item->fetchHotlist$this->Registry->Session->getUserId() );
            }
            catch ( 
    ItemException $e){
                
                throw new 
    Exception$e->getMessage(), 500 );
            }
            
            
            
            
    //fetch the asset summary
            
    try {
                
                
    $register_summary     =    $Item->fetchSummary(  );
            }
            catch ( 
    ItemException $e){
                
                throw new 
    Exception$e->getMessage(), 500 );
            }
            
            
            
            
    //create a view
            
    try{
                
                
    $View = new View
                    
    $this->Registry,
                    
    'normal',
                    
    'default__admin',
                    array(
                        
    'default',
                        
    'item'
                    
    )
                );
                
                
    $View->setParams$this->Registry->CommonView );
                
                
    $output    =    $View->render(array(
                    
    'hotlist'            =>    $hotlist,
                    
    'register_summary'    =>    $register_summary,
                ));
            }
            catch( 
    Exception $e ){
                
                throw new 
    Exception$e->getMessage() );
            }
            
            
            
            
    //output
            
    $this->Registry->HttpResponse->appendNoCacheHeaders();
            
    $this->Registry->HttpResponse->appendHeader('Content-Type: text/html; charset=utf-8');
            
    $this->Registry->HttpResponse->setMessage$output );
            
    $this->Registry->HttpResponse->output();
        }
    }
    ?>

  4. #79
    SitePoint Addict
    Join Date
    Feb 2007
    Posts
    251
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by ionix5891 View Post
    I havent tested a php IDE that does a good job at autocomplete anything 2-3 levels deep
    PDT handles any number of levels just fine...

    PHP Code:
    class Registry {
        
    /**
         * @var bLAH 
         **/
        
    public $bLAH;
    }

    class 
    bLAH {
        
    /**
         * @var bLEH 
         **/
        
    public $bLEH;
    }

    class 
    bLEH {}

    class 
    Foo {
        
    /**
         * @var Registry
         */
        
    protected $registry;
        function 
    bar() {
            
    $this->registry->bLAH->... // PDT shows bLEH
        
    }


  5. #80
    SitePoint Addict
    Join Date
    Jan 2008
    Posts
    203
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    hmm which version of PDT are you using? if this is true then im jumping on it


    edit: you example works, but if the class is defined in another file and the registry is passed in to the action class via constructor (link in the code above) it doesn't show up in outline in the editor and theres no autocomplete more than few levels...
    so in my case typing $this->registry->... results in nothing

  6. #81
    Theoretical Physics Student bronze trophy Jake Arkinstall's Avatar
    Join Date
    May 2006
    Location
    Lancaster University, UK
    Posts
    7,062
    Mentioned
    2 Post(s)
    Tagged
    0 Thread(s)
    The problem with PHP in terms of autocomplete is that a variable can hold anything - so how does it know what's what, without extra documentation?

    But again guys, we're going off-topic here...
    Jake Arkinstall
    "Sometimes you don't need to reinvent the wheel;
    Sometimes its enough to make that wheel more rounded"-Molona

  7. #82
    SitePoint Addict
    Join Date
    Jan 2008
    Posts
    203
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by arkinstall View Post
    The problem with PHP in terms of autocomplete is that a variable can hold anything - so how does it know what's what, without extra documentation?

    But again guys, we're going off-topic here...
    OFFTOPIC

    visual studio intellisense handles dynamic languages quite fine ... but of course we in the php world are left with subpar tools

    /OFFTOPIC

  8. #83
    SitePoint Addict
    Join Date
    Feb 2007
    Posts
    251
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by ionix5891 View Post
    hmm which version of PDT are you using? if this is true then im jumping on it
    I'm using PDT 1.0.3.

    Quote Originally Posted by ionix5891 View Post
    edit: you example works, but if the class is defined in another file and the registry is passed in to the action class via constructor (link in the code above) it doesn't show up in outline in the editor and theres no autocomplete more than few levels...
    Is there any reason you can't put a hint in the action class?

    PHP Code:
    class MyActionClass {
        
    /**
         * @var Registry
         */
        
    protected $registry;
        function 
    __construct($registry) {
            
    $this->registry $registry;
        }
        function 
    bar() {
            
    $this->registry->...autocompletion;
        }

    I assume I'm missing something though, because I just realized I typed the same thing up earlier. Why doesn't that work for you?

  9. #84
    SitePoint Addict
    Join Date
    Jan 2008
    Posts
    203
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by cuberoot View Post
    I'm using PDT 1.0.3.



    Is there any reason you can't put a hint in the action class?

    PHP Code:
    class MyActionClass {
        
    /**
         * @var Registry
         */
        
    protected $registry;
        function 
    __construct($registry) {
            
    $this->registry $registry;
        }
        function 
    bar() {
            
    $this->registry->...autocompletion;
        }

    I assume I'm missing something though, because I just realized I typed the same thing up earlier. Why doesn't that work for you?
    i don't know why its not autocompleting, if you look at the code posted i do have a "hint" in the action class for the registry being passed in

    the registry doesnt even show up in the outline

  10. #85
    SitePoint Addict
    Join Date
    Feb 2007
    Posts
    251
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    I think the problem there is that PDT isn't taking the type hint from the constructor argument list. You have to clue it in using phpdoc hints instead...

    PHP Code:
    class Registry {
        
    /**
         * @var bLAH 
         **/
        
    public $bLAH;
    }

    class 
    bLAH {
        
    /**
         * @var bLEH 
         **/
        
    public $bLEH;

    }

    class 
    bLEH {}

    class 
    Foo {
        protected 
    $registry;
        function 
    __construct(Registry $registry) {
            
    $this->registry $registry;
        }
        function 
    bar() {
            
    $this->registry->...nope
        
    }
    }

    class 
    Baz {
        
    /**
         * @var Registry
         */
        
    protected $registry;
        function 
    __construct(Registry $registry) {
            
    $this->registry $registry;
        }
        function 
    bar() {
            
    $this->registry->...autocompletion
        
    }


  11. #86
    SitePoint Guru
    Join Date
    Nov 2004
    Location
    Plano
    Posts
    643
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    just part of the reason i'm a newfound fan of IDEs, the autocompletion gives you incentive to document and comment your code well with javadoc. i have no problem committing an instance variable to a certain class / type.


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •