Need single entry point like solution

北慕城南 提交于 2019-12-25 07:26:03

问题


I work on ready made framework (legacy framework).Its almost like any other MVC framwork you get in market, except that its not having single entry point.
So in every Controller file I have to include configs & Model classes.
Currently I manage with __autoload() , but still one include is left on every page.
If I add .htaccess for single entry point then I have to do lots of changes in my code.Because every controller file is different physical file.Its not even near to object oriented structure and for views smarty is used.
Is there any solution including .htaccess rules , instead of php.ini? It will be easier to maintain. Please suggest best solutions for my dificulty.


回答1:


The best suggestion I could give you is by using auto prepend files. Before any script runs, a piece of code is prepended to it.

In Apache you can set this per directory using the php_value auto_prepend_file xxx.php directive.




回答2:


You could route all traffic to one PHP script, usually index.php like so:

RewriteEngine on
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule .* index.php [L]

Then index.php would handle all necessary library files and handle the routing for the controllers.



来源:https://stackoverflow.com/questions/12178941/need-single-entry-point-like-solution

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!