Zend Framework Bootstrap question - zend-framework

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.

Related

Ionic having multiple files for services and controllers

Usually by default in Ionic Framework there is a single file that all services are stored and a single file that all controllers are stored.
But this on big projects may turn out with hard to maintain and develop code.Is there a way to split the code of controllers and services into smaller easily maintainable files?
I already have this project: https://github.com/pc-magas/faster And I want from the start to set it Into a Mentainable form.
Along with suggestions from above user, you can even bundle all your JS using gulp task and include that single file in index.html. This will ensure you don't miss out any file inclusion in index.html.
Take a look at Angular Best Practices
Yes, there is. I would recommend that you take a look at the angular-seed project. In their code, they have separated their services and controllers into separate files.
Basically, what you have to do is separate the files and then include them in your app.js, like this:
angular.module('myApp', [
'myApp.controller1',
'myApp.controller2'
])
And then above your controller, you have to put something like the following:
angular.module('myApp.controller1', [])
.controller('Controller1Ctrl', [function() {
}]);
Lastly, you need to include the controller, service or directive in your index.html, like this:
<script src="folder/controller1.js"></script>
It is up to you to decide how you want to structure your files. Here is an article, in which the author outlines some ways to structure AngularJS projects.

Add New Pages to CMS in Rails

I'm more-so looking for a best practice. I'm working in a team on a rather large project. I'm doing the server side coding and someone else is doing the designing. We decided to do an in-house style CMS so someone else can make some changes to content, without changing the styling.
We need to add some new pages in to make more functionality to the site, but I'm looking for a best practice for doing this. Originally I thought about using the db:seed command, but that's more-so for loading initial data, rather than a new page. Now, I'm starting to think about using a migration file, but I think it's kind of bad practice to edit a migration file back and forth for changes to a CMS page.
Any thoughts for a best practice for editing static pages through a DB record between team members?
For something like this, I usually create some classes in /lib to handle creating the necessary data if it doesn't exist. You can make sure the process is idempotent by doing something like this:
page = Page.find_or_create_by_name("blahdeblah")
where "name" is some unique identifier for a page.
Example:
class CreateSamplePages
def execute
page = Page.find_or_create_by_name("blahdeblah", content: "This is an entirely awesome sample page.")
... (more stuff here)
end
end
Then in the rails console (rails c in your project root), you can do CreateSamplePages.new.execute

How to extend Alfresco Share existing activity list dashlet with my own activity type?

In Community 4.0.a, I'm posting my custom activities in the repo following this: http://wiki.alfresco.com/wiki/3.0_Activities_Developer_Guide
I have defined my own activity type, with custom bundles and pagelink to display custom needs in the activity dashlet.
But I face an issue, I need to specialize the output based on the activity-type in a similar way of what is done already in activity-list.get.js in the specialize() function.
I can't hack the js cause I'm packaging things in my own amp for Share.
What is the best way to do it? Is there some kind of extension point or do I need to override completely the dashlet?
The old way (3.x) to change the behaviour of a webscript controller is to copy the code and overwrite the Javascript by placing it under web-extension: alfresco/web-extension/site-webscripts/org/alfresco/components/dashlets/activity-list.get.js. There you can modify the specialize() function or whatever you need to do.
All files you place in the alfresco/web-extension/site-webscripts folder will replace original files in the share.war WEB-INF/classes/alfresco/site-webscripts classpath. Best practice is to place your customizations in the tomcat/shared/classes/alfresco/web-extension folder so you don't need to modify the WAR file.
Alfresco 4.0 provides a new way to change the javascript controllers of a webscript. You can add additional Javascript code that will run after the original code. This is preferable because you don't need to change original code and you can upgrade more easily later. To use it you need to get familiar with the new Share extension modules concept. See David Draper's Blog for more info on that.

Spring 3 MVC : Cleanest way to retrieve dynamic information in the header and footer if they are includes

I am looking for the cleanest way to retrieve and display information in my headers and footers. They are .jspf includes inside my .jsp files.
I know I could just boilerplate copy and paste ModelMap.addAttribute in every one of my controllers but that sounds like a terrible solution. I also do not want to use a session attribute if I can help it.
I was thinking that I could create a "Master Controller" class that all my other controller classes could extend from but, I am very interested in doing it the correct and most efficient way.
Implement the HandlerInterceptor interface. In the postHandle method, add the boilerplate to the ModelMap. It will be there on every Handler call, automatically.

How to add styles dynamically from layout folder of zend application

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);