gusa - 13 May 2008 01:53 PM
hi!
congrats for the new framework. next month i’m starting an administration tool and i hope (and taking all these progress in account, i’m sure) that codex is going to help.
let me tell u about my situation. i’m not starting from the scratch. in fact, i’m programming in ci since -let me remember- 2006 (i’m programming a foreign commerce query system; checkout http://www.mercosur.int/sim/es/siaec/view_register/search_by_code for instance). and yeah, off course, i’m not the guy who chooses which database to use (we use sql server 2000) nor which app server (iis; arghhh).
besides, we have developed some admin stuff, using freakoutlight as auth system. in fact, we have modified fal because we don’t like database sessions. we like php native sessions (via http://codeigniter.com/wiki/Native_session/).
the first thing i found is that codex uses ob session, so my first question is whether it is possible to extend codexsession without touching the code.
OMG IT WORKED!
i found a way to make codex works with native_session + sql server.
steps:
0) create the user table and insert the admin user mannualy:
CREATE TABLE [dbo].[users] (
[id] [int] NOT NULL ,
[username] [varchar] (40) COLLATE Traditional_Spanish_CI_AS NOT NULL ,
[password] [varchar] (40) COLLATE Traditional_Spanish_CI_AS NOT NULL ,
[access_level] [int] NOT NULL
) ON [PRIMARY]
GO
1) overwrite codexsession:
class codexsession extends Native_Session {
public function __construct()
{
parent::Native_Session();
}
function sess_destroy()
{
$this->destroy();
}
function userdata($item, $read_once = FALSE)
{
$userdata = parent::userdata($item);
if ($read_once === TRUE && $userdata !== FALSE) {
$this->unset_userdata($item);
}
return $userdata;
}
function set_flashdata($newdata = array(), $newval = '')
{
if (is_string($newdata))
{
$newdata = array($newdata => $newval);
}
if (count($newdata) > 0)
{
foreach ($newdata as $key => $val)
{
parent::set_flashdata($key, $val);
}
}
}
}
Note: I had to modify backend.php because APPPATH points to ‘codex/application/’ and i need it to point to an absolute path.
3) change check method of codexlogin.php:
$username=$this->CI->db->escape($username);
$password=$this->CI->db->escape($password);
$sql = "SELECT id,username,access_level FROM {$this->users_table} WHERE username=$username AND password=$password";
4) change isLoggedIn method of codexlogin.php:
$sql = "SELECT {$this->users_table}.access_level FROM {$this->users_table} WHERE {$this->users_table}.id='$user_id'";
TADAAAAAM!! funciona!!!
now i can access to one of my tables. i’m getting errors when i try to edit any row, but the first step is done.
TODO LIST:
* filter the list of tables in the main-nav (see the attached image).
* if the main-nav spans into multiple lines, the search-plus display box breakes down.
Click thumbnail to see full-size image