开发者

How to easily include links to other pages of my site within my PHP files?

开发者 https://www.devze.com 2023-04-08 09:36 出处:网络
I was wondering if there is a way to make the following process more automated (so links automatically update throughout if the links get changed).

I was wondering if there is a way to make the following process more automated (so links automatically update throughout if the links get changed).

I have a PHP site, with a front controller.

Now I'm wondering how would I go about displaying certain links (to pages) within the different PHP files? (I don't want to actually do so manually...as that would mean 开发者_如何学运维if the page name got changed I'd have to manually flick through all the files).

Basically what I'm looking for is a way I can include links to pages on my site easily and automatically.

I had an idea of storing them in an config array and then using some sort of wrapper/helper function in the PHP files to retrieve them from the config array and display them (but not sure if its the best way forward or if there are other ways)?

Perhaps something like how WordPress does it (although I'm not familiar with it I've heard that its using a similar technique...) as what I have is a front controller alongside a mapping array (containing the urls of the pages) - if that helps.

Appreciate all approaches and responses.


I recommend looking at some of PHP's great MVC frameworks for the best examples of using the strengths of MVC to do dynamic routing and access those routes in your views, so they update automatically.

Code Igniter, CakePHP, Zend Framework

I'm partial to CodeIgniter myself, but they all have their strengths.

I seriously suggest you look into adopting one of these frameworks if your application is complex enough to need this level of route management. No need to reinvent the wheel. Using a framework lets you spend less time messing with the nuts and bolts and more time just building your application.

Whether you use the framework or not, they are probably better examples of good object oriented design than you are likely to find in wordpress.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号