SitePoint Sponsor

User Tag List

Page 4 of 5 FirstFirst 12345 LastLast
Results 76 to 100 of 101
  1. #76
    SitePoint Evangelist Ian R. Gordon's Avatar
    Join Date
    Feb 2004
    Location
    New York
    Posts
    474
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Is anyone taking into consideration that PHP4 is still used by a majority of web hosts, so posting PHP5 examples might hamper development of good code for people still using PHP4?

    In any case, I think this has gotten way too complicated, from my perspective at least. I am simply wondering how I can do the following:

    1. User Requests Page
    2. Application Begins by accessing Database
    3. Determines necesary action based on request (i.e. index.php?cat=apples&page=green)
    4. Grabs page data from database
    5. grabs template xhtml from database
    6. Application puts data in template via variables (i.e. $_PAGE['Title'], $_PAGE['Body'])
    7. Sends result to browser
    Ian Gordon
    CSS / XHTML / PHP Programmer
    http://www.iangordon.us

  2. #77
    eschew sesquipedalians silver trophy sweatje's Avatar
    Join Date
    Jun 2003
    Location
    Iowa, USA
    Posts
    3,749
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by Ian R. Gordon
    Is anyone taking into consideration that PHP4 is still used by a majority of web hosts, so posting PHP5 examples might hamper development of good code for people still using PHP4?
    Have you considered that in open source, and on forums, people work on what interests them?

    This may or may not happen to match your current set of requirements. Judging by the responses you are getting, no one wants to work on a PHP4 only CMS which store it's action mappings and templates in a database. I don't blame them, from the outset that is a set of requirements for a dog slow application.

    It seems like you have a very definite perceived need to know something, as you have been posting entries on every MVC thread in the Advanced PHP forum. Every time someone response, you seem give them a terse brush-off, apparently because their response is not served up on the golden platter of your desired requirements.

    Perhaps you would be better served by reviewing at the code already posted in these threads with an open mind, and adapting it to your own requirements, rather than asking every forum poster to do that for you.
    Jason Sweat ZCE - jsweat_php@yahoo.com
    Book: PHP Patterns
    Good Stuff: SimpleTest PHPUnit FireFox ADOdb YUI
    Detestable (adjective): software that isn't testable.

  3. #78
    Non-Member
    Join Date
    Jan 2003
    Posts
    5,748
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    SweatJe,

    Having a lot of respect for yourself, I find it difficult to understand your attitude in what you've posted?

    Anyways, to answer some questions

    You could create an instance to your database at the top of the page and pass this around although I'd favour using a Singleton so there would be no need to pass the connection around?

    A Front Controller can decide how to dispatch an action to a Page Controller for example? A Front Controller could simply be a SWITCH in some cases

    For gathering page information this should be a Model (MVC) which is delegated by what logic the Controller has for a given action. In the event you've put a template in the database this is a Model as well, in league with a View to render the template.

    Note (in my view) the View shouldn't know the source of the template. You have it in the database for the time being, but you may need to change this to a flat file later, so no, the View has no idea of where the template comes from

    Despite SweatJe's attitude, he does have a point however so I would add to what SweatJe has said, and read up on all the MVC threads

  4. #79
    simple tester McGruff's Avatar
    Join Date
    Sep 2003
    Location
    Glasgow
    Posts
    1,690
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    A template does not become part of the model just because it's stored in a db.

  5. #80
    Non-Member
    Join Date
    Jan 2003
    Posts
    5,748
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Well, yer you do have a point there McGruff but what I'm referring to as I see it you do need to fetch the template and for reasons I stated (portability <> reusability) I feel fetching the template it's self belongs in the Model

    Are you suggesting that the View fetches the template? I note some people feel that this is justified but I disagree on that point...

  6. #81
    simple tester McGruff's Avatar
    Join Date
    Sep 2003
    Location
    Glasgow
    Posts
    1,690
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    The template - and any code which applies formatting to page elements - IS the View.

  7. #82
    SitePoint Evangelist Ian R. Gordon's Avatar
    Join Date
    Feb 2004
    Location
    New York
    Posts
    474
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by sweatje
    Have you considered that in open source, and on forums, people work on what interests them?

    This may or may not happen to match your current set of requirements. Judging by the responses you are getting, no one wants to work on a PHP4 only CMS which store it's action mappings and templates in a database. I don't blame them, from the outset that is a set of requirements for a dog slow application.

    It seems like you have a very definite perceived need to know something, as you have been posting entries on every MVC thread in the Advanced PHP forum. Every time someone response, you seem give them a terse brush-off, apparently because their response is not served up on the golden platter of your desired requirements.

    Perhaps you would be better served by reviewing at the code already posted in these threads with an open mind, and adapting it to your own requirements, rather than asking every forum poster to do that for you.
    Actually that what I mean, I thought the point of the forum was to facilitate discussion on varied topics, I was asking a question because I don't know how to do it. Obviously in order to review code, I need code to look at, my point was that PHP5 code was posted and a majority of people still use PHP4 so could a PHP4 version of some of the MVC models be posted.

    How I decide to code my application is my business, you don't like templates in a database fine, I do, thats my choice. You don't need to tell me gonna be dog slow.

    In anycase, if you didn't want to give me an example or offer me help, you didn't have to make a post and "yell" at me. I am aware of what I did, I was simply seeking solutions.

    Quote Originally Posted by Dr Livingston
    Despite SweatJe's attitude, he does have a point however so I would add to what SweatJe has said, and read up on all the MVC threads
    I did read up on the MVC threads but, I was/am still confused. I was looking for some examples that don't make use of PHP5 because, I am still using PHP4.

    I am aware of WACT btw.
    Ian Gordon
    CSS / XHTML / PHP Programmer
    http://www.iangordon.us

  8. #83
    Non-Member
    Join Date
    Jan 2003
    Posts
    5,748
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    and any code which applies formatting to page elements - IS the View.
    Yes, that is correct McGruff. But how the View gets the template is what I'm talking about... Does or should it (the View) know about the database to fetch the template? I think not is where I'm at, and the reasoning where I said the Model should fetch the template

    That's my assumption of course and we all have our own idea of MVC so if I'm wrong or something, I'd be interested in knowing more myself now...

  9. #84
    simple tester McGruff's Avatar
    Join Date
    Sep 2003
    Location
    Glasgow
    Posts
    1,690
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    I can't follow your "reasoning" at all. The model knows nothing about views.

  10. #85
    eschew sesquipedalians silver trophy sweatje's Avatar
    Join Date
    Jun 2003
    Location
    Iowa, USA
    Posts
    3,749
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    I think the central disconnect here is the rule of thumb: all persistant storage (particularly db access) should be done through Model classes.

    Of course files are persistant storage as well, so even a Template based View which fetches templates as files is "accessing persistnant storage" without going through a view. I think the twist here is that most of the time the template is not normally in the database, so it spins peoples thinking in different directions.

    If the desire is to have the view maintain templates in the database, then the view should have a database connection passed to it and do it's work on it own. As I mentioned earlier, we have already "violated" the rule of thumb by accessing files to begin with, but it is an assumption engrained in our brains as "okay" so we move on without thinking about it until this desired behavior is presented to us in a new aspect (coming out of a db instead of the file system).

    Anyway, that is my take on the last few posts.

    $0.02

    Regards,
    Jason Sweat ZCE - jsweat_php@yahoo.com
    Book: PHP Patterns
    Good Stuff: SimpleTest PHPUnit FireFox ADOdb YUI
    Detestable (adjective): software that isn't testable.

  11. #86
    SitePoint Enthusiast
    Join Date
    Sep 2004
    Location
    S. Florida, USA
    Posts
    60
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by sweatje
    As I mentioned earlier, we have already "violated" the rule of thumb by accessing files to begin with
    I missed this one. Where did you mention it?

  12. #87
    eschew sesquipedalians silver trophy sweatje's Avatar
    Join Date
    Jun 2003
    Location
    Iowa, USA
    Posts
    3,749
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by trini0
    I missed this one. Where did you mention it?
    In the paragraph above it where I said "Of course files are persistant storage as well, so even a Template based View which fetches templates as files is "accessing persistnant storage" without going through a view."

  13. #88
    Non-Member
    Join Date
    Jan 2003
    Posts
    5,748
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Umm...

    Okay, not wanting to argue with anyone (McGruff) I'll just have to accept that the general consensus on this forum is that it's acceptable for the View in a given context to have a database connection, and just be done with it

    Maybe it's because as SweatJe says, not a lot of people use the database for template storage, and it's this approach I've not looked into much?

    Consider my view changed now McGruff

  14. #89
    SitePoint Wizard
    Join Date
    Aug 2004
    Location
    California
    Posts
    1,672
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Thank you sweatje for bringing something important to light.

    Let's remember that MVC is a pattern and a goal - NOT a design or a rule. Statements like:
    The template - and any code which applies formatting to page elements - IS the View.
    are erroneous at best. The template we are talking about here is data, it is not the View. Things like Template View and Transform View are patterns on which you can base the code design for parts of your View code. But those patterns and the code based on them are not template data. And View is not that concerned where the template data comes from. For example, any CMS that supports something like bbcode is fetching template data from a database and transforming it. It is very common practice.

    In the case described here you could implement a method in your Model code that fetched the template data, or you can just fetch the data directly. That most View code loads persistent data related to presentation without using the Model is common practice. This just shows that patterns are guides to practical implementions, not straightjackets for the mind.
    Christopher

  15. #90
    SitePoint Wizard DougBTX's Avatar
    Join Date
    Nov 2001
    Location
    Bath, UK
    Posts
    2,498
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by sweatje
    all persistant storage (particularly db access) should be done through Model classes.
    That's seems to stem from a confusion between "Model" and "Database Abstraction Layer". They are not the same thing, though it would be unusual for the Model to not use a DBA of some sort: but they are different things. One is Biz logic, the other is a way to access a storage mechanism.

    Douglas
    Hello World

  16. #91
    simple tester McGruff's Avatar
    Join Date
    Sep 2003
    Location
    Glasgow
    Posts
    1,690
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    I don't know why MVC causes so much confusion (admittedly it used to confuse me too) since it's really very simple.

    The important point is the separation of model from presentation. MVC further splits the UI into View and Controller.

    Quote Originally Posted by arborint
    Statements like...are erroneous at best.
    Just to avoid confusing people reading this thread, the View is in fact everything involved in formatting "raw" data obtained from the model ie templates and any code used to format data or make formatting decisions. A design might adhere to the presentation / domain / data source layering but if it doesn't also separate Controller and View it's not MVC. If it doesn't even split presentation from model, it's not worth wasting time on.

    Quote Originally Posted by arborint
    In the case described here you could implement a method in your Model code that fetched the template data.
    That's a flat no. Breaking VC separation might not be so bad, but breaking model / presentation layering certainly is.

    Quote Originally Posted by arborint
    The template we are talking about here is data, it is not the View
    It doesn't matter where or how it's stored it's still formatting ie View. Or View data if you want to split hairs.

    Quote Originally Posted by arborint
    For example, any CMS that supports something like bbcode is fetching template data from a database and transforming it.
    BBcode simply tags pieces of text which different views can interpret in different ways - that's when the formatting is applied. This is model data - not template data - which gets passed to the View. It's similar to the "display overdrawn accounts in red" example where the model might set some boolean flags indicating certain accounts are overdrawn then it's up to the View to decide how to format them. Php tags, for example, could be formatted in many different ways: with/without line numbers, in scrolling windows, with different syntax colours, etc. The model doesn't care - but it does know which blocks of text are tagged as php code.

  17. #92
    SitePoint Zealot
    Join Date
    Oct 2004
    Location
    naperville
    Posts
    189
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Consider my view changed now McGruff
    A pun. funny.

    I'm suprised the fact of file vs database template storage even came up - it shouldnt be an issue; it should (imo) be handled by a template-getter DAO and be decided by like a configuration flag. The method of access should never come up anywhere else. On the same note, I think passing a DB to a view is "ok" although not nescesarily the cleanest method. A singleton would hide this, but hiding is never good.

  18. #93
    eschew sesquipedalians silver trophy sweatje's Avatar
    Join Date
    Jun 2003
    Location
    Iowa, USA
    Posts
    3,749
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Off Topic:

    Quote Originally Posted by Super Phil
    A pun. funny.
    I personally think of it as a double-entendre, because I prefer not to be punished.

  19. #94
    Non-Member
    Join Date
    Jan 2003
    Posts
    5,748
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    A pun?? Well, I don't know as this wasn't the intention of that statement, I'm actually surprised now that some folks see it that way though

    I would like to reply to the recent posts made but I fear I might just start the ball rolling again so I'll keep quiet (for the moment at least )

  20. #95
    Non-Member
    Join Date
    Jan 2003
    Posts
    5,748
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    SweatJe,

    I've just gone and googled the double... as I didn't know what it meant, and I found a jokes site here in the UK

    Posted some examples, just for a laugh

    Edit:

    Inappropriate


    Last edited by seanf; Feb 19, 2005 at 06:39.

  21. #96
    SitePoint Addict lundberg's Avatar
    Join Date
    Mar 2003
    Location
    Sweden
    Posts
    370
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Hello again!

    I've been working on thr's example and before I was discussing it with him directly but after the big World of Warcraft influenza that has spread all over the world, I've not seen him online for a while. (I'm not sure this is the case)

    Where in his code example (picture, for those who have not checked the code) should I get information from the Model? Should I get it in the ViewController?

    Thanks in advance!

    Martin Lundberg
    Sweden

  22. #97
    Non-Member
    Join Date
    Jan 2003
    Posts
    5,748
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Er, what information are you talking about? I think this thread went off topic for a while there so excuse me while I got lost (still laughing from my last posting)

  23. #98
    SitePoint Addict lundberg's Avatar
    Join Date
    Mar 2003
    Location
    Sweden
    Posts
    370
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    hehe, some laughter is allways good in all the confusing posts!

    The picture im talking about is at this post: http://www.sitepoint.com/forums/show...5&postcount=70

    and the code at this: http://www.sitepoint.com/forums/show...0&postcount=74

    and if I understood you wrong and you mean the information that I said I should get from the model. I ment well, information from a database. Let's say I'm going to show a userlist, the UserList action is requested, where in the code is the users actualy taken from the database, that is where should the Model come in? I this code right now, is there a model at all? For mee it feels like alot of controllers and alot of views =)

    Martin Lundberg
    Sweden

  24. #99
    Non-Member
    Join Date
    Jan 2003
    Posts
    5,748
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Here is an example off the top of my head, and thus its just a simple example

    PHP Code:
    class UserListAction {
    ...
    public function 
    execute() {
    $model = new UserListModel// dumb name btw
    $lists $model -> findById$_GET['id'] ); // do not use $_GET directly either ;)
    ...
    $view = new PagePrinter'templates/basic-template.tpl' ); // the view
    $view -> assign'list'$lists );
    ...
    }
    ...

    So the View would have an Iterator to iterate over the lists, which'd be (typically) an array for each row you pull out of the database?

    This is a basic example though but I hope it gives you some ideas anyways

  25. #100
    SitePoint Addict lundberg's Avatar
    Join Date
    Mar 2003
    Location
    Sweden
    Posts
    370
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Thanks! I think I got how I'm supposed to do it, thanks.

    Martin Lundberg
    Sweden


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
  •