用户
 找回密码
 入住 CI 中国社区
搜索
查看: 1703|回复: 3
收起左侧

[HELP] 如何在 CI 框架中加载自定义的数据结构

[复制链接]
发表于 2012-12-14 12:19:52 | 显示全部楼层 |阅读模式
请问一下大大们,在应用CI框架中,如果我有许多结构体和枚举类型的定义,这些定义该放在哪个文件夹,如何加载呢?
好像使用 CI 的 Library 不行,因为它的加载是靠 $this->load->library('xxx'); 并且在这次运行中只会产生一个实例对象,而且它的文件和类名也要匹配。

还请大家赐教~~
谢谢
发表于 2012-12-14 12:55:24 | 显示全部楼层
无论CI怎么NB, 他都是PHP,php加载文件不都是包括嘛  如include,有些时候不要想的太多致无法入手 ,简单就好/。
发表于 2012-12-14 14:37:21 | 显示全部楼层
结构体,我没有看错吧。
 楼主| 发表于 2012-12-14 15:29:17 | 显示全部楼层
本帖最后由 Lory 于 2012-12-14 15:33 编辑

多谢1楼兄弟,尝试了一下,可以的
这个数据结构是和数据库里相匹配的,方便程序中操作
用 require_once 包含
PHP复制代码
 
<?Php if ( ! defined('BASEPATH')) exit('No direct script access allowed');
 
class ACTA_terminal
{
        private $property = array();
       
        public function __construct()
        {
                $this->property['TerminalID']       = '';
                $this->property['TerminalGroupID']  = '';
                $this->property['TerminalGroup']    = '';
                $this->property['TerminalSN']       = '';
                $this->property['TerminalType']     = '';
                $this->property['TerminalName']     = '';
                $this->property['TerminalIP']       = '';
                $this->property['TerminalModel']    = '';
                $this->property['FirmwareVersion']  = '';
                $this->property['FAMVersion']       = '';
                $this->property['Description']      = '';
                $this->property['RegisteredUser']   = '';
                $this->property['MaxUser']          = '';
                $this->property['AutomatchUser']    = '';
                $this->property['MaxAutomatchUser'] = '';
                $this->property['CurrentStatus']    = '';
                $this->property['RegStatus']        = '';
                $this->property['dmode']            = '';
                $this->property['last_update']      = '';
                $this->property['last_log']         = '';
        }
       
        public function __set($property, $value)
        {
                if (isset($this->property[$property]))
                {
                        $this->property[$property] = $value;
                }
        }
       
        public function __get($property)
        {
                if (isset($this->property[$property]))
                {
                        return $this->property[$property];
                }
               
                return FALSE;
        }
       
        /*
                从客户端传递的对象初始化本对象
        */

        public function loadFromObject($terminal)
        {
                $this->property['TerminalID']       = $terminal->terminalID;
                $this->property['TerminalType']     = $terminal->terminalType;
                $this->property['TerminalName']     = $terminal->terminalName;
                $this->property['TerminalSN']       = $terminal->terminalSN;
                $this->property['TerminalIP']       = $terminal->terminalIP;
                $this->property['TerminalModel']    = $terminal->terminalStatus->modelNumber;
                $this->property['FirmwareVersion']  = $terminal->terminalStatus->firmwareVersion;
                $this->property['Description']      = $terminal->terminalStatus->description;
                $this->property['RegisteredUser']   = $terminal->terminalStatus->registeredUsers;
                $this->property['MaxUser']          = $terminal->terminalStatus->maximumUsers;
                $this->property['AutomatchUser']    = $terminal->terminalStatus->automatchUsers;
                $this->property['MaxAutomatchUser'] = $terminal->terminalStatus->maximumAutomatchUsers;
        }
}
 
复制代码

本版积分规则