Pathname
Understanding and harnessing the power of the $uri
and $pathname
variables in web development can significantly enhance the functionality and user experience of your applications. These variables provide invaluable insights into the structure of the current request, enabling developers to tailor responses dynamically and streamline navigation pathways.
Pathname
The $pathname
variable returns the pathname of the current request: "/docs", excluding the leading slash ("/"). You can use this variable to access the pathname of the current request, which includes the path.
You can use these variables to build your menu navigation, easily access the current page, and more.
Example
<nav class="ml-auto flex gap-4 sm:gap-6">
<a class="text-sm font-medium hover:underline underline-offset-4 <?= $pathname === '/' ? 'underline' : '' ?>" href="/">
Home
</a>
<a class="text-sm font-medium hover:underline underline-offset-4 <?= $pathname === '/docs' ? 'underline' : '' ?>" href="/docs">
Documents
</a>
</nav>
Summary
The $uri
and $pathname
variables provide convenient ways to access the URI and pathname of the current request in Prisma PHP. By using these variables, you can access the full URI of the current request and the path portion of the URI without the query string, respectively.