On 4/20/07, Heather <[EMAIL PROTECTED]> wrote: > Ok, so the whole MVC set up of the file system of projects is fine, > makes sense. At the high level, anyway. But when we start getting > more specific, that's where I have questions.
I reordered your questions in a way I think is easier to explain. > Models-> This part seems pretty straightforward but could be 'cause I > didn't mess w/ this yet :D I guess my one question would be the same > as for the template folder: is that what it takes for pylons to know > that I'm using SQLAlchemy (or whatever you chose to use)? Oh, and > again - there's an object to pass info from models to wherever else, > right? The model contains your "business objects"; i.e., a representation of the real world. If the site is an online pizza-ordering site there would be a Pizza class here. Pizzas contain Toppings, a 1:many relationship. Each item sold has a Price. Each Customer has an Address; each Order has a PromisedDeliveryTime. You need an Accounting system to track the dollars earned in a month. All these map naturally to tables and fields in some ideal database. The model is where you describe these objects and connect them to an actual database. In a typical Pylons application you'd use SQLAlchemy for this, so your model contains SQLAlchemy tables and ORM classes, perhaps with methods like .add_topping(t) and .get_menu(vegetarian=False). > Controller folder -> this is where the "glue" code goes, right? You > use a controller to communicate w/ the user, the view, and model? How > does a controller get called into play? When a user clicks a link? > That's what I'm thinking but I might be off. And what about the view > and the action - what are these exactly? The view is a file in the > template directory maybe? Not really sure what action is. And not > really sure how the whole routes thing factors into this. This is what > I garnered from the tutorials, so far. When the user clicks a link, the browser makes a request to your HTTP server. Pylons uses Routes (myapp/config/routing.py) to decide which method in which controller class to call. Routes uses the term "action" for the name of the method. The controller method checks the request, calls things in the model, sets variables for a template, and invokes the template to return a response. "Action" is Routes terminology for the name of the controller method. So if the URL matches a routing rule whose controller="foo" and action="index", Pylons will instantiate myapp.foo.Foo and call its .index method. A "view" is MVC terminology for a template. The controller is always the active part: it invokes the model and the view. > Templates-> I have to admit I don't fully get why you use templates. > Is it to just make it easier to put variables in and to include > files? anyway, your code to render you page goes here. Curious why > css files don't - is it speed? Also, is just being in the template > file what tells pylons I"m using Mako (or whatever template language > you put in your middleware.py)? Is there a provided object that > allows you to access your templates from outside the templates folder > (maybe there's no call for this?)? I've seen references to available > objects here and there but I haven't found a good explanation yet. > User error, I'm sure, but still. :) You don't have to use templates at all: the controller can calculate an HTML page as a string, or piece it together from include files. But templates provide better organization: they show the logical structure of your output, and keep the user interface (HTML) separate from the logic code (controller). You can give templates to a graphic designer to customize. A template engine is like an include function but much more sophistocated. A template combines changing output (variables) with unchanging output (template text). CSS files are normally unchanging -- everybody gets the same one -- so you put it in the public directory because it's more convenient: you don't have to write a controller or route for it. It's theoretically faster and requires less processing to deliver a static file, though you won't notice the difference unless the site is very heavily used. Note that if you do make a controller and view for your template, the controller will have to create a custom Response object and set the content type to "text/css"; otherwise Pylons will assume "text/html" and the browser will do who knows what. You set the template language in middleware.py, and optionally in the controller's render_response call. I don't understand what you mean by "a provided object that allows you to access your templates from outside the templates folder" or "I've seen references to available objects here and there". If you mean, "Can I access my templates from outside outside Pylons?", the answer is yes, but you'd have to configure the template engine or Buffet manually for this. -- Mike Orr <[EMAIL PROTECTED]> --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "pylons-discuss" group. To post to this group, send email to [email protected] To unsubscribe from this group, send email to [EMAIL PROTECTED] For more options, visit this group at http://groups.google.com/group/pylons-discuss?hl=en -~----------~----~----~----~------~----~------~--~---
