SitePoint Sponsor

User Tag List

Page 1 of 2 12 LastLast
Results 1 to 25 of 29
  1. #1
    SitePoint Member
    Join Date
    Sep 2008
    Posts
    24
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Variety of ZF Questions

    Hey guys, im new to Zend, ive been a long time user of Cake, I have a few questions related to conventions, etc.

    1. Can someone possibly post a bootstrap/index file for a modular file convention where there are seperate controllers/views for public and admin modules that share models?

    2. Is there a 'magic' save() method for saving to the database? I see currently there is Insert & Update, I dont mind using insert & update, was just curious.

    3. Is there any kind of table inflection when you insert or update? What I mean is if you have a table with 2 columns, id & name the array I try to insert has 3 array keys for id, name & created it throws an error - Cake does table inflection where it only attempts to save columns that exist in the table.

    4. Is there any decent way to autoload models instead of doing.... $this->someModel = new someModel; in the init() of every controller?

    5. Whats the correct method for gathering the filtered data from a controller, I saw in a tutorial where you basically check if the request is a post, then you assign the POST array to a variable, then you loop through each array key and do getValue() from the Form object...like this...

    $formModel = new FormModel;

    $dbRow = array();

    foreach($postArray as $pKey => $pValue) {
    $dbRow[$pKey] = $formModel->getValue($pKey);
    }

    Is that the best way?

    Thank you

  2. #2
    SitePoint Guru
    Join Date
    Jan 2005
    Location
    heaven
    Posts
    953
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by WildFoxMedia View Post
    Hey guys, im new to Zend, ive been a long time user of Cake, I have a few questions related to conventions, etc.

    1. Can someone possibly post a bootstrap/index file for a modular file convention where there are seperate controllers/views for public and admin modules that share models?
    I personal place all of my modules in a directory within my application folder. Each module contains a controller, model and view directory. Use the following to point to set the path to folder holding all the models.
    PHP Code:
    $controller->setDefaultModule('default'); // if no module is supplied
    $controller->addModuleDirectory('application/modules'); 
    2. Is there a 'magic' save() method for saving to the database? I see currently there is Insert & Update, I dont mind using insert & update, was just curious.
    No.
    3. Is there any kind of table inflection when you insert or update? What I mean is if you have a table with 2 columns, id & name the array I try to insert has 3 array keys for id, name & created it throws an error - Cake does table inflection where it only attempts to save columns that exist in the table.
    No.
    4. Is there any decent way to autoload models instead of doing.... $this->someModel = new someModel; in the init() of every controller?
    Not yet. But several people have created their own model loaders. As a personal preference, I moved my models into a library folder so that I can take advantage of Zend_Loader's autoload feature. I'm not saying its the best solution, but it works well enough for now.

    5. Whats the correct method for gathering the filtered data from a controller, I saw in a tutorial where you basically check if the request is a post, then you assign the POST array to a variable, then you loop through each array key and do getValue() from the Form object...like this...

    $formModel = new FormModel;

    $dbRow = array();

    foreach($postArray as $pKey => $pValue) {
    $dbRow[$pKey] = $formModel->getValue($pKey);
    }

    Is that the best way?

    Thank you
    I don't think there is a "best way" ... its highly subjective. What ever works for you. I personally would prefer a cleaner approach having my database model handle the loading of form values. For me, it would look like this:

    PHP Code:
    $form = new MyForm();
    if(
    $form->isValid($_POST))
    {
      
    $table = new Model();
      
    $table->setForm($form)->save();

    But whatever floats your boat :3. A word to the wise, the documentation sucks for the Zend Framework and there are tons of inconsistencies within the framework. Use the Docs to get an idea of how things work then go digging through the code to get a better idea of how things work. I think there are two books currently out for the Zend Framework, both of which aren't worth reading. I was highly disappointed by them both ._. ...

  3. #3
    SitePoint Member
    Join Date
    Sep 2008
    Posts
    24
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Thanks for the reply imaginethis - As you mentioned, there are nothing but inconsistencies within the documentation and among peoples opinions on best practices.

    I guess thats what you get when you have a framework that is as detached from itself as much as Zend is - You start to see the different ways people choose to accomplish the same thing, which isnt to say that its bad, but hard for anyone new to the software to understand the correct and incorrect ways to do things.

  4. #4
    does not play well with others frezno's Avatar
    Join Date
    Jan 2003
    Location
    Munich, Germany
    Posts
    1,391
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by WildFoxMedia View Post
    Hey guys, im new to Zend, ive been a long time user of Cake, I have a few questions related to conventions, etc.
    any reason you don't (want to) stay with Cake?
    We are the Borg. Resistance is futile. Prepare to be assimilated.
    I'm Pentium of Borg.Division is futile.Prepare to be approximated.

  5. #5
    SitePoint Member
    Join Date
    Sep 2008
    Posts
    24
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    frezno, if it were my choice, I would.

    The company I work for got this hair up there *** about switching to Zend, not for technical merits (Which I find lacking) but because they think telling people that a site/app is built with Zend is more marketable and professional than cake...

  6. #6
    SitePoint Enthusiast
    Join Date
    Feb 2008
    Posts
    33
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by WildFoxMedia View Post
    frezno, if it were my choice, I would.

    The company I work for got this hair up there *** about switching to Zend, not for technical merits (Which I find lacking) but because they think telling people that a site/app is built with Zend is more marketable and professional than cake...
    to be fair, they have a point - the ZF has the backing of a fair few industry bigwigs whereas Cake is still very much community driven.

  7. #7
    SitePoint Zealot
    Join Date
    Feb 2008
    Posts
    109
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by philjohn View Post
    to be fair, they have a point - the ZF has the backing of a fair few industry bigwigs whereas Cake is still very much community driven.
    And with that comes further inconsistancies and bad practice.

  8. #8
    SitePoint Member
    Join Date
    Sep 2008
    Posts
    24
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    I understand that it has more industry backing with companies like Google, IBM, etc. but the apps & sites were creating arent even CLOSE to being on same level as the big boys.

    Even still, to make a technology decision based solely its name is irresponsible at best, especially when those people dont know how to program themselves - But thats more of an issue with the people I work with then it is Zend, Cake or any piece of technology.

  9. #9
    SitePoint Guru
    Join Date
    Jan 2005
    Location
    heaven
    Posts
    953
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by WildFoxMedia View Post
    I understand that it has more industry backing with companies like Google, IBM, etc. but the apps & sites were creating arent even CLOSE to being on same level as the big boys.

    Even still, to make a technology decision based solely its name is irresponsible at best, especially when those people dont know how to program themselves - But thats more of an issue with the people I work with then it is Zend, Cake or any piece of technology.
    There's a great deal of push towards the ZF within the PHP community and I'm I switched to ZF for the same reasons. There has to be some sort of standard amongst frameworks, one that stands above all the rest and the ZF has the best chance to be such a framework because it is backed by "the big boys" as you so nicely put it . The ZF, however, is not like PHP and is fairly difficult to learn. There's quick and dirty feel to it like php. Its structured and BIG and a great pain in the ... well you get my point.

  10. #10
    SitePoint Addict
    Join Date
    Jan 2008
    Posts
    203
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by imaginethis View Post
    There's a great deal of push towards the ZF within the PHP community and I'm I switched to ZF for the same reasons. There has to be some sort of standard amongst frameworks, one that stands above all the rest and the ZF has the best chance to be such a framework because it is backed by "the big boys" as you so nicely put it . The ZF, however, is not like PHP and is fairly difficult to learn. There's quick and dirty feel to it like php. Its structured and BIG and a great pain in the ... well you get my point.
    not really, you dont have to use their whole framework, for example I only use some of the components that I need such as Cache, Amazon Service, Lucene Search, its nice the way its so loosely structured

  11. #11
    SitePoint Addict
    Join Date
    Jan 2008
    Posts
    203
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    actually ill take one thing back

    wrote own FileCache object after profiling the Zend Cache with File back end and concluding that its way too bloated

    them extra milliseconds do add up quickly considering i have rather large sites to run

    so to sum it up, after running tests i came to conclusion that a homebrew solution would be better, but i have to admit using the Zend one is so convenient, tho there was a time where they broke backwards compatibility in this Class causing me headaches when I had to upgrade to new framework version

  12. #12
    SitePoint Member
    Join Date
    Sep 2008
    Posts
    24
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    The fact that you can use the pieces seperately and outside of the framework is nice, but it leads to the framework as a whole not being cohesive or quick to develop. In my mind the reason for a framework is to speed up development and handle alot of the low level crap that you would usually have to deal with - Zend just doesnt seem to fit that bill.

  13. #13
    SitePoint Guru
    Join Date
    Jan 2005
    Location
    heaven
    Posts
    953
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by WildFoxMedia View Post
    The fact that you can use the pieces seperately and outside of the framework is nice, but it leads to the framework as a whole not being cohesive or quick to develop. In my mind the reason for a framework is to speed up development and handle alot of the low level crap that you would usually have to deal with - Zend just doesnt seem to fit that bill.
    er... development speed has little do with framework cohesiveness. I can create your very basic CMS system within an hour provided I spend 45 minutes planning. Development speed is restricted primarily to knowledge of how to use the framework. It takes an inordinate amount of time to get used to using the framework, but if you actually go through and read he code, not the documentation, some of it makes a great deal of sense.

    Quote Originally Posted by ionix5891
    not really, you dont have to use their whole framework, for example I only use some of the components that I need such as Cache, Amazon Service, Lucene Search, its nice the way its so loosely structured
    I'm not exactly sure what the "not really" was referring to, but I'm pretty sure you just agreed with me?

  14. #14
    SitePoint Addict SirAdrian's Avatar
    Join Date
    Jul 2005
    Location
    Kelowna, BC
    Posts
    289
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Once you have a basic project set up, it's easy to set new ones up. It just takes time to initially learn how. Zend's goal was not to provide you with a way of quickly producing a functional blog.
    Adrian Schneider - Web Developer

  15. #15
    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
    Once you have a basic project set up, it's easy to set new ones up. It just takes time to initially learn how. Zend's goal was not to provide you with a way of quickly producing a functional blog.
    Erm... who said anything about blogs? O.o... In any case, it does allow you a way of quickly producing a functional blog. Zend_Db, Zend_Auth, Zend_Session, Zend_View, Zend_Layout, Zend_Form, Zend_Controller and you have a functional blog... Granted its not as fast as installing Wordpress or Drupal, but its still fairly quick all considering. ZF is more or less an all-purpose framework...

  16. #16
    SitePoint Member
    Join Date
    Sep 2008
    Posts
    24
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    imaginethis - Maybe im doing something wrong then... Another unfortunate part of my bosses is that they didnt let me have a chance to even learn the framework, instead, just told me to build a site with the same timeline as building a site with Cake.

    To me, having to instantiate models manually and even having to manually call methods to pull associated records, among many other things, isnt conducive to rapid development.

  17. #17
    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
    Erm... who said anything about blogs? O.o... In any case, it does allow you a way of quickly producing a functional blog. Zend_Db, Zend_Auth, Zend_Session, Zend_View, Zend_Layout, Zend_Form, Zend_Controller and you have a functional blog... Granted its not as fast as installing Wordpress or Drupal, but its still fairly quick all considering. ZF is more or less an all-purpose framework...
    I know you didn't... it's just the usual test case that doesn't really show anything.
    Adrian Schneider - Web Developer

  18. #18
    SitePoint Guru
    Join Date
    Jan 2005
    Location
    heaven
    Posts
    953
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by WildFoxMedia View Post
    imaginethis - Maybe im doing something wrong then... Another unfortunate part of my bosses is that they didnt let me have a chance to even learn the framework, instead, just told me to build a site with the same timeline as building a site with Cake.

    To me, having to instantiate models manually and even having to manually call methods to pull associated records, among many other things, isnt conducive to rapid development.
    Trust, me I understand what your feeling... My boss is quite similar.

    By no means is the ZF complete. It has a few gaping holes that still need to be filled. ZF doesn't have full MVC support, it only has VC which is some what annoying. But eventually it will get better, I hope... If not, I'm going back to C++ .

  19. #19
    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 know you didn't... it's just the usual test case that doesn't really show anything.
    I have absolutely no idea what you are attempting to say...

  20. #20
    SitePoint Addict SirAdrian's Avatar
    Join Date
    Jul 2005
    Location
    Kelowna, BC
    Posts
    289
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    imaginethis, I was replying to the following initially.
    In my mind the reason for a framework is to speed up development and handle alot of the low level crap that you would usually have to deal with - Zend just doesnt seem to fit that bill.
    It wasn't meant to be for rapid development of small applications - it was meant for larger applications where you need more than a simple CRUD application. It's a tool, but not meant to do all the work for you.

    For your Cake comparison, Cake does do a huge amount of the work for you. With Zend, you'll get good database abstraction and functionality, request handling, simple (yet powerful) templates, and a system that puts it all togehter without being too restricting. It's very open ended.


    At my company, we were developing large applications on top of vBulletin,then finally we snapped and said we wanted to use Zend. We managed to put a full (quite complex) site together in a week, and now we are working on another site which is twice as big. Once you break out of the basic CRUD requirements, then you can start to appreciate it over others like Cake.
    Adrian Schneider - Web Developer

  21. #21
    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
    imaginethis, I was replying to the following initially. It wasn't meant to be for rapid development of small applications - it was meant for larger applications where you need more than a simple CRUD application. It's a tool, but not meant to do all the work for you.

    For your Cake comparison, Cake does do a huge amount of the work for you. With Zend, you'll get good database abstraction and functionality, request handling, simple (yet powerful) templates, and a system that puts it all togehter without being too restricting. It's very open ended.


    At my company, we were developing large applications on top of vBulletin,then finally we snapped and said we wanted to use Zend. We managed to put a full (quite complex) site together in a week, and now we are working on another site which is twice as big. Once you break out of the basic CRUD requirements, then you can start to appreciate it over others like Cake.
    Ah! That's better :3... I Like words .

    And I agree with you, that it ZF is very open ended which I personally love. I don't mind spending days on end reading through code and figuring out how it works, a gift I owe to my CS Professor.

    Though, I still don't see the ZF as being specific to large applications. I would still use ZF for a quick contact form if circumstances permit. I see it as an all purpose tool, like a spoon... Oh the things you can do with a spoon... >.>

  22. #22
    SitePoint Addict SirAdrian's Avatar
    Join Date
    Jul 2005
    Location
    Kelowna, BC
    Posts
    289
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Eww... words.

    Yeah it's great just digging into code; that's the best way to learn how something works. I'll agree with you for small apps (or scripts, rather) like a contact form. I was thinking more like basic sites where there is one primary piece of data (entries, or contacts) and then one or two associated tables (categories, etc.).

    CakePHP aims at this market for rapid development of blogs (this is the common screencast) and other similar applications. They try to show you how "fast" you can build an application, which while true, you don't really get to do much coding. You are just configuring an already existing application.

    A lot of people here are complaining about the lack of M in Zend. Personally, I hate how most frameworks handle databases. I like writing my own classes which simply use the Zend_Db_Adapter and Zend_Db_Select. You get far more control over what is happening, and you actually get to code. To me that's important.

    If you have a way you like doing things, start your own base model class and have each model extend it. All of the actual dirty connection code, abstraction and error handling are done for you.
    Adrian Schneider - Web Developer

  23. #23
    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
    Eww... words.

    Yeah it's great just digging into code; that's the best way to learn how something works. I'll agree with you for small apps (or scripts, rather) like a contact form. I was thinking more like basic sites where there is one primary piece of data (entries, or contacts) and then one or two associated tables (categories, etc.).

    CakePHP aims at this market for rapid development of blogs (this is the common screencast) and other similar applications. They try to show you how "fast" you can build an application, which while true, you don't really get to do much coding. You are just configuring an already existing application.

    A lot of people here are complaining about the lack of M in Zend. Personally, I hate how most frameworks handle databases. I like writing my own classes which simply use the Zend_Db_Adapter and Zend_Db_Select. You get far more control over what is happening, and you actually get to code. To me that's important.

    If you have a way you like doing things, start your own base model class and have each model extend it. All of the actual dirty connection code, abstraction and error handling are done for you.
    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.
    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!

  24. #24
    SitePoint Member
    Join Date
    Sep 2008
    Posts
    24
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    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.

  25. #25
    SitePoint Guru
    Join Date
    Jan 2005
    Location
    heaven
    Posts
    953
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    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.
    I understand your frustration but here is an example of a "quick" model for a database table called users.

    PHP Code:
    <?php
        
    class Default_Models_UserModel extends Zend_Db_Table
        
    {
            protected 
    $_name "users";
            protected 
    $_primary "us_id";
        }
    ?>
    That's fairly quick if you ask me . You can insert, update, delete as well as run more advanced queries.
    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!


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
  •