我已经有一个使用 core php 构建的网站。但现在我想添加更多功能,如 fb connect 等。我希望将 CodeIgniter 用于这些新功能。在这种情况下,我应该将旧代码转换为 CodeIgniter,然后添加新功能,还是有其他方法可以使用 CodeIgniter 仅添加新功能?
3 回答
只要您现有的应用程序和 CI 之间没有名称(函数/类/等)冲突,我认为这是将 CI 的 index.php 导入您的应用程序的问题。您必须通过您的应用程序获取 CI 对象的句柄=& get_instance()
才能访问 CI 内容。
从那里开始,将所有$this->(function name)
调用替换为(your variable)->(function name)
来自 CI 的问题。
例如:
$this->CI =& get_instance();
$this->load->view('welcome_message')
你打电话而不是打电话$this->CI->load->view('welcome_message')
免责声明:我还没有真正尝试过从另一个应用程序中调用 CI。我在 CI 插件/库几乎是普通的旧 PHP 的前提下进行操作。在此处查看更多信息:http: //codeigniter.com/user_guide/general/creating_libraries.html
但我同意其他响应者的观点,如果您花时间将应用程序移植到 CI,从长远来看可能会更容易。
如果这是我的情况,那将是一个问题。如果您的站点具有巨大的功能,那么从旧的 PHP -> CI 传输代码对您来说将是一项乏味的工作。但如果你有足够的耐心,不妨试一试。顺便说一句,CodeIgniter 很好 :)。我的英语不怎么好。对不起!:\
I would recommend you to use CI for development. Initially it might be hassle to port your code from normal php to CI. That too done properly won't be much hassle.
Once you will move to CI, your code will be organized, then you can enhance features in future. It will make your task very easy.
If you only want to move to CI just to add facebook connect. There is not much difference adding faceebook connect in normal php or CI.