SitePoint Sponsor

User Tag List

Page 2 of 2 FirstFirst 12
Results 26 to 29 of 29
  1. #26
    SitePoint Guru
    Join Date
    Jan 2005
    Location
    heaven
    Posts
    953
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    I don't really know if this will help or not but here's a way to load models.

    /application/modules/default/controllers
    PHP Code:
    <?php
    class IndexController extends Zend_Controller_Action
    {
        protected 
    $_loader '';
        public function 
    init()
        {
            
    $this->_loader = new Zend_Loader_PluginLoader();
            
    $this->_loader->addPrefixPath('Default''./application/modules/default/models');
        }
            
        public function 
    indexAction()
        {
            
    $db Zend_Registry::get('db');
            
    $loader $this->_loader;
            
    $class $loader->load('UserModel');
            
    $user call_user_func(array($class'getInstance'), $db);
        }
    }
    ?>
    in the /application/modules/default/models directory
    PHP Code:
    <?php
    class Default_UserModel extends Zend_Db_Table
    {
        protected 
    $_name "users";
        protected 
    $_primary "pu_id";
        
        public static function 
    getInstance($db)
        {
            return new 
    Default_UserModel($db);
        }
    }
    ?>
    Creativity knows no other restraint than the
    confines of a small mind.
    - Me
    Geekly Humor
    Oh baby! Check out the design patterns on that framework!

  2. #27
    SitePoint Addict SirAdrian's Avatar
    Join Date
    Jul 2005
    Location
    Kelowna, BC
    Posts
    289
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by imaginethis View Post
    I personally spent a great deal of time trying to figure out how to handle models in ZF. I spent hours looking through Zend_Controller and Zend_View to see if I missed something. It was some what annoying. I don't think ZF needs a large code base for models... But it should atleast define some sort of standard.
    I agree they should have a base model, but names aside, that's what the Zend_Db_Table is for.

    Quote Originally Posted by WildFoxMedia View Post
    This is just me and my stupid opinion but I have found that many of Zends libraries seem bloated and abstracted too far just to show how Zend, the "PHP Company" uses PHP to its fullest extend with multiple Interfaces, Abstract Classes & application of Iterators, etc.

    Im also annoyed at other factors like how silly some of the Zend DB stuff is - I was under the impression that you setup a relationship in Zend so it would be easier to access related data for a given model. So far, I havent found that to be the case.

    And for everyone that constantly says 'Oh, write your own class' - Is that really rapid? Is that quick? - If the answer is always 'Write your own class' then why not take it a step further and just say 'Write your own framework'. Some of the *** backwards stuff in Zend like results kicking out in Objects and Zend Form only being allowed to populate from an Array makes no sense to me - How about using a consistent type, whether it an Array or an Object who cares, just be consistent.
    It's so you can mix and match pretty much anything you want. It has already come in very handy for me.

    As for writing your own classes, yet it really is that easy and quick. All I really had to write was functions to read/write data, the underlying support for it already exists. Isn't that what the model is for? The framework isn't supposed to do this for you, you still have to write code.

    I've had no problems with objects versus arrays, it's usually very self explanatory or in the docs.
    Adrian Schneider - Web Developer

  3. #28
    SitePoint Guru
    Join Date
    Jan 2005
    Location
    heaven
    Posts
    953
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by SirAdrian View Post
    I agree they should have a base model, but names aside, that's what the Zend_Db_Table is for.
    Models extend beyond a database.
    Creativity knows no other restraint than the
    confines of a small mind.
    - Me
    Geekly Humor
    Oh baby! Check out the design patterns on that framework!

  4. #29
    SitePoint Addict SirAdrian's Avatar
    Join Date
    Jul 2005
    Location
    Kelowna, BC
    Posts
    289
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by imaginethis View Post
    Models extend beyond a database.
    Yes, but people are complaining about the lack of a database-access base model, otherwise an empty class is perfect (and I agree).
    Adrian Schneider - Web Developer


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
  •