dt3674 2019-05-07 03:42
浏览 96

PHP:如果用户在特定页面上,则编写指向不同链接的函数

I'm fairly new to PHP. I have a small issue with an application I'm working on. I have a very simple header for the application that displays on all the pages. Heres's my code for it:

Header

function writeHeader($profile) {
    <a href="update_profile">Update Profile</a>
}

The purpose of the header is to direct the user to their "Update Profile" page. So the header functions just fine if the user is on the Index page (because the route is just "update_profile"). But I have several sub-pages in my app, they are structured kind of like this:

-index.phtml
-characters/create.phtml
-characters/edit.phtml
-worlds/create.phtml
-worlds/edit.phtml
-etc.

Whenever a user navigates to a page other than "Index", the link stops working because the route has changed.

I considered writing a whole new functions just to write headers specifically for these pages, but I'm wondering if there's a way to just update the function I have now to change the route if the user is navigating to the "Update Profile" page from anywhere other than Index. Can anyone give any suggestions for how to do this?

  • 写回答

2条回答 默认 最新

  • dongmiao4733 2019-05-07 04:35
    关注

    You have to be the closest possible to what you'll get in production. It means that you don't have to target the localhost, but the domain instead. To do so, you have to create a virtual host in your http.conf file, and target it. This way, you should be able to use the absolute path, as Nick said, and it will be the same once your app will be deployed.

    评论

报告相同问题?

悬赏问题

  • ¥15 使用C#,asp.net读取Excel文件并保存到Oracle数据库
  • ¥15 C# datagridview 单元格显示进度及值
  • ¥15 thinkphp6配合social login单点登录问题
  • ¥15 HFSS 中的 H 场图与 MATLAB 中绘制的 B1 场 部分对应不上
  • ¥15 如何在scanpy上做差异基因和通路富集?
  • ¥20 关于#硬件工程#的问题,请各位专家解答!
  • ¥15 关于#matlab#的问题:期望的系统闭环传递函数为G(s)=wn^2/s^2+2¢wn+wn^2阻尼系数¢=0.707,使系统具有较小的超调量
  • ¥15 FLUENT如何实现在堆积颗粒的上表面加载高斯热源
  • ¥30 虚心请教几个问题,小生先有礼了
  • ¥30 截图中的mathematics程序转换成matlab