SitePoint Sponsor

User Tag List

Page 2 of 5 FirstFirst 12345 LastLast
Results 26 to 50 of 101
  1. #26
    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)
    But I'm still very much into the idea of a CoR-type of applicationflow, which lets you stick other Handlers inside the CoR if one fail.
    Well, I kind of do the opposite. In my FrontController I have a ControllerChain. This is modeled over the InterceptingFilter pattern, so that each Controller in the stack, gets it's go at the incomming Request, after turn. If one of the Controllers decides that it wants to handle the Request, it will do so, and won't advance the ControllerChain any further. The last Controller in this chain tends to be an instance of DefaultController, witch just throws a 404.

  2. #27
    SitePoint Guru thr's Avatar
    Join Date
    Jun 2003
    Location
    Sweden
    Posts
    664
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    This was kind of what I had in mind. Or well, something similiar - exactly how do you implement it? Are you willing to share some code(or atleast techinical directions) ? How do you mapp your ControllerChains to specific actions? How do you take care of authentication? Form validation? etc.

  3. #28
    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)
    How do you mapp your ControllerChains to specific actions?
    It's a two-step approach. The FrontController has a ControllerChain, witch contains Controllers (bad name really, but i ran out of nouns). One of the Controllers is an ActionController, witch inspects the incomming Request and selects an appropriate Action.
    Next, the ActionController sets up an ActionChain, and adds the Action to it. It then executes the ActionChain.
    Each Action returns a Response, witch may either be a Redirect or a Component. If the Response is a Redirect, execution is halted, and the Request is redirected. If it's a Component, the next Action in the ActionChain is executed, while getting the previous Component passed as argument. This allows to wrap several Components together in a CompositeView-pattern.
    I deliberately left authentication out of the example, since it may be implemented on different levels, and depends much on the needs of a particular project. Form validation is handled by the individual Action, with a Validator-object (witch belongs somewhere inbetween Controller/Action and Model)

    Note : Objects/Classes are in bold, Concepts/Patterns are in italic

  4. #29
    SitePoint Guru thr's Avatar
    Join Date
    Jun 2003
    Location
    Sweden
    Posts
    664
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    That seems like a realy nice structure you got going there. What type of different controllers(You only mention ActionController) do you have? And if the Action returns a Redirect, is it a Redirect to another Action or a client redirect thru the URL? If I got this right a Component is basicly the result of an action that has been run already that is passed to another Action in the chain?

    How do you handle the mapping between the different Actions and Controllers(For example if you want several Action and Components wrapped together with the CompositeView). Do you put it as different return statements in the code. Or do you use some type of mapping file?

  5. #30
    Non-Member
    Join Date
    Jan 2003
    Posts
    5,748
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    doing a Tony?
    What you mean? Maybe we could use that expression to describe a tendancy to take

  6. #31
    SitePoint Enthusiast
    Join Date
    Sep 2004
    Location
    S. Florida, USA
    Posts
    60
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by kyberfabrikken
    It's a two-step approach. The FrontController has a ControllerChain, witch contains Controllers (bad name really, but i ran out of nouns). One of the Controllers is an ActionController, witch inspects the incomming Request and selects an appropriate Action.
    Next, the ActionController sets up an ActionChain, and adds the Action to it. It then executes the ActionChain.
    Each Action returns a Response, witch may either be a Redirect or a Component. If the Response is a Redirect, execution is halted, and the Request is redirected. If it's a Component, the next Action in the ActionChain is executed, while getting the previous Component passed as argument. This allows to wrap several Components together in a CompositeView-pattern.
    This is something like what I was describing earlier.
    But in my version, I call your ControllerChain, intercepting filter chain.
    Which contain filters which you call Controllers.
    Your ActionController, I call bootStrapFilter.
    The difference between our descriptions, are that, from what Im understanding, is that your controllers (filters in my case), returns
    a response (component or redirect).
    In my case, I have it so that filters (controllers in your case), are oblivious to each other, so they don't know who was before or after them in the chain.
    So they can only do the job they were designated to do, or perform a redirect, (either client or server side, of which the server side method Im still iffy on) if they choose to do so.

    Side note.
    This naming thing is getting on my nerves.
    I need to go back over the archives, and see if a standard was ever devised (for php that is).

  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)
    What type of different controllers(You only mention ActionController) do you have?
    On my public FrontController I have the following stack :
    Code:
    $controllerChain =& new ControllerChain();
    $controllerChain->push(new Authentication());
    $controllerChain->push(new NodeController());
    $controllerChain->push(new DefaultController());
    While my backend has this stack :
    Code:
    $controllerChain =& new ControllerChain();
    $controllerChain->push(new Authentication());
    $controllerChain->push(new ActionController());
    $controllerChain->push(new DefaultController());
    The NodeController inspects the REQUEST_URI and from this, selects a Node-object (part of the Model). The Node-object has an Action-property, witch is used to instantiate an Action. This Action is then added to an ActionChain, and the ActionChain is executed.

    The Authentication just identifies you. The actual authorization is handled later by each Controller. (Or Action)

    And if the Action returns a Redirect, is it a Redirect to another Action or a client redirect thru the URL?
    The Redirect is just a wrapper around a url. The url may be created from an Action (Most often it is). The ActionChain handles it by throwing a header() call and exiting.

    If I got this right a Component is basicly the result of an action that has been run (...)
    Yes. The most common Component is a Template or a StringComponent, witch is just a wrapper around a string.
    In a real-world(tm) setup, the ActionChain would consist of several Actions, but this isn't mandatory. If the last Action in the ActionChain returns a Component, the ActionChain will pass this all the way back to the FrontController, witch will call it's render() method, and echo to the useragent.

  8. #33
    SitePoint Guru thr's Avatar
    Join Date
    Jun 2003
    Location
    Sweden
    Posts
    664
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    trini0: Yes, the nameing is going to kill me to. Another thing I'm curious(spelling? =p) about in your aproach is how do you handle say - the main page for a completex site such as sitepoint.com ? Where you need to render a multitude of different parts needed (latest news, articles, blogs, etc.) with your aproach?

  9. #34
    SitePoint Guru thr's Avatar
    Join Date
    Jun 2003
    Location
    Sweden
    Posts
    664
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by kyberfabrikken
    The NodeController inspects the REQUEST_URI and from this, selects a Node-object (part of the Model). The Node-object has an Action-property, witch is used to instantiate an Action. This Action is then added to an ActionChain, and the ActionChain is executed.
    Ok - and a Node is what? A page (for example the index page that hits you when you first enter the sit) ?

    Everything else I got, but what exactly are Nodes?

  10. #35
    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 trini0
    This is something like what I was describing earlier (...)
    My ControllerChain implements the InterceptingFilter pattern, and my Controllers are Filters in regard to that pattern. So I guess we pretty much agree on that.

    Quote Originally Posted by trini0
    In my case, I have it so that filters (controllers in your case), are oblivious to each other, so they don't know who was before or after them in the chain.
    They have the same luxury in my setup. The Response is something happening in the ActionChain. Each Controller is just concerned with the incomming Request, and has the option to either take the initiative, or pass.

  11. #36
    SitePoint Enthusiast
    Join Date
    Sep 2004
    Location
    S. Florida, USA
    Posts
    60
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by thr
    trini0: Yes, the nameing is going to kill me to. Another thing I'm curious(spelling? =p) about in your aproach is how do you handle say - the main page for a completex site such as sitepoint.com ? Where you need to render a multitude of different parts needed (latest news, articles, blogs, etc.) with your aproach?
    This reply assumes that I understand what you're talking about.
    If I read you right, you're talking about the different sections (blocks if you will) of a page?
    If this is what you mean, here is my reply ->
    In my opinion, those different sections, should be dictated by the view (or more specifically the html/php template).
    I've only been doing this *hard core* OOP thing for the past few months, so I may be wrong.
    But the direction I was heading, was to dictate different parts of the page,
    by the template.

  12. #37
    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 thr
    Ok - and a Node is what? A page (for example the index page that hits you when you first enter the sit) ?
    The Node object is realy a mapping between Request and Action. A Node has a title/path, witch is used to select it from the database, depending on the incomming REQUEST_URI (depends a bit on mod_rewrite here). Apart from "action" and "title", the Node also has a "section" property. The "action" will be the name of a Action, witch decends from NodeAction. When the NodeAction executes, it will instantiate an Action with the name of it's "section", and add this Action (the SectionAction) to the ActionChain.

    Did that make sense ?

  13. #38
    SitePoint Guru thr's Avatar
    Join Date
    Jun 2003
    Location
    Sweden
    Posts
    664
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by trini0
    This reply assumes that I understand what you're talking about.
    If I read you right, you're talking about the different sections (blocks if you will) of a page?
    If this is what you mean, here is my reply ->
    In my opinion, those different sections, should be dictated by the view (or more specifically the html/php template).
    I've only been doing this *hard core* OOP thing for the past few months, so I may be wrong.
    But the direction I was heading, was to dictate different parts of the page,
    by the template.
    Ah yes, that was my question. While, yes, these parts should be displayed and put to proper use in the View. But you have to pull the data inside the model, don't you? So do you go with one "big" action for the whole page - like "index.php?action=ShowMain" or something like that?

  14. #39
    SitePoint Guru thr's Avatar
    Join Date
    Jun 2003
    Location
    Sweden
    Posts
    664
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by kyberfabrikken
    The Node object is realy a mapping between Request and Action. A Node has a title/path, witch is used to select it from the database, depending on the incomming REQUEST_URI (depends a bit on mod_rewrite here). Apart from "action" and "title", the Node also has a "section" property. The "action" will be the name of a Action, witch decends from NodeAction. When the NodeAction executes, it will instantiate an Action with the name of it's "section", and add this Action (the SectionAction) to the ActionChain.

    Did that make sense ?
    Yes, (I think =p). But why do you seperate Nodes and Actions - in your backend you say that you have "ActionController", and in your fronend "NodeController" - If a node basicly is a mapping to an action, why not send the action instead?

    ( Edit: ) Oh, and yes: I feel that your ControllerChain looks more like a Chain of Responsibility then a Intercepting Filter Chain - mainly because if the ActionController can handle the request, then DefaultController is never executed (if i got thing right) - from what I understand of the Incercepting Filters all elements in a IF Chain should be executed?

  15. #40
    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)
    The Node is a content-entity, while the Action is ... well an Action. I would generally have one Action per contenttype. For example a ArticleNodeAction. When I create a new ArticleNode, it will per default be associated with the ArticleNodeAction.
    The aim is to make a logical directory-structure. Instead of example.net/?action=ArticleNodeAction&nodeId=22, I would have something like this : example.net/Articles/SomeArticle. In this example, SomeArticle will map to a ArticleNode, witch has an ArticleNodeAction. If the user decides to remove the last part of the url and end up with example.net/Articles, he will select a DirectoryNode witch has a DirectoryNodeAction.

    On the backend, I have no need for logical structures - it's less content-oriented, more task-oriented, so I just map a action-parameter from the $_REQUEST to a Action. For example : example.net/backend/RemoteGetNodesByParentAction&parentId=1

    Quote Originally Posted by thr
    if the ActionController can handle the request, then DefaultController is never executed (if i got thing right)
    You got it right.

    Quote Originally Posted by thr
    from what I understand of the Incercepting Filters all elements in a IF Chain should be executed?
    I should say, that's the Intercepting in InterceptingFilter ? But then again - I'm not sure either if the controllerChain is better described as CoR or IF.

  16. #41
    SitePoint Enthusiast
    Join Date
    Sep 2004
    Location
    S. Florida, USA
    Posts
    60
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by thr
    Ah yes, that was my question. While, yes, these parts should be displayed and put to proper use in the View. But you have to pull the data inside the model, don't you? So do you go with one "big" action for the whole page - like "index.php?action=ShowMain" or something like that?
    I haven't thought of everything that far as yet, but here is the basic idea.
    For now, lets call these page sections blocks.
    I setup a structured directory, which contain contain folders,
    where each one represents a block.
    Each block should contain code that represents a controller, a view, and a model.
    In the main page template, create xml tags, that I can read via maybe some
    DOM wizardry, and execute the blocks as needed.

    So its like an MVC pattern within an MVC pattern.
    Where the main MVC is dictated by client requests, and the mini MVCs are dictated by the template & client request.

    For now its still an idea...

  17. #42
    Non-Member
    Join Date
    Jan 2003
    Posts
    5,748
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    The actual authorization is handled later by each Controller. (Or Action)
    I'm still reading over the recent posts though I like where it's all going. I have a basic understanding of the CoR myself now (thanks in some part to McGruff) but leaving that for now, and getting back to the quote, how about this?

    PHP Code:
    ...
    if( 
    Permissions::hasPermission$action -> isSecure(), $request -> getParameter'action' ) ) ) {
    ... do 
    action ...
    }
    ... 
    Whereby the class method isSecure() of a given action is true (public) and false (private)? So if a page requires a user to be logged in, the resultant isSecure() would return false

    The Permissions class would verify the user is valid to carry out the action it's self if they're logged in, if they're not logged in the action is redirected or something... a 404 or whatever?

  18. #43
    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)
    Dr Livingston >
    The real issue is at what level to apply it. It could be done in the FC, by extending the Authentication object with your proposed code. Or it could be done in the ActionController/NodeController or it may even done by each individual Action. It really comes down to the degree of granularity you want. For instance, for the frontend I put the authorization in the NodeController, witch pulls a unix-style privilege-property from the Node.

  19. #44
    SitePoint Guru thr's Avatar
    Join Date
    Jun 2003
    Location
    Sweden
    Posts
    664
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by kyberfabrikken
    I should say, that's the Intercepting in InterceptingFilter ?
    I would not agree on that, as the thought behind intercepting filters is that they intercept the request, apply all logic needed on it and passes it to the next filter/real application. While the CoR looks for a element within itslef that can handle the specified request, and the elements after the one that can handle the request are never executed.

    Quote Originally Posted by kyberfabrikken
    The Node is a content-entity [....]
    So basicly a nodes and actions has a One(action) to Many(node) relationship?

    Now, to something totally different: Authentication and on what level. The problem I face now is that I prefer to implement Authentication on a level as high as possible to restrict how much data/application logic that has to be loaded if the user is not authorized. I've got some real issues on how to implement this - and currently I can only come up with an implementation that does it on the action-level. I would prefer to do any authentication before even the frontcontroller is loaded, but I dont think that is possible.

  20. #45
    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)
    Now, to something totally different: Authentication and on what level. The problem I face now is that I prefer to implement Authentication on a level as high as possible to restrict how much data/application logic that has to be loaded if the user is not authorized. I've got some real issues on how to implement this - and currently I can only come up with an implementation that does it on the action-level. I would prefer to do any authentication before even the frontcontroller is loaded, but I dont think that is possible.
    I tend to regard the FrontController as a abstract conecpt, involving anything before the Action. In that perspective it's not possible. You could however just pop a .htaccess file into the same dir as your bootstrapfile (index.php or whatever).

  21. #46
    Non-Member
    Join Date
    Jan 2003
    Posts
    5,748
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Kyber,

    Yes you are correct in that regard For me I don't see having the use of authentication in an action, but in the front controller. I have authentication (login) via an intercepting filter at the moment.

    This I feel, is where it belongs, the part I posted would act based on the SESSION for that user as I see it, regardless of they've logged in or not, permissions returns a result?

    Thr,

    as the thought behind intercepting filters is that they intercept the request, apply all logic needed on it and passes it to the next filter/real application.
    From my understanding, the intercepting filter(s) can (and do) act upon a request, though they're not solely the only task of the filtering process? ie You can buffer (cache) content via a filter, which has nothing to do with a request.

    McGruff has made a point now and again of quantifying a request for security reasons which is great but as I see it intercepting filters can do more besides validating a request? I think (from memory) McGruff doesn't use intercepting filters for validating anyways but don't quote me on that

    On the point of the CoR you have the same understanding of what I have at the moment

  22. #47
    simple tester McGruff's Avatar
    Join Date
    Sep 2003
    Location
    Glasgow
    Posts
    1,690
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    I'm getting behind here - there's a lot of stuff I'll try to reply to later.

    Quote Originally Posted by thr
    Authentication and on what level.
    ...
    I would prefer to do any authentication before even the frontcontroller is loaded, but I dont think that is possible.
    Authentication might be an ApplicationController responsibility or it might be carried out at the action level.

    Where there are a series of possible pages which might be served in repsonse to a single request, ApplicationController makes the decision. (There always are and you always need an ApplicationController). If you show a login page when a user isn't authenticated, and the requested page when they are, that's one for the ApplicationController.

    At other times authentication might simply determine whether a layout contains a login box or a "welcome Joe" message. The same page, in a different flavour, is served in either case so ApplicationController isn't involved. Instead, a decision is made at the action level.

    Authentication state could be set anywhere, and queried where needed. As long as this is done before any authentication-dependant action or decision, you're OK.

  23. #48
    SitePoint Guru thr's Avatar
    Join Date
    Jun 2003
    Location
    Sweden
    Posts
    664
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Another question I have is, I've seen several small case examples of MVC applications. But with a realy big application - say sitepoint.com. How would one handle the part where you need to pull data from several different parts of the backend? When you need to display stuff like latest news, latest blogs, articles, etc. Do you execute several actions (for example: LatestNews, LatestBlogs, LatestArticles) and then put them together, or do you have one action named "Main"?

    What I realy want i is some way to just be able to, for example. create an action that for example get's a list from the model with the 5 latest blog entries. and then you can plug any view you want on that? And then be able to put several small actions together to form the whole page? There would need to be some type of ActionChain for this to happend tho, but well... :] any ideas? (100% pure modulearity would be ideal, so you can plug small parts of your page in and out ... but I think that subject is out of the scope for this discussion)

  24. #49
    SitePoint Enthusiast
    Join Date
    Sep 2004
    Location
    S. Florida, USA
    Posts
    60
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by thr
    And then be able to put several small actions together to form the whole page? There would need to be some type of ActionChain for this to happend tho, but well... :] any ideas? (100% pure modulearity would be ideal, so you can plug small parts of your page in and out ... but I think that subject is out of the scope for this discussion)
    Yes out of scope, but please do post a new topic as I too would like to see
    how others handle this, so I would know if my previous idea is a shot in the foot or not...

  25. #50
    simple tester McGruff's Avatar
    Join Date
    Sep 2003
    Location
    Glasgow
    Posts
    1,690
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    This is really the only part of sitepoint I read so I'm guessing those lists are all on one page somewhere.

    Don't quote me, but I think WACT does this with a sort of composite MVC approach. Each request is observed by mini-MVC controllers each of which create a part of the page and (I think) are observable in turn. A single request creates a cascade of nested sub-controllers. Nice idea - if I got that right.

    A chain is another option. ChainOfResponsibility (in its queue form rather than it's strict GoF definition where it makes a decision of some kind) and Observer are actually very similar.


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
  •