脚本宝典收集整理的这篇文章主要介绍了php – 如果CodeIgniter方法不存在,则重定向到默认方法.,脚本宝典觉得挺不错的,现在分享给大家,也给大家做个参考。
<?PHP if (!defined('BASEPATH')) exit('No direct script access Allowed'); class Components extends CI_Controller { public function __construct() { parent::__construct(); } public function _remap($method,$params = array()) { if (method_exists(__CLASS__,$method)) { $this->$method($params); } else { $this->test_default(); } } // this method is exists public function test_method() { echo "Yes,I am exists."; } // this method is exists public function test_another($param1 = '',$param2 = '') { echo "Yes,I am with " . $param1 . " " . $param2; } // not exists - when you call /compontents/login public function test_default() { echo "Oh!!!,NO i am not exists."; } }
由于默认为PHP保留,因此您无法使用它,因此您可以编写自己的默认方法,例如test_default.这将自动检查您的类中是否存在方法并相应地重定向.它还支持参数.这项工作非常适合我.你可以测试自己.谢谢!!
以上是脚本宝典为你收集整理的php – 如果CodeIgniter方法不存在,则重定向到默认方法.全部内容,希望文章能够帮你解决php – 如果CodeIgniter方法不存在,则重定向到默认方法.所遇到的问题。
本图文内容来源于网友网络收集整理提供,作为学习参考使用,版权属于原作者。
如您有任何意见或建议可联系处理。小编QQ:384754419,请注明来意。