Fork Me on GitHub

Fabriq::link_to() to use or not to use?

March 27, Sun 10:35 am

Back in the days before the PathMap (and BaseMapping) core classes were added and the introduction of modules which brought forth the pathmap module, the Fabriq::link_to() function made perfect sense. In those days URLs for Fabriq sites/apps always only contained the controller and action and all of your other variables were query strings.

The BaseMapping and PathMap core classes were added to enable the beginnings of creating custom paths as well as write fully clean URLs. The BaseMapping has the core mapping functionality and the PathMap class extends BaseMapping and lives in the /app directory so that it can easily be added to.

A handy feature that was moved from the Fabriq class to the PathMap class was the build_path() function. By calling PathMap::build_path() and passing in a variable number of arguments, a URL is built for either clean URLs if they're turned on (which it is recommended that they are) or not clean URLs. This function came in handy for update actions where you also want to pass in the item ID that you're working on (ex: http://example.com/controller/update/123) in a form element's action attribute. While Fabriq::link_to() is used to build a complete link, you can build a more natural looking HTML link by using the PathMap::build_path() function for href attribute of an <a> tag.

So is it bad to use Fabriq::link_to()? In traditional controller and action only in the path circumstances, probably not, but it is recommended to use the newer and more versatile PathMap::build_path() function in an <a> tag's href attribute. At this point, there are no plans to depricate Fabriq::link_to(), but it could happen at some point in the future in favor of using PathMap::build_path().

Return to blog