SitePoint Sponsor

User Tag List

Page 2 of 2 FirstFirst 12
Results 26 to 36 of 36
  1. #26
    PHP/Rails Developer Czaries's Avatar
    Join Date
    May 2004
    Location
    Central USA
    Posts
    806
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by allspiritseve View Post
    This approach links objects directly to tables 1:1, and that is not always desired.
    I actually like a 1:1 relationship between tables and mappers myself (one mapper per table). Using the datamapper pattern, It's more of a hybrid between a table data gateway and datamapper than a strict definition datamapper, but I've found it to be the most convenient arrangement by far. Most people are already thinking in terms of "this data from this table", "that from that table", etc. So using one mapper per table is an easy shift to make. It also helps to have one clear place to define the table structure and all it's fields clearly and easily, and helps to solidly define the scope of the mapper down to one and only one table so it will never end up "knowing too much" about the rest of the system.

  2. #27
    Spirit Coder allspiritseve's Avatar
    Join Date
    Dec 2002
    Location
    Ann Arbor, MI (USA)
    Posts
    648
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by Czaries View Post
    I actually like a 1:1 relationship between tables and mappers myself (one mapper per table).
    Just curious... what do you do about joins?

    Also-- most of my mappers are one to one with tables as well. I like having the possibility of spanning more than one if I need to though. I think that will become a need as the apps I make become more complex. For now, I've just been writing my datamappers custom, and then at some point I'm going to see if I can refactor out a class or two.

  3. #28
    PHP/Rails Developer Czaries's Avatar
    Join Date
    May 2004
    Location
    Central USA
    Posts
    806
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by allspiritseve View Post
    Just curious... what do you do about joins?

    Also-- most of my mappers are one to one with tables as well. I like having the possibility of spanning more than one if I need to though. I think that will become a need as the apps I make become more complex. For now, I've just been writing my datamappers custom, and then at some point I'm going to see if I can refactor out a class or two.
    I usually use table relationships in my mappers (has one, has many, etc.) instead of performing cross-table joins. I've found that table relationships will solve my problem more effectively than joins, because they provide me with complete separate row objects from the specific table mapper instead of merging a bunch of properties together in one row. With separate distinct objects, I can save the data back to the originating tables much easier when I need to.

    I am working on a project you may be interested in, that may be useful to you - especially if you're making your mappers by hand - PHP DataMapper. In the current version, the relations require an additional query to be made, but I am wanting to at least have a 'join' option available to reduce overhead for those who need it.

    So right now, if I ever wanted to perform a join, I would end up writing a custom query in a model function. Hopefully that will change in future releases, as the project gets more mature and the adapters support joins. If you want to contribute, I'd love for you to help me out with it - it's open source MIT licensed.

    Check out the code on Google Code: http://code.google.com/p/phpdatamapper/

  4. #29
    Spirit Coder allspiritseve's Avatar
    Join Date
    Dec 2002
    Location
    Ann Arbor, MI (USA)
    Posts
    648
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by Czaries View Post
    I am working on a project you may be interested in
    I actually had it open in a tab, I was gonna look at it later today.

  5. #30
    SitePoint Addict
    Join Date
    Oct 2004
    Location
    Sutton, Surrey
    Posts
    259
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by allspiritseve View Post
    Just curious... what do you do about joins?
    I use my data dictionary to keep track of all relationships, even with tables in different databases, and this data is exported int a structure file for each table in the form of a $parent_relations array and a $child_relations array.

    When constructing the default sql SELECT statement for a table I use the contents of the $parent_relations array to automatically include a JOIN to each parent table. This allows me to include in the select list any number of fields from the parent table.

    It is far more efficient to perform JOINS in a single SQL statement than it is to access each table separately.

    I also have the facility to allow the sql SELECT statement to be customised into whatever fits the task at hand.

  6. #31
    SitePoint Member
    Join Date
    Jul 2008
    Posts
    15
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    I was hoping to get some good ideas from this thread. In the limited spare time I have I'm architecting a PHP framework. Among other issues I have in coming up with a good design, the method in which I will design and implement access to data plays an important role. Until now I was not able to find a design that would suit my needs. Unfortunately, this thread doesn't help me either.

    Performance is of extreme importance for me and some of your approaches would make the applications crawl. I am sure you would argue with me on this, but after conducting quite a few tests and benchmarks I know that the more abstraction you add the slower it gets. Also, the broader the class of problems you are trying to solve, the slower it gets.

    PHP is not Java or C++ or C#. I've worked with Java for a while and if you want your PHP app not to crawl you better not try to copy the principles behind Java and other compiled languages. Patterns are great. When I first learned Java (after 2 years of PHP) I was amazed how nicely structured it was. At some point I even tried to code in PHP as I did in Java. Not a good idea! The way a PHP script is called is totally different than how a Java program or servlet executes.

    So, while I have no idea how the design of the framework will look in the end, I can tell you for sure that I want the flexibility of SQL. That means, for starters, I won't use ActiveRecord. Very probably the framework will only support MySQL, and in order to add PostgreSQL support you would have to rewrite queries in models. Not sure about this though, as I might find a better way. Between a fast PHP/MySQL framework and a slow PHP/any-db one I choose the fast one. If you've developed with MySQL from start you have no reason to switch to other DBMS at the end. Or if you do you probably made the wrong choices in the first place.

    This is not the best way to do it. It is MY best way. I don't think there's a right and wrong way to design a system. As long as it meets your requirements it is done the right way. Patterns are cool, but to use them just because it's cool and trendy is crazy. There are a bunch of patterns that don't have their place in a PHP system. They are in a way like Smarty template engine - supposed to do something better, but practically just overkill. I honestly don't see a reason to handcode 10 classes, execute 5 functions instead of just mysql_query(), instantiate 10 objects (that consume memory) instead of none, etc just so I match a certain design methodology and implement a few fancy patterns.

    I also think PHP is missing a good IDE. It has tons of editors but absolutely no IDE. Syntax highlighting and code completion are functions of an editor not those of an IDE btw. I see many frameworks, CMS', and generally PHP systems, that turn to PHP and a DBMS to generate a functionality that should be implemented in an IDE not in the final application. I won't go into a lot of detail on this though, because I would have to write pages.

  7. #32
    SitePoint Wizard silver trophy kyberfabrikken's Avatar
    Join Date
    Jun 2004
    Location
    Copenhagen, Denmark
    Posts
    6,157
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by jackmk View Post
    Performance is of extreme importance for me ...
    Why is that?

  8. #33
    SitePoint Addict
    Join Date
    Feb 2007
    Posts
    251
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by jackmk View Post
    So, while I have no idea how the design of the framework will look in the end, I can tell you for sure that I want the flexibility of SQL. That means, for starters, I won't use ActiveRecord. Very probably the framework will only support MySQL...
    So, what you're saying is, you're gonna use a bunch of transaction scripts? I think that's a good fit for a lot of projects, but definitely not all of them.

    What it boils down to in the end is that there is no such thing as a golden hammer. No silver bullet. No knight in shining armor. No prince charming. Frameworks are not god. Heck, god probably isn't even god, but I digress.

    Frameworks are from Mars, Problems are from Venus. Frameworks are general, Problems are particular. Happy marriages are few and divorce rates are high. Whatever shall we do?

    Over there we have a problem saying, "I just need somebody to listen to me..." Then a framework comes along. "No time for that! Here's what we're gonna do!..." Problem sobs, "I just needed you to listen to me, you stupid, stupid man... er, framework!"

    Ah, and I definitely need to get more sleep at night.

    This is not the best way to do it. It is MY best way. I don't think there's a right and wrong way to design a system. As long as it meets your requirements it is done the right way.
    Maybe not wrong and right, but definitely a way to do it that is open to change and way to do it that makes change beyond a certain point very difficult. Further, a good domain model will actually suggest new functionality, perhaps even demand it, whereas more technology-oriented approaches will not. Eric Evans talks about this a bit in DDD.

    I also think PHP is missing a good IDE. It has tons of editors but absolutely no IDE. Syntax highlighting and code completion are functions of an editor not those of an IDE btw.
    IDE = Integrated Development Environment. By definition, if you can do all of your development work inside of a particular tool, that tool is an IDE.

    PDT sits on top of a very powerful IDE known as Eclipse. You can manage database tables, debug code, etc. Even better, if some piece of functionality isn't there, you can create it. Write a plugin or something. Contribute it to the community.

  9. #34
    SitePoint Addict webaddictz's Avatar
    Join Date
    Feb 2006
    Location
    Netherlands
    Posts
    295
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by cuberoot View Post
    Over there we have a problem saying, "I just need somebody to listen to me..." Then a framework comes along. "No time for that! Here's what we're gonna do!..." Problem sobs, "I just needed you to listen to me, you stupid, stupid man... er, framework!"

  10. #35
    SitePoint Guru
    Join Date
    Jan 2005
    Location
    heaven
    Posts
    953
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by jackmk View Post
    I also think PHP is missing a good IDE. It has tons of editors but absolutely no IDE.
    PHP doesn't need an IDE... Just stop using windows and you'll be fine.

  11. #36
    SitePoint Member
    Join Date
    Jul 2008
    Posts
    15
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    For me as I said the speed of the application is important. Also having a framework is important. Even if just to have a clean standard code structure. Some useful components that i use a lot come in handy too - validation, data grid, email sender, etc. The more functionality you want out of the box the more complicated it gets to build a system that can offer that functionality while staying flexible. Look at wordpress - a popular system, extensible, but with a poor design. When you add poorly designed plugins (most of them are like that) to it it crawls even worse. Same story with many CMS'.

    I think the main role of a framework (i am using this term very loosely) is to speed up the development time. Even if you don't use an existing framework, when you develop a large app you will eventually end up with a framework anyway. After all the principles behind OOP are there to eliminate code redundancy and to improve your development time and code clarity. Reusability, extendability, etc. are all useful because they cut down development time (if done right). The reason why I say that PHP is lacking a IDE is because in order to obtain really good development time you need support. You can obtain this support by using custom coded tools but ideally you should have a good IDE that can do everything you need. You need an IDE that "thinks" PHP+SQL+AJAX+XML+WebServices as a whole not PHP and SQL and maybe AJAX, XML, etc. You need a IDE that "thinks" in terms of web development not programming. Hawing a good approach when developing an application does not compensate for lack of proper tools.

    IDE = Integrated Development Environment. By definition, if you can do all of your development work inside of a particular tool, that tool is an IDE.

    PDT sits on top of a very powerful IDE known as Eclipse. You can manage database tables, debug code, etc. Even better, if some piece of functionality isn't there, you can create it. Write a plugin or something. Contribute it to the community.
    No IDE was able to do more than 40% of what I would have liked it to do.
    I used PDT. I used PHPEclipse, Aptana, Zend, Zend for Eclipse, Dreamwawer, some linux editors, Vi (pretty impressive once you get to learn it well, though I don't really like that style). I have been coding in PHP for 7 years. 1 year I worked in Java SE (desktop apps) using NetBeans. NetBeans can be considered a good IDE for Java. Eclipse too (for Java) though i like netbeans more. I think Java and it's IDEs are at miles ahead PHP and its editors. I don't want to start a flame war but it's the true. Argue with me only if you've used both. Part of the poorly designed PHP apps have to do with the fact PHP is an easy language to learn as opposed to Java. It allows you to do many things without hitting you in the head with it's rules (like Java does). They both (java and php) have pros and cons, but i think Java forces you to code better than PHP does. Java has patterns in its blood and they are all glued together nicely and they are the result of good design decisions regarding the language. PHP has no patterns. You make the patterns if you want. And, in many cases you make the wrong design decision if you choose to implement patterns in PHP. The way PHP is built as a language and the way it works internally (including as a component of LAMP) is not very pattern friendly. I think one should design PHP apps without patterns in mind. If it happens to end up implementing patterns OK, but don't start with that thought in mind.

    Oh, by the way, I'm using Java as a comparison not to put PHP in a bad light but to emphasize certain aspects. In case you ware wondering...

    So, where was I? Oh yeah, patterns. Now, my favorite pattern - MVC. So many frameworks implement it. And is borrowed from Java. It is however implemented a bit different in PHP. And from what I have studied, while a useful pattern because it separates things logically, it makes more sense the way it is implemented in java than the way it is implemented in most PHP frameworks. Unfortunately, I know no other approach that would be better than MVC. And please understand that I don't like in any special way the pattern itself, but the fact it separates things. There's also 3-tier. Which is not identical to MVC though it seems it is. I think you can read about the differences on Wikipedia.

    So, IDEs, patterns, attacking PHP... where am I heading to? PHP is being used in ways it was not initially intended to be used. It was made to enhance your web pages not as an enterprise development platform. Necessity pushed it where it is today. Even more, it has features that are useless.

    In PHP5, among features that are useful some are 100% useless. Like Interfaces which offer no real advantage in PHP. If you think you need interfaces in PHP you know PHP less than you thought you do. Interfaces are needed in Java and other languages but not in PHP. Why? PHP is a weakly typed language as opposed to Java which is strongly typed. Using Interfaces in PHP means just that you're coding things you don't really need.

    With PHP5.1 PDO support was added to PHP. A nice feature that I only discovered a short time ago. This feature existed in Java since the begining. It was actually needed in Java in order to conform with its strong OOP model. Implementing a custom PDO or DB abstraction layer system in PHP makes things much slower than limiting yourself to one RDBMS system and using just mysql_* or pgsql_* functions because instead of calling for example mysql_query() you need to call a function that calls mysql_query() and does other things too. Native PDO from PHP, while I haven't benchmarked it yet, should be much faster.

    So, PHP is not Java and should not be used in the way Java is used. Never forget what PHP is and it's limitations or you will pay for your ignorance. There are things in PHP that would amaze you to know. Like for example the fact $[0]='a'; is faster than $['zero']='a'; Including a bunch of files while convenient, is very slow. I mean really slow. Even while using APC or other opcode cache.

    Tony Marston took an interesting approach. He uses a tool to help him in development. I haven't read the details yet but if it works how I think it works, it is very similar to an idea I've came up with. This approach will improve development time without affecting performance. You use a tool to generate classes that make the DB structure (metadata) available to PHP. I think it is an elegant solution. And it supports my statements that PHP is lacking a good IDE. Of course, the reason why is lacking a good IDE has to do with the fact it is a very flexible language as opposed to Java which is all patterns. So you actually need a framework for PHP - as in a structure - and based on that you build an IDE that takes a lot of the work you do and does it itself. Zend seems to do this, but unfortunately at this moment I don't like Zend framework that much.

    So I wrote a lot off topic here lol. Just wanted to explain my view on PHP patterns and limitations better. The thing is I have no idea how to best implement model classes. If you're OK with PHP5.1+ PDO will be useful. I liked Tony Marston's Object-Oriented Programming for Heretics. Not sure if eventually I will use the same one class per table approach but his ideas make sense. So I suggest you read them if you haven't already. Studying how other people did it, even if it doesn't prove to be the best way for you too, is invaluable.

    I am sure some will agree with me and some will not (fully or partially). I am by no means the smartest guy around and I am sure I'm not always right. However, If you have a different opinion please base it on your own experience and as a comparison with what I say otherwise you're just attacking my idea without any solid support and I can't learn anything from you if you do that. Oh and just to be clear, I don't think any of your approaches are bad. But some of them, while having a nice and clear OOP structure, seem to require more handcoding than I like.


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
  •