Skip Navigation
Falvey Library
Advanced
You are exploring: Home > Blogs

VuFind, Zend Framework 2, and Flash Messages

One minor weakness of VuFind 1.x is that it doesn’t always provide good feedback for user actions.  One of the advantages to switching to a standard framework is that we can leverage an existing “flash message” mechanism to display messages to users in a consistent way.  Zend Framework 2 includes a simple FlashMessenger helper, but it took a bit of learning to use it as effectively as possible.  I hope that a discussion of my solution to this problem will helpfully demonstrate some aspects of the framework and VuFind 2.x’s architecture.

The Problem

In Zend Framework, flash messages are stored in an object by the controller.  For example:

$this->flashMessenger()->setNamespace('info')
    ->addMessage('Email sent successfully.');

or

$this->flashMessenger()->setNamespace('error')
    ->addMessage('Operation failed.');

 

The view is then responsible for pulling information out of the object and formatting it for display.

I wanted VuFind to display messages in a consistent way, so it seemed to make the most sense to use a View Helper to render flash messages.  This helper could take care of pulling messages from the namespaces in the object, applying translation, and building <div> tags with appropriate classes. This way, all I would have to do is add this code to a template:

<?=$this->flashMessages()?>

 

and my flash messages would display.

There’s just one hard part: getting the object containing the messages from the controller to the view with a minimum of fuss.

Solution #1: Brute Force

My first solution was not hard to come up with, but I was never happy with it.

Controllers in Zend Framework 2 pass values to their corresponding views by returning a value (often a ZendViewModelViewModel object).  If we want to ensure that all of these objects contain a particular value, we can establish a convention where VuFind’s controllers never construct a ViewModel directly; instead, they always call a $this->createViewModel() method defined in an abstract base class.  This helper method is responsible for constructing a ViewModel and then attaching the flash messenger object to it.  Once the ViewModel has a flash messenger attached, the View Helper responsible for rendering the messages can simply pull the messenger from a known named property in the model.

Advantage: It works.

Disadvantage: It’s ugly.  It relies on a particular arbitrary value being in a particular arbitrary place.  It takes away some of the flexibility of the framework by forcing the user to always return ViewModels, and to construct them in a particular way.  It makes the user jump through a hoop (calling createViewModel to create a view model) and punishes them in an unintuitive way if they don’t comply (flash messages stop appearing).

Solution #2: Working with the Framework

Fortunately, there is a better way.

One of the nice features of ZF2 is its service manager system (described in more detail in this blog post).  Service managers are responsible for constructing and storing instances of important objects used by the application.  Ugly application-specific details can be pushed into service manager configuration so that the actual components of the application can be simpler and more reusable.

The flash messenger controller helper and our custom view helper are both constructed by service managers.  This means that, through proper service manager configuration, we can ensure that the flash messages view helper always has access to the flash messenger controller helper, with no need for the intervention of a nasty createViewModel() method.

This is achieved with the help of a factory in our view helper service manager configuration:

'flashmessages' => function ($sm) {
    $messenger = $sm->getServiceLocator()
        ->get('ControllerPluginManager')
        ->get('FlashMessenger');
    return new VuFindViewHelperRootFlashmessages(
        $messenger
    );
},

 

Here’s how it works: service manager factories are passed an instance of the service manager that is doing the object construction ($sm in the example above — an instance of the service manager devoted to view helpers). $sm->getServiceLocator() retrieves the service manager that constructed $sm — the top-level service manager that manages the whole VuFind application. From here, we can call ->get(‘ControllerPluginManager’) to obtain the service manager for controller plugins. We can then call ->get(‘FlashMessenger’) on the controller plugin service manager to get hold of the flash messenger. This object ($messenger) is then passed to the constructor of the new VuFindViewHelperRootFlashmessages helper. The object now has access to the flash messenger as soon as it is constructed. None of the other code needs to know about the details — it just works like magic.

Yes, this is a bit ugly. But the important thing is that the ugliness is now in the configuration of the application — part of the glue that holds everything together. It’s okay for this part of the code to be a bit convoluted and application-specific, because its whole purpose is to make the various parts of the application fit together. The beautiful thing is that those component parts don’t have to know anything about the details of how the glue works — as a whole, the application has become less coupled and more flexible. Compare this to solution #1, where the ugliness was more deeply embedded in the application’s controllers and in the behavior of the view helper itself.

The Code

If you want to see how VuFind transitioned from Solution #1 to Solution #2, take a look at these diffs.

The Bottom Line

There’s definitely a learning curve involved with ZF2, but I continue to feel that it is worth the effort.  I hope this example has shed a little light on some of the issues… but if anything is unclear (and I’m sure something is), feel free to ask questions.  I’m always happy to help, especially if it means that more people are potentially able to help with the process of improving the code.


Like

Need Help? Defining and Locating Church Documents

 

By Darren G. Poley

What is usually meant by church documents?

Church documents are published statements, primarily on matters of faith and morals, which are publicly promulgated by some part of the official hierarchy of the Catholic Church. The hierarchy is the body of church leaders, called bishops, who are in communion with the Bishop of Rome. The hierarchy is headed by the visible head of the Catholic Church: the bishop of Rome, who is the supreme pontiff or simply the pope. A good starting point for research is ATLA Catholic Periodical and Literature Index. You can enter a keyword in the advanced search and under Publication Type, select either “Church Document” or “Papal Document.”

What are papal documents?

In addition to being the spiritual leader for over a billion Catholics worldwide, the pope is also the head of state for the Vatican City and chief officer of the Holy See, another name for the Catholic Church’s government commonly called The Vatican. The Vatican functions as the administration for the Catholic Church, a diplomatic entity as well as a religious organization. The documents signed by a pope are called papal documents. The official Vatican Web Site is an excellent place to look for papal documents from popes of the twentieth-century.

The most famous kind of papal document produced today is the encyclical, a public “letter” to his fellow bishops that is meant to be circulated and read by all. Encyclicals are theological in nature but are by no means the only source of Catholic doctrine. Search in Falvey’s catalog using “Catholic Church Doctrines Papal documents” as a subject. See also compilations of church doctrine such as the multi-volume Précis of official Catholic teaching or the one volume Catechism of the Catholic Church in English online and in print. (more…)


Like

Window Shopping: One Book Villanova Little Princes Featured in First Floor Exhibit

By Alice Bampton

Little Princes by Conor Grennan is the 2012-13 One Book Villanova selection. Joanne Quinn, Falvey’s design specialist, created an exhibit highlighting Little Princes: One Man’s Promise to Bring Home the Lost Children of Nepal. The display also reflects the history of the One Book Villanova program, which began in the 2005-2006 academic year after a conversation between Joe Lucia, University librarian, and Terry Nance, PhD, professor of communication and assistant vice president for Multicultural Affairs.

Grennan will be signing books in the Speakers’ Corner, first floor, Falvey, on Tuesday, Jan. 29 at 1:30 p.m.

Bright blue informative posters, in the center, feature “The Story,” “The Author” and “Schedule of Events.” Photographs of Grennan, Grennan with Nepalese children and a map of Nepal complete the centerpiece. Framing the “Little Princes” materials and One Book Villanova posters are images documenting each of the eight previous One Book Villanova selections. Colorful Tibetan prayer flags form a backdrop.


Like

London Critical Theory Summer School 2013

  • Posted by: Gabriel Rockhill
  • Posted Date: January 18, 2013
  • Filed Under: Library News

The 2013 London Critical Theory Summer School will take place at Birkbeck from 1st July – 12th July 2013. This unique opportunity is for graduate students and academics to follow a course of study and to foster exchange and debate. It will consist of at least 6 modules over the two weeks, each convened by one of the participating academics.

http://www.bbk.ac.uk/bih/lcts


Like

*NEW* Encyclopedia of Ancient History

The long awaited Encyclopedia of Ancient History is now available after repeated publication delays. Unparalleled in scope with over 5,000 original, peer-reviewed articles, the Encyclopedia covers subjects ranging from the ancient Near East to Pharaonic Egypt, the Roman Republic, and Late Antiquity. Five general editors, twenty-three area editors, and a total of 1,827 scholars collaborated on this project. Villanova University’s own Christopher Haas, PhD, contributed articles on Axum and Hypatia. Although available in thirteen print volumes, the Encyclopedia was conceived and planned as a digital reference work. Its content will be continually updated, and new articles will be added over time. Readers are encouraged to contact the editorial board with corrections and suggestions for additional entries.

Searching and browsing the contents of the Encyclopedia seems unnecessarily complicated. A first-time user will be tempted to simply use the search box on the start page, which will retrieve keyword matches from all Wiley-Blackwell titles. Only upon closer inspection will the reader notice the “Search in this Book” link beneath the search box. The “Find Articles” options on the left menu are barely noticeable as well. Articles are organized in twenty-two topical categories to facilitate browsing. The scope of the Encyclopedia makes it easy to compare topics between various ancient civilizations. A good example is the seven different entries on calendars.

Articles vary in length but rarely exceed ten pages. PDF files of articles are available for downloading. Each article lists references and suggested readings. A good number of references are written in foreign languages, but available English language translations are included as well. A “How to Cite” link generates a basic citation for each article. Alternatively, citations can be exported to RefWorks or EndNote. Overall, this is an excellent new reference title and a good starting point for undergraduate and graduate students alike.

You may also be interested in the following new e-reference works from the Blackwell Companions to the Ancient World Series:
A Companion to Women in the Ancient World
A Companion to the Archaeology of the Ancient Near East
A Companion to Tacitus

Questions or comments? Contact me directly (jutta.seibert@villanova.edu) or post your comments online.


Like

Quick Tip: How to Print in Falvey

There are two self-service print stations in the Library: one on the first floor for all first floor computers and one on the third floor for computers on the 3rd and 4th floors. Villanova University students, staff and faculty can use library public workstations to print from any Internet, email or desktop application. Alternatively, items can be sent to iPrint, the University online printing service, to be picked up at Bartley Print Services.

For self-serve printing:

Choose single- or double-sided, and make sure to note which printer you are sending to (first or third floor). At the print workstation, identify and click on your print job by your username or document name. Click the Print button on the bottom left hand corner. Swipe your Villanova University Wildcard with the magnetic stripe facing to the bottom right. Remember to slide your card all the way through and make sure the card is placed firmly in the reader. This will deduct money from your VPrint account.

For personal laptop printing:

This one-time procedure allows Villanova University students, staff, and faculty to send work to the library printers from their personal (non-Apple) laptops.

  • On your laptop, press and hold the Windows key and the letter R.
  • In the “Run” window that appears, type goprint and press the Enter button.
  • You will then be prompted for your (Villanova email) username and password.
  • Username: type VUADusername
  • Password: type your password
  • Double-click the printer you wish to access (Falvey printers have the prefix FML).

The rest is automatic. The printer has now been added to your computer’s “Devices and Printers” and will be available each time you print from your laptop.

For Graphic Services printing:

Go to the iPrint website and log in with your University username and password. Upload the document to print.  Be sure to choose Bartley as the pickup location.  Choose printing options and quantity, and approve the proof and payment information. Click “Place Order.” You will then get a receipt of your printing job.  Items can be picked up from the Bartley Print Center.

You do not need to be in the library to send items to iPrint!  You can print files from any computer and pick them up in Bartley.

Find other library Quick Tips by clicking here.

Questions? Suggestions? Let us know in the Comments below. Or give us a call at the Information Desk at 610-519-4270.

Also contributing: Gerald Dierkes, Luisa Cywinski, Judy Olsen


Like
1 People Like This Post

Give Your Students the Edge They Need: Book an Instruction Session

Course instructors, are you satisfied with the quality of the sources your students use for term papers and other research assignments? Tired of seeing references to Wikipedia?

Falvey librarians can teach your students how to access and navigate the authoritative, information-rich resources available through the library website. Full text-journal articles, national and international newspapers (current and historical), statistical reports, handbooks and raw data sets: all these resources are literally at students’ fingertips.

Unfortunately, many of our computer-savvy students, unaware that the library home page is their gateway to these high quality sources, never find these valuable tools.

Broaden your students’ research horizons by scheduling a library instruction session for your students with a subject specialist librarian. If you do not know the name of your liaison librarian, check the contact list by department, or contact Barbara Quintiliano, instructional design librarian. Sessions can be scheduled during a regular class period or at another convenient time.

You and your students are welcome to come to the Griffin Room on the library first floor for hands-on instruction, or librarians can do a demo in your classroom. Librarians are also available to prepare online course and topic guides, as well as handouts to assist your students.

Give your students the edge they need. Contact your liaison librarian today!

Above: Rob LeBlanc teaches students some strategies for fruitful searching.


Like

eBook Available: History of the Catholic Church in Paterson, N.J.

Title page of History of the Catholic Church in Paterson, N.J. (1883)When we first blogged about the Digital Library’s involvement with the Distributed Proofreaders project in March of last year, our first project was History of the Catholic Church in Paterson, N.J. A few months later, the project has been completed, and the book is now available on this page to read online or download onto the electronic reading device of your choice.

As the title implies, this is a history of a particular church in Paterson, N.J. from its construction up to the book’s publication in 1883.  The church’s predecessors are also discussed, as is the early history of Catholicism in the region.  The book includes brief biographies of several prominent Paterson Catholics, making it of possible interest to genealogists.

More proofreading projects will be completing soon, so watch this blog for further announcements.


Like

New & Improved Searching in VuFind, the library catalog

By Demian Katz

VuFind, the library catalog, was recently tested and upgraded for the new semester. The most noticeable improvement is a more detailed set of values in the Collection facet of the search results. You can now do things like limit your results to Special Collections, main stacks, etc. Other changes are minor bug fixes and behind-the-scenes adjustments that are unlikely to significantly affect day-to-day use. The section below will take you through the changes.

Catalog Search Tip: Filtering By Collection

The library catalog, searchable through the “Books & more” option on the Search tab of the library home page, contains a mix of useful materials. Most are physical books and journals owned by the Library, but some are links to online materials such as free government documents. It is usually helpful to have a large variety of options available in the catalog, but sometimes things can get in the way. This week’s upgrade to the catalog system adds a new option that should help you find exactly the items that you need.

Suppose, for example, that you want to check out a recent book about Medicare. You can do a Books & more search for Medicare, and you will see results like this:

 

 

 

 

 

 

 

 

 

 

The top three results show up as books, but they are actually online articles, and none of them are especially recent.

You can sort by “date descending” to bring newer items to the top:

 

 

 

 

 

 

 

 

 

 

This is better, as the first result is now a recent book. However, there are still a lot of online documents cluttering up the results. That is where the new feature comes in. If you look to the right side of the screen, you will see a Collection filter:

 

 

 

 

 

 

This allows you to limit your search results to a particular area of the collection. Since you don’t want Internet items, you can click on “Main Stacks” to limit to items in our main physical collection. Now you get these search results:

 

 

 

 

 

 

 

 

 

 

The top three results are all books from 2012 that you can access in the Library.

Of course, these books may not cover the aspect of Medicare that interests you.  That’s okay!  Because you filtered out the unwanted Internet resources, the other filters in the “Refine search” box should now show more relevant options, making it possible to further refine your search until you find exactly what you need.

Let us know what you think about these new enhancements in the Comments section below.

Demian Katz , a library technology development specialist at Falvey, is a major contributor to the enhancement of VuFind.

 


Like

Business Books Go Mobile

Ever wish you had mobile access to the quality business books your professors expect you to  use?  There’s an app for that (and I’m not thinking SparkNotes, besides it only covers literature!).  Ebrary, one of Falvey Memorial Library’s  ebook platforms, released a mobile app for iPhone/iPad/iPod and Android.  To get it, search the App Store for ebrary and install.  Because the copyrighted book content is only available to subscribers, to use the app you will need to take additional steps including getting an Adobe account and a personal ebrary account.  With these ebrary mobile app sign instructions, you will be on your way in no time.   http://tinyurl.com/a6rwkd7    The app lets you search online, read and download.

 

 

 


Like

« Previous PageNext Page »

 


Last Modified: January 11, 2013

Ask Us: Live Chat
Back to Top