Today it was announced that Zend Framework is being rebranded as Laminas project. (drawn from the meaning “a thin layer”) Along with the rebrand comes some other important changes as well. Yes, this includes Expressive and Apigility, so continue reading.
Zend Framework is one of the largest and oldest PHP frameworks and has become a staple for enterprise development around the world. As of April 2019, it has over 400 million lifetime downloads of all packages associated with the project, which has seen a 4-fold increase in just the last 2 years alone. Despite this amazing track record, up to now the project has been supported and guided single-handedly by Zend Technologies, and later Rogue Wave Software.
Therefore, to continue this growth and receive the best support possible, the Zend Framework team is announcing that all projects under that umbrella will rebrand to a newly formed “Laminas” project“, which aims to continue their mission as an open source project hosted by the Linux Foundation. The transition will enable more companies to provide support for the projects they’ve come to depend on and help it continue to grow. As part of this transition, it is important for them to differentiate the open source project from the Zend commercial brand. Therefore, the new name “Laminas” project was created.
While tweaking the SunshinePHP site to be a bit more SEO friendly I realized we had neglected to create a sitemap for search engines to find. I was pleasantly surprised to see the Navigation component of Zend Framework 2 includes a bunch of view helpers, including a Sitemap helper. So now I have an xml sitemap created by Zend Framework 2 that works hand in hand with the site navigation. However, the documentation was not complete as of this writing and caused me to do a bit of trial and error debugging to get it working. Below I will post how I got it working, in hopes it will help others. (If the ZF2 folks like this post I will go in an update the documentation later.) As with most things in Zend Framework 2 there may be more than one way to do things, but this is how I did it. (Until someone informs me of a better way.)
In the Application module.config.php I created a factories node in the service_manager container where I pulled in the DefaultNavigationFactory.
Then I also added a navigation container where I specified the sitemap for the site.
NOTE: To add navigation specific for each module you would simply create this container in the specific module.config.php.
Next I added a route for the future sitemap to be viewed. Notice how I simply added a sitemapAction to the Application IndexController. You can add it wherever you desire if you want to create a separate controller or whatever, I just left it there.
Because I just want the xml produced by the helper, I created a blank layout xml.phtml that does nothing more than output the content of the view.
The sitemap.phtml view is also pretty simple and outputs the xml sitemap created by the helper.
In my controller I specified the layout to use, nothing more was needed.
By navigation to the URL specified in the route we should now be able to view the XML output.
In this example someone would need to navigate to /sitemap to view the sitemap, but some automated tools would try to go to /sitemap.xml which would fail with this setup. I will come back at some point in the future and enable the file extension to be ignored (after I figure out how).
The entire process is really pretty simple once the pieces are all in place, and the output was accepted by the various search engine webmaster tools…SCORE!