2 Attachment(s)
views looking messy, is there a better way?
Couple of questions:
1)
Which direction do you choose?
output buffering or concat $page var (all views return a string)?
I choose the concat method, however, it's hard on the eyes: I didn't notice until i worked with a non programmer. [designer]
PHP Code:
$this->html.='<p class="more">'.
'<a href="/rss" title="Click here to see an XML representation of the content of this weblog."><img src="'.EnumArticleConstants::$path.'themes/'.$this->theme.'/img/xml-summaries.gif" alt="Click here to see an XML representation of the content of this weblog." /></a> '.
'</p>';
I took a look at smarty template engine, however i never implemented it as I felt the learning curve for the designer would be as much as picking up basic semantics for php. (also php has incredible documentation and is easy to learn)
so I tried to recreate the crash course in php.. I'll like to get feedback on this if possible ...its attached. [i'll like to take a look at some advanced smarty template files to c if i can recreate them using what i've created]
I used a registry to register my transfer object in case the data access and view were not sequential. meaning data access was called a lot earlier than the view. This has a negative effect in that i can't reuse templates since the view asks the registery for a specific transfer object. [example 1]
are data access and view ever that seperated?
Example 2 shows a template the doesn't explicitely request the transfer object.. but expects for the object to exist in the same scope. [require instead of require_once]
2
How many use the method described on page 282 of harry's volume 2 book? Does anyone know what this method is called? dao? ..as it does create a transfer object.
Is that what the example attempts? (without the business object)? http://java.sun.com/blueprints/corej...essObject.html
3
i plan to refactor a lot of my views this summer as i feel the views have become bloated. Take a look at my biggest view. How can i redesign using view helpers?
- one of my ideas in refactoring is to implement view helpers as described in core j2ee patterns by alur..
anyone with any advice?
4
lastly does anyone use composite controllers?
are composite controllers the same as chain of responsiblity
my thoughts are to have all my applications have a controller.. and in the __constructors add specific controllers for that domain.
CalendarController, AuthenticationController, ArticleController
anyone with any advice?
1 Attachment(s)
this might be helpful in answering some of my questions
attached is the screen shot of the view [note i cut some of the article]
in previous applications all files have standard place to be included. Either constants.php or the application specific constants.php
I always felt more control instead of including files randomly in the view .. what do ya feel about includes randomly spread throughout the app?
phpsmarty design
the user can map data to values he wants... uses __get intercept
uses final on construct so user cannot overload and affect the logic.
user must implement the routine in map.
>Dr Livingston
i'll do my searching this week.. i've already found some gems about composites/composite views. I guess i'll concentrate on CoR since composites +visitors are becomming more and more familiar ground.
thanks.
can composite view and composite controller live together
here are the examples taken from the forums:
Example of composite view
http://www.sitepoint.com/forums/showthread.php?t=352752
by kyberfabrikken
PHP Code:
$page = new PageBuilder();
$page->attach( new View("header.tpl.phtml") );
$page->attach( new View("login.tpl.phtml") );
$page->attach( new View("menu.tpl.phtml") );
//main content start
$content = new CompositeView("content.tpl.phtml"); //<div> and closing </div>
$content->attach( new View("musicSearch.tpl.phtml") );
$content->attach( new View("music.tpl.phtml",$music) );
$page->attach($content);
//main content end
$page->attach( new View("footer.tpl.phtml") );
$page->render();
In this composite view, all views now need logic inside to decide how exactly the view should be represented. Example login.tpl.phtml: when a user has logged in; the view should change to show the user name instead of the login form.
also example needs: $page->render( $RequestObject ); //so views base there logic off the request object
All views now are required to pull data.. unless this example shows static templates not needing data. Looks like $music can be dynamic data passed to the view.. but i'm not sure.
This is a good strategy if you've already seperated out your views in the application.
forums/ - has a defined view
forums/showthread.php - has a defined view
www.sitepoint.com/ - defined view
http://www.sitepoint.com/blogs/ - defined view
PHP Code:
$ViewBuilder = CompositeViewFactory::getInstance($RequestObject); //returns the full composite tree for a defined view
$ViewBuilder->render(); //each component in the tree will have to fetch its own data
Since in my application have defined views i might take this track.
composite controller
by Dr Livingston http://www.sitepoint.com/forums/show...3&postcount=14
PHP Code:
// each composite - handler - is a controller
$page = new PageHandler();
$page -> attach( $body = new BodyHandler() );
$body -> attach( new BlogHandler() /* module */ );
$body -> attach( new ArticleHandler() /* module */ );
/* add other modules */
$page -> attach( new MenuHandler() );
$page -> attach( new FooterHandler() );
$response = new Response();
$response -> render( $page );
Although composite view looks like a winner since my views are distinctly defined....
I also have applications/components properly defined.
I have a calendar, gallery, and article system
they're small applications(admin sections and all), therefore wouldn't it make sense to designate a controller for each?
and why is it not: echo $page->render($response) //so all elements in the tree see the response.
So is this how you generate a view with composite controller?
PHP Code:
function render($response) {
$subview='<div>';
foreach($this->components as $child) {
$subview.=$child->render($response);
}
$subview.='</div>';
return $subview;
}
is there any application that takes advantage of both the composite view and the composite controller? I feel that they approach page generation with different strategies that collide with one another if implemented together on 1 site.