Jump to content

Page Display Logic Problems


xeross

Recommended Posts

I've been writing a CMS for a while now, and so far most of the time it fit the requirements (Tough lacking in some) however as time passes limitations have appeared, and as in my opinion one should make the code do what he wants and not do what the code dictates I have decided it needs a major/minor rewrite.

 

Okay, so onto the problem, currently these 2 limitations have risen to the surface.

[*]Outputting only the code in the designated template when a switch is activated

[*]Specifying a title to be set in the application logic

 

This can not be realized at the moment due to how the display logic is handled, here follows the general path any request follows:

[*]Request arrives

[*]The request gets parsed to get the data from it needed to initiate the application

[*]Initialization code gets handled including connecting to the database and instantiating various classes

[*]The header.tpl gets parsed into the buffer (Output buffering is enabled)

[*]The main application logic gets called and the template that belongs to this application logic gets parsed into the buffer by the view class

[*]After the main logic finished footer.tpl gets parsed into the buffer and then the buffer is sent to the user

[*]Application cleans up and shuts down

Now the bold step is one of the problems, as this means the main application logic can't set anything that's done in the header.tpl.

You could say why not just wait with the header, well the header, footer, and really any template can have a call to another section of business logic (They call the dispatcher that basically gets called in step 1) including for example the navigation.

 

Now the only thing I can think of at the moment is check if we're currently outputting the main application template through some kind of variable (And we'd have to somehow detect when we're launching the dispatcher from within the main template) and after that parse the header template and whatnot. However I don't have the slightest clue of how to handle this.

 

Now another thing that could be done is a big rewrite of how it all works, however when I wrote this code this was the best way I could seem to write it, so if you have any philosophies or methods on how to handle this (While still keeping in line with the MVC pattern) I'd like to hear about it.

 

Oh yes and finally, there's the issue of getting the title changes through when using ajax, but that's a different problem altogether which can be tackled after this problem.

 

So if anyone that has read this post knows a way to solve my problems please leave a reply your input is greatly appreciated.

 

Thank you for your time and attention, Xeross

If anything is unclear after reading this post don't hesitate to ask for clarification, you can only help me to the fullest extend if you understand the problem ;)

Link to comment
Share on other sites

Use a template instead of header.tpl and footer.tpl and fill in the required area's. If you use Smarty it's possible to use functions that will call template data (eg menu)

Well I'm using the .tpl extension but I'm not using smarty, just FYI.

 

Also with use a template do you mean I should use a single master template, and put the logic result into a variable ?

 

Also what if I would ever for some odd reason need to call 2 different controllers for 1 "page" how would I handle that (Has happened before).

Link to comment
Share on other sites

Yes, I meant one master template file.

 

Also what if I would ever for some odd reason need to call 2 different controllers for 1 "page" how would I handle that (Has happened before).

 

I don't see the problem. You can call 400 billion controllers in one request if you like. It all depends on your logic. You could for example set it to use x as a default template and controller y could tell rendering should occur in template z. It all doesn't matter as it happens after all business logic has occured.

Link to comment
Share on other sites

Hmm, well the way it used to work was that the first $this->_view->display("template_name.tpl"); call would be processed and loaded into a variable and output in the content area of the master template.

 

The way you are saying it would be that the controller or something would set what template it should use and once the controller finishes the template gets parsed with any data the controller stored.

 

Now my view logic is obviously skewed but if I want to call 2 controllers I'd have to make  a controller function to somehow load in the controllers and execute their members ?

Link to comment
Share on other sites

I build this my own, so in some occasions something is worked out the wrong way like in this case the view class.

 

If I got this right I should call controllers to get data and pass it to the view and then finally make that parse it once it got all the data (Navigation, page, etc.), just need to figure out a way to queue the controllers then, hmm.

Link to comment
Share on other sites

If I got this right I should call controllers to get data and pass it to the view and then finally make that parse it once it got all the data (Navigation, page, etc.), just need to figure out a way to queue the controllers then, hmm.

 

Wrong, you don't call Controllers for data but your Models. Your Controller only ties together your Model & View

Link to comment
Share on other sites

Controllers request data from the models, and handle this data accordingly (Possibly saving it for use in the view). Execute multiple controllers for navigation and whatnot and then make the template render everything.

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.