我会做这样的事情;
<?php
/*
CREATE TABLE `options` (
`id` int(11) unsigned NOT NULL AUTO_INCREMENT,
`name` varchar(64) DEFAULT NULL,
`value` text,
PRIMARY KEY (`id`),
UNIQUE KEY `name` (`name`)
);
INSERT INTO `options` (`id`, `name`, `value`)
VALUES
(1, 'generic_keywords', 'This,is,my,generic.keywords'),
(2, 'generic_description', 'This is a brief site summary'),
(3, 'page_status_active', '1'),
(4, 'page_status_draft', '2'),
(5, 'page_status_invisible', '2'),
(6, 'page_status_archived', '4'),
(7, 'listing_length', '20'),
(8, 'page_status_deleted', '9');
*/
function systemOptions() {
$options = FALSE;
$query = $this->db->get('options');
if($query->num_rows() > 0) {
foreach($query->result() as $row) {
$data = new StdClass;
$data->{$row->name} = $value;
$options[] = $data;
}
}
return $options;
}
function systemOption($name) {
$query = $this->db->get_where('options', array('name' => $name), 1);
return ($query->num_rows() == 1) ? $query->row() : FALSE;
}