Jump to content

mr groovy

Members
  • Posts

    14
  • Joined

  • Last visited

    Never

Profile Information

  • Gender
    Not Telling

mr groovy's Achievements

Newbie

Newbie (1/5)

0

Reputation

  1. Hi, I am designing an implementation of the data mapper pattern, for school and to get an understanding of what is under the hood of all the ORM systems out there. The mapping itself is no to hard te get done, automaticly using relation information to extract unique objects from a resultset consisting of multiple joined tables (this is called hydration by other systems i think). These unique objects are then stored in a central space: the identitymap. When a query with joins is performed the objects can be connected: Objects with a foreignkey know exactly how to find the object they belong to, the can find it in the identitymap (this is 1:1). At the other end of the relation there is a collection (1:many) So when domainobjects are created they are added to the collections at the other end of the relation. This is my problem: Becouse the objects in the identitymap are used in the whole system, changes to these objects will have an affect everywhere. So when many querys are run (the one with many where claues the other with limit claues and so on) The collections will contain unexpected data. <?php $authorMapper = new authorMapper(); // First query: NO PROBLEMO! $authorCollection = $authorMapper->findAuthorsInnerJoinBooks(); foreach($authorCollection as $author){ // . . . foreach($author->books as $book){ // . . . } } // Second query: more specefic collections $authorCollection2 = $authorMapper->findAuthorsAndFiveNewestBooks(); foreach($authorCollection2 as $author){ // . . . foreach($author->books as $book){ /* The books collection inside the author objects would still contain ALL data from the table becouse of the first query and not the five newest books. */ } } However i may have answer to this: Just dont store collections in the identitymap. Just store objects with unique data in the identitymap and never let them refer to each other directly. And then create a decorator(s) around these raw data objects. This way the decorator can access the data in the identitymap and have its own collections at hand. Its like composing a graph of objects. What do you people say and think? does this make any sense ? and if not, why not ? Please tell me if i got some basic ideas wrong, i want your thoughts.
  2. Really thanks for the suggestions, This article sums things up nicely: http://www.sitepoint.com/article/beyond-template-engine/ I thought template engines where the best things posible but now i am convinced they are nothing but overhead and added complexity, it is a real eyeopener for me. Thanks for the help!
  3. Hi, Yes what you say does make sense to me. I have used a template system before and i liked it, becouse it completely seperates PHP from html. Using php inserted in a HTML file seems te give more freedom, becouse php can do anything i want when i want in the template. With a template i am stuck with the tags and blocks and need to write code to manage calls to template functions. It was fun to write a templating engine, i have really learned alot about regular expressions through that (nested blocks where a real challenge). But if there is a better and simpler solution then i am allways open to it and will look into it.
  4. Maybe if you want a cleaner HTML source, you can check for redundant closing tags. I see in the HTML source closing </a> and </span> tags while there is none opened.
  5. Like this: <?php if(!empty($row_Recordset1['coupon'])){ echo '<a href="/images/coupon/' . $row_Recordset1['coupon'] . '" target="_blank" class="style3">Coupon</a>'; }else{ echo 'no coupon'; } ?> Just add a else block, it get's executed when the if conditions where false. but i would make the final code like this: <?php if(empty($row_Recordset1['coupon'])){ //empty() returned true : so there is nothing echo 'no coupon'; }else{ //empty() returned false so it is NOT true that there is nothing //so we can print it out: echo '<a href="/images/coupon/' . $row_Recordset1['coupon'] . '" target="_blank" class="style3">Coupon</a>'; } ?> To make it more readable, otherwise you check for sometinh being not true. They both behaive the same but the code looks simpler. I hope i did not confuse you
  6. Now i see, there is no image link for every item in the row. In the HTML source i see that all rows except one has empty links. You can make a if statement to check if content is present and not just output it without checking. This can be a solution: if(!empty($row_Recordset1['coupon'])){ echo '<a href="/images/coupon/' . $row_Recordset1['coupon'] . '" target="_blank" class="style3">Coupon</a>'; }
  7. Then it is as easy as i say in reply #8: Just put the text "coupon" between the anchor tag: <a href="www.foo.bar">Coupon</a>
  8. Ok, so you now know i dont quite understand the problem you are facing. Maybe you can give more details about your situation. I really would like to help and give suggestions but it's not clear for me what the situation is :-X
  9. Yes i think so if i understand it correctly, if you allways want is to say "coupon" then simply do this: <a href="/images/coupon/<?php echo $row_Recordset1['coupon']; ?>" target="_blank" class="style3">Coupon</a> But it cant be that easy i must miss something.
  10. <html> <head> <style> #myImage { display: none; } </style> <script> function toggle(){ img = document.getElementById('myImage'); if(img.style.display == 'none'){ img.style.display = 'block'; }else{ img.style.display = 'none'; } } </script> </head> <body> <img src="image.jpg" id="myImage" /> <span onclick="toggle()">KLIK ME!</span> </body> </html> This a simple toggle javascript. But i think you don't want to do it client sided when i read the other posts. Anyway, i hope you ll find a solution that suits you.
  11. Hi, You could do it with javascript. Just make the link and put a onClick event in it. Also give the image a id so you can call it and controll it's properties. The function is getElementById('yourID') to get a handle to it. Then you can change css properties so you can toggle display. I hope it is helpfull
  12. Hi, thanks for the reply, Really helpfull, I will look into view helpers. First thing that showed up in google: http://blog.rvdavid.net/template-view-and-view-helper-design-patterns-in-php/. Ok, i thought views where not allowed to do anything, not even call functions. I thought they are more or less passive and only waiting to be assigned with values from smarter objects. Things will fall into place now, thanks alot
  13. Hi, I am new to phpfreaks.com, this is my first post. I am writing a object oriƫnted framework with the Model View Controller concepts in mind, but have a question. I know the basics of MVC: a frontcontroller recieves the URI and selects a controller to call the right action (function that is). Inside this action function models are being used for data manipulation and that is assigned to a view for display. For the views I use a self made template system that can replace tags and supports nested blocks. The basics of MVC are not really a problem, there are enough examples on the internet to be found (including the wiki of phpfreaks.com). But my question is about the complete presentationlayer: the whole template where the view generated by the action function is being put into. The template that wraps everything has logic of it's own like building a navigation with extra buttons depending on if the user is logged in or not. Where to put this code? and how will it fit into the MVC pattern? One way that pops in my mind is making a base class for all controllers. Then subclass the base controller with common functions for layout logic. Then subclass that controller to re-use the functions. This way i can create a heirarchie for different layouts in the website. I would really like to hear your thoughts about this design problem. Any help is welcome!
×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.