Custom classes in CodeIgniter

前端 未结 6 564
走了就别回头了
走了就别回头了 2021-01-31 05:45

Seems like this is a very common problem for beginners with CodeIgniter, but none of the solutions I\'ve found so far seems very relevant to my problem. Like the topic says I\'m

6条回答
  •  栀梦
    栀梦 (楼主)
    2021-01-31 06:05

    Codeigniter has a common function to instantiate individual classes.

    It is called load_class(), found in /system/core/Common.php

    The function;

    /**
    * Class registry
    *
    * This function acts as a singleton.  If the requested class does not
    * exist it is instantiated and set to a static variable.  If it has
    * previously been instantiated the variable is returned.
    *
    * @access   public
    * @param    string  the class name being requested
    * @param    string  the directory where the class should be found
    * @param    string  the class name prefix
    * @return   object
    */
    

    The signature is

    load_class($class, $directory = 'libraries', $prefix = 'CI_')
    

    An example of it being used is when you call the show_404() function.

提交回复
热议问题