tags:

views:

19

answers:

1

Hi,

I'm trying to implement a simple login box to my web application, just a regular username and password field if no session is detected and a welcome message if there is one, i started with the following:

  1. I thought a simple element will do the job, but i realized than i can't include css or js(not inline) from an element because the $scripts_for_layout would be already sent to the output buffer.

  2. I'm now thinking of implementing it as a component, not sure if this would be the right architecture(is it?) but i can definitely add the js/css and output them in the head tag from there. The question is now where should i place the markup for the login box, an element or view maybe, and how do i inject them to the view? a simple $this->set('x', htmlmarkup) in the component and another echo in the view. What's right way to do it.

Thanks. Yehia

+1  A: 

An element is definitely what you need as it is a front-end element that is reused on several pages.

To get around the issue of not being able to include CSS or JS from an element you could create separate CSS and JS files for the login box and include them in the layout.

ABailiss
that's exactly my problem, i don't want to always include the css/js for the login in every page (that is, in the layout) and when calling an element from the layout it can't dynamically add the js/css files to the header ($scripts_for_layout would have been parsed already). My current workaround is to create a component that's only job is to include the css/js to the $script_for_layouts, and call as usual the element from the layout. Any other thoughts?
Yehia A.Salam