How to add styles dynamically from layout folder of zend application - zend-framework

My all styles are located behind the root under application layout folder. I don't want to keep my styleS in public folder.
How can I read them dynamically in my layout using below commands?
$styleFile = "greenish.css"; // from database
$this->headLink()->appendStylesheet(APPLICATION_PATH . 'modules/frontManagement/layouts/styles/'.$styleFile);
Any Idea?

If you want to avoid inline styling and only use headlink() but deliver content that is tucked safely away outside the web root or in a db, then it sounds like you'll have to headLink() to a dynamic server-side script that accepts the customer identifier and then delivers that customer-specific CSS, complete with mime-type headers.
With clever cache headers and url naming, you might even be able to get this to cache on the browser side, like you'd get with static, totally public CSS resources.
But I'll tell ya, it all sounds like overkill to me. Who cares if all the other styles are 'accessible' as long as you deliver only stylesheet_XXX.css to customer 'XXX'? Still, if it's your requirement, then I think you can manage it with the approach above.

Why wouldn't you want to keep your styles/scripts in the public folder? That's where you're supposed to keep them because, well, because their public resources.
Even if you kept them somewhere else, you'd still have to read it and apply the styles to your page. Which means you can't actually hide it (if that's your intention)

I think you want the HeadStyle view helper which includes the style sheet inline in the document head. The basic usage is something like this:
$styleFile = "greenish.css"; // from database
$style = file_get_contents(APPLICATION_PATH . 'modules/frontManagement/layouts/styles/'.$styleFile);
$this->headStyle()->appendStyle($style);

Related

How to change the website look and feel by changing the design location under page properties

I have a requirement where I have 2 clientlibs having different CSS files for my website. The business author should be capable of switching the website look and feel by just changing the path of the design under page properties. While I am able to achieve that requirement by changing the clientlib categories name referred in my JSP of base template of my site, can the same thing be achieved by the business author without actually performing a code level change? Basically, he should be able to select the design path present under the page properties section, and selecting a different design should change the look and feel of the website. Please let me know how this can be achieved.
Note: I have placed my clientlibs under /etc/design/proj-name/ path
The foundation page component is designed to include css link in the head if a file called static.css is present under the design. It's done through the design object.
If you have different css in the static.css file under different designs then the look and feel will change with the design. However you will be stuck with one file and cannot leverage the utility of client libs.
This adobe doc suggest's doing something like this for css and related images
<%= currentDesign.getPath() + "/static/img/icon.gif %>
Data from design dialogs is stored under the design , swapping designs to change look and feel will cause data inconsistencies too.
Why not add a selection widget to the page and use it's value to selectively include different client lib categories instead of relying on the design.

Zend Framework Bootstrap question

I am new to Zend Framework. I have a master layout file and I want to add and remove css/js files dynamically. I plan on creating an XML file which contains which controller/actions should have which files added. I was thinking of having the constructor for the controller read the xml file and add the files as required but this seems a bit bad practice. I am thinking it may be better to have this done in the bootstrap class file.
Can anyone tell me if this would be the correct way of doing it and how I may go about doing this please?
The correct way would be to let your views decide which styles/scripts they need. There are view helpers available for this very purpose. This way you separate your representation logic (views, scripts, css) from your application logic (controllers/bootstrap) and your data logic (database,...).
Create your own layout plug-in class . Inside its post-dispatch hook code your own logic .
It is a good idea to load static resources only when you need them!
That said, it seems like a contradiction in your question that you're considering loading these view specific resources during bootstrap. That's much too early, your app has no clue yet about what will be needed.
With the tought of economic lazyness in the background, you should add resources in your views:
if (somecondition)
{
$this->headScript()->addJavascriptFile($this->baseUrl() . '/path/to/your file');
}
else
$this->jQuery()->addOnLoad($someShortjQueryScript);
}
If that's too late for your taste, you can do it in the action too:
$this->view->headLink()->appendStyle($someCSS);
Check out the view helpers, you can do all kinds of things, append, prepend, addOnLoad, add files, scripts, styles, etc.
It doesn't seem like a good idea to me to read a list of files from config. But I may be wrong.

What separates a content management system from just a bunch of web pages?

I have a website that has related pages. They have links that point back and forth to one another but I have no integrated system, nor do I know what that would mean.
What is the minimum code that a group of web pages must have to be considered a Content Management System (CMS). Is it that all the settings are in the database and the pages are generated somehow? Is there some small snippet that all my pages could share that makes them a CMS, database or not?
Thanks. I was also hoping not to have to study a giant CMS to see what makes it a CMS . After maybe a basic understanding I would know what I was looking for.
edit: here's why I ask about code. Whenever I have looked at a CMS, and maybe they aren't all the same, I saw that to develop a module you always had to inherit from certain classes and had some necessary code. I didn't know if there was some magic model that I just don't get that all cms makers understand.
edit: perhaps my question is more about being extendable or pluggable. What would a minimum look like? Is it possible to show that here?
edit: how about this? Is something a CMS if it is not extendable and/or pluggable?
I think this is really impossible to say. We all manage content. The "system" is just whatever mechanism you use to do so(dragging and dropping in Explorer or committing content changes via a SQL query). To say there is a minimum amount of code needed really isn't indicative. What is indicative is how often you find yourself making mistakes and how easy it is for a given user of a given skill level and knowledge to execute the functions in the designed system. That tells you the quality/degree of what you have in place being worthy of being called a "CMS."
Simply put a CMS is an application that allows the user to publish and edit existing web content.
In response to the edit:
A "good" CMS allows of extensibility. By using inheritence you can extend the functionality of a CMS outside of the core components provided. That's the magic.
About Extensibility:
Depending on the language/framework you want to build your CMS with, you can load pages or controls(ASP.NET) using command built into the framework. Typically what is being done is a parent class/interface is being defined that forces an module that is to be developed to follow some given standards:
Public MustInherit Class CMSModule
'Here you will define properties and functions that need to be global to all modules being developed to extend your CMS.
public property ModuleName as string
End Class
public class PlugInFooCMSPage
inherits CMSModule
end class
Then it's just a matter of simply loading a module dynamically in whatever construct a given language/framework provides.
Ultimately, a CMS is a system that lets you manage content, so it needs an user interface that is dedicated to letting you easily create, edit and delete pages on your website.
However, it's fairly usual to expect from a CMS to provide a browser-based WYSIWYG page editor, file uploading, image resizing, url rewriting, page categories and tags, user accounts (editor, moderator, administrator), and some kind of templae system.
Without dragging you into a theoretical explanation of what a CMS is and what it's not, perhaps some tutorials on the building methodology of a CMS will help you better understand.
http://css-tricks.com/php-for-beginners-building-your-first-simple-cms/
http://www.intranetjournal.com/php-cms/
A Content Management System is a System that Manages Content. :)
So if you got many pages that share the same layout, you can create a system that stores the content into a database and when a page is requested, it gets that content, merges it with a template that contains the page header, menu, etc.. and outputs the result.
The basis idea is that you don't want to copy HTML pages, and have to edit hundreds of them when you want to change your layout.
Such a system can be very complex, featuring wysiwyg editors, toolbars, version control, multiple user publishing and much more, but it could be as simple as a single page behind a standard loging, that contains only an input field for the title and a textarea in which you type the html content.

How to cache layout content in Zend Framework

How would you implement caching of the layout content in Zend Framework?
In the layout.phtml I do: $this->layout->content and I want the content of this variable to be cached. The other widgets from the layout are real time (or cached other way).
The best bets are:
static cache (the fastest)
page cache
My pages already have unique page id (canonical), so it could be used as page cache tag.
Potentially looks like I have to overload __get property of the layout.
I'm trying to do something like the layout of SO (user panel at the top, rest cached for all).
I assume, site should work without JavaScript.
You might want to have a look at the Front Controller Cache plugin weierophinney describes. The problem probably is that you don't want the script to stop on cache hit. So you don't exit; the the script, you could work with $request->setDispatched(true) within the plugin. (You'd need a new request-object for every different cacheable).
Another approach could be that you don't use the dispatchLoopStartup but the preDispatch in your plugin and reset the dispatching there.
They way to go actually depends on how you load all the other stuff (be it cached or not). (E.g. the ActionStack pushes a new request to the dispatcher).

How to create custom pages in dasBlog?

I know I've seen this in the past, but I can't seem to find it now.
Basically I want to create a page that I can host on a dasBlog instance that contains the layout from my theme, but the content of the page I control.
Ideally the content is a user control or ASPX that I write. Anybody know how I can accomplish this?
The easist way to do this is to "hijack" the FormatPage functionality.
First add the following to your web.config in the newtelligence.DasBlog.UrlMapper section:
<add matchExpression="(?<basedir>.*?)/Static\.aspx\?=(?<value>.+)" mapTo="{basedir}/FormatPage.aspx?path=content/static/{value}.format.html" />
Now you can create a directory in your content directory called static. From there, you can create html files and the file name will map to the url like this:
http://BASEURL/Static.aspx?=FILENAME
will map to a file called:
/content/static/FILENAME.format.html
You can place anything in that file that you would normally place in itemTemplate.blogtemplate, except it obviously won't have any post data. But you can essentially use this to put other macros, and still have it use the hometemplate.blogtemplate to keep the rest of your theme wrapped around the page.
I did something similar setting up a handler to stream video files from the blog on my home server. I ended up ditching it because it killed my bandwidth whenever someone would view a video, but I did have it up and working for a while.
To get it to work I had to check dasBlog out from source control and open it in visual studio. I had VS2008 and it was built using VS2005, so it took some work to get everything to build. Once I could get the unaltered solution to build I added a new class library project to hold my code. This is to make sure my code stays separate across dasBlog updates.
I don't have access to the code here at work so I can't tell you exact names right now, but if you want your pages to be able to use the themes then they need to inherit from a class in the newtelligence.dasBlog.Web namespace, and I believe also implement an interface. A good place to look is in FormatPage and FormatControl.