My site's structure....need help

Hello, the basic gist of my site is that I have several different Programs, each of which contains several Modules. There has to be a tree-like structure, i.e.

  • The home page contains a list of the Programs

  • When you click a Program, you see the Modules that Program contains

  • You can then click on a Module and view entries for that Module

So for example, index.php/Stories/7?pid=208 would refer to the Story module’s 7th entry, which belongs to Program 208 (the breadcrumbs looks like Home » Program 208 » Stories » View Story. However, I know using $_GET to determine the correct page and for access rules is not the proper MVC way to do things, so I was just looking for any tips to improve the structure of my site. I need the entries in Stories, for example, to depend on the current Program ID. However, I don’t know how to represent this in the address bar any other way. In other words, how else could I pass the PID besides sending it as a variable? Any help is appreciated. Thanks.

But do you really have to put everything (i.e. program, module and entries) into url (route)?

Maybe I’m missing something, but wouldn’t it be easier for you to create three controllers (or one controller with three actions) like for example:

index.php/main/showprogram?pid=2

index.php/main/showmodule?pid=20

index.php/main/showentry?pid=208

You don’t need every information in URL. For example you don’t need ID of both program and module when looking for an entry. Entry’s ID is all you need and if you build your models (for programs, modules and entries) relations correctly, you will be able to get other required information (here - other IDs) directly from model.

Since, as you wrote, entry must belong to some module and each module must belong to some program, simply use BELONGS_TO and/or HAS_MANY relations, when building your relational model concept.

The same goes level up. You only need module ID. You can determine both ID of the program, current module belongs to as good as all entries is has. You can get it (as good as any other information - for example for building breadcrumbs) right from relational model concept. Just look into blog demo in documentation. When you are displaying a comment, you only need that comment ID in url (route). You don’t need ID of a post, this comment belongs to, because you can read it right from a model.

Thank you for the reply, it made me think about my issue again and gave me a new perspective. However, the only thing that bothers me about not including all that info in the url is that for users, it might be more informative when they see that long url. I do use the appropriate breadcrumbs, though, so I don’t know if it matters. I just know from my web developer perspective, it annoys me that the url is so uninformative. I will definitely continue considering all the options though.

And I’m looking at this problem form strictly opposite point of view - the more information you gave to a user the higher chances you get, he’ll try to mess around by changing something in URL! :] That’s why I find Yii with it’s urlManager and other url masking features very useful. There are also other pros, like. shorther URLs are easier to copy from one source (i.e. e-mail) to another (does not break into two lines) and are easier to type, when you can’t paste it (for example in mobile device) etc. But that is my personal point of view.

Good points, thanks a lot. So just to confirm one thing: it’s okay to use a GET variable to determine the program that the current module belongs to? In other words, there are several modules, but one module can belong to one, several, or all programs. It’s the entries in the module that are dependent on the program. I can’t think of how else to do it, but I could have sworn I read some topic about how it breaks MVC or something. Thanks.

Yes, I think it is OK. The question is, is it worth doing so? Aren’t you producing yourself more job than you already have?

If module X belongs to program Y and you go my way, you are only calling main/getModule?id=X and you are determining Y from model relations. If you go your way, if I understand you correctly, you want pass both module and program id in URL. Therefore something like this: main/getModule?id=X&programId=Y. But what, when user manipulate your URL and send you module ID correctly but with incorrect program ID (to which this module does not belongs)?

Not only you are concern about if MVC allows this, but you also force yourself for writing additional checkout methods to determine such manipulated situations.

The golden rule (maybe my private one! :]) says: send as little information as possible through URL and try to determine yourself (from code, db, relations) as much as you can. This way you are avoiding writing unnecessary checkings for malformed URLs and also secure your site from possible attacks.

You know… No one will prevent you from writing sites that are accessible through URL like index.php?open=another.php. And there still are many developers that do so, even if most people know that it is cracker’s kindergarten to break site like this! :]