Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/296.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/6/codeigniter/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Php 在codeigniter库函数中,如何调用同一库的另一个函数_Php_Codeigniter_Codeigniter 3 - Fatal编程技术网

Php 在codeigniter库函数中,如何调用同一库的另一个函数

Php 在codeigniter库函数中,如何调用同一库的另一个函数,php,codeigniter,codeigniter-3,Php,Codeigniter,Codeigniter 3,由于这两个方法属于同一类,只需替换以下内容: $this->CI->xor\u字符串($ns1,URL\u到参数键) 为此: $this->xor\u字符串($ns1,URL\u到参数键)我建议不要使用static,或者将需要的函数也设置为static。您可能不想在类中创建类的实例。这只是你不需要的大量开销。您还可以将所有这些内容移动到帮助文件中(不是CI中的所有内容都需要在类中) 类加密{ /*不需要 受保护$CI; 公共函数构造(){ $this->CI=&get_instance(); }

由于这两个方法属于同一类,只需替换以下内容:

$this->CI->xor\u字符串($ns1,URL\u到参数键)

为此:


$this->xor\u字符串($ns1,URL\u到参数键)

我建议不要使用static,或者将需要的函数也设置为static。您可能不想在类中创建类的实例。这只是你不需要的大量开销。您还可以将所有这些内容移动到帮助文件中(不是CI中的所有内容都需要在类中)

类加密{
/*不需要
受保护$CI;
公共函数构造(){
$this->CI=&get_instance();
}
*/
公共静态函数decryptParam($url){
$ns1=base64_解码($url);
$result=self::xor_字符串($ns1,URL_TO_PARAM_KEY);
返回json_decode($result);
}
公共静态函数xor_字符串($string,$key){
对于($i=0;$i
我遇到这样的错误,致命错误:当不在中的对象上下文中时使用$this,您将函数声明为static。删除它,否则您需要在函数中创建类的实例,这可能有点麻烦。每当我看到
static
时,我认为,至少在CI中,您最好使用助手而不是类。完全正确。。。我以前没注意到<代码>自我::异或字符串
然后:)。。。尽管如此,我同意亚历克斯的观点。如果您确实需要使用CI进行静态处理,那么最好使用帮助器类,而不是处理静态和类实例化的所有开销
<?php

defined('BASEPATH') OR exit('No direct script access allowed');
define('URL_TO_PARAM_KEY', 'x09c22f5');

class Encryption {

    protected $CI;
    public function __construct() {
        $this->CI =& get_instance();
    }

    public static function decryptParam($url) {

        $ns1 = base64_decode($url);
        $result = $this->CI->xor_string($ns1, URL_TO_PARAM_KEY);
        return json_decode($result);
    }

    public function xor_string($string, $key) {
        for ($i = 0; $i < strlen($string); $i++)
            $string[$i] = ($string[$i] ^ $key[$i % strlen($key)]);
        return $string;
    }
}
class Encryption {

    /* not needed
    protected $CI;
    public function __construct() {
        $this->CI =& get_instance();
    }
    */

    public static function decryptParam($url) {

        $ns1 = base64_decode($url);
        $result = self::xor_string($ns1, URL_TO_PARAM_KEY);
        return json_decode($result);
    }

    public static function xor_string($string, $key) {
        for ($i = 0; $i < strlen($string); $i++)
            $string[$i] = ($string[$i] ^ $key[$i % strlen($key)]);
        return $string;
    }
}