Lithium applications beyond CRUD

This is a more or less basic version of the stack overflow question , which talks about how most of the introductory materials in MVC applications tend to present a tight connection between models, views, and controllers. For example, you will have a User table that will be modified by the user controller, which in turn repels the filtered data in the user's view. I got the impression that many MVC frameworks tend to reflect this model. It’s all good and good what it is, but it never leads me to anything other than building and displaying monotonous lists of things with an HTML form.

The MVC structure that now looks is Lithium , which seems pretty interesting, as an example of PHP5.3's smart coding methods. At one end, Lithium has a Model class that offers wrapper objects around individual tables and abstracts some simple queries. On the other hand, he got an excellent agreement on the routing of URLs for method calls on controller objects, which are then displayed to display patterns.

But in the midst of this, I don’t understand where to place all the interesting logic that links the data in table A with the data in tables B through Z. Or at least I'm not sure where to place such logic in such a way that it matches the design structure. As far as I understand, the abstraction of the Lithium Model not much more than the removal of some insert / update / delete pattern at the row level, and the controller / view architecture is mainly related to the user interface. I would not want to put a lot of business logic in the same Controller class, which receives routed function calls from URL requests.

My instinct was to fill the gap with a bunch of my own code that exists more or less completely out of the box. I'm not sure I should expect more than that, but given how rigidly everything else in Lithuania is structured, it feels somehow unsatisfactory, as if I could just reel my own code reduction code without the overhead of the source great structure.

What am I missing here? Is there a recommended architecture or philosophy for using this type of framework?

+6
php model-view-controller lithium
source share
1 answer

One thing you should remember with Lithium is that the finished product is not ready yet (although some sites use it in production). The main missing feature now is model relationships. With relationships in place, I assume that your question will be partially addressed, as this is an important brick in the overall picture of creating more complex applications. You can check the x-data branch, where work on relations should continue.

For the second part of writing domain logic, the simple answer is "in the model." See this (rather useless) example of extending model functionality , for example. Another example to consider is the open source gadget, which is one of the few open source examples of lithium used. The analog model model shows a slightly fatter model.

And finally, the question of connecting the dots between M, V, and C. The lithium controller should basically delegate tasks to the models and, possibly, restructure the input if necessary. Simple examples of having a Post model, PostsController, and views / posts / add, index, etc. Do not mean that you should just have Post :: all (). PostsController :: view needs to load a set of comment models, perhaps.

This way, of course, you will throw a lot of your code. Otherwise, it will not be a large number of applications. But keep the domain logic tied to a model where it is natural.

  • Need to verify that your blog has a unique title? Write a validator.
  • Need to ensure that the user has write access to the message? Override the save method and check it or filter it.

But I think that we need to wait for the relationship on land and release 1.0 before we can fully judge how best to allow structuring applications in Lithuania.

+8
source share

All Articles