Witam,
mam problem z rolami. Ogólnie role są rozpoznawane (admin/user) tylko w przypadku danej roli mam problem z wyświetleniem contentu z kodu poniżej:
Błąd dotyczy fuction index w którym otrzymuję komunikat : Message: Undefined index: content, Filename: controllers/site.php, Line Number: 107 (patrz komentarz).
Dziwne jest to że defakto wszystko jest wyświetlane poprawnie, tzn. jeżeli $perm = user -> wyświetla tylko "Zaloguj" (oraz błąd) a jeśli $perm = admin -> zawartość if (w tym momencie nie ma żadnego błędu).
Błąd jest tylko przy pierwszym ekranie i po wylogowaniu.
class Site extends Controller
{
function Site()
{
parent::Controller();
$this->load->model('User');
$this->response = array(); }
// bazowy kontroler
function index()
{
if(Site::_check_perm('admin')){
//echo 'admin';
$users = $this->User->get_users()->result_array();
{
$this->response['content'] = $this->load->view('user_list', array('users' => $users), True); //echo 'user_list';
}
else
{
$this->response['content'] = 'Brak użytkowników<br /><div style="text-align:center;"><h2><a href="'.site_url('site/user_add/').'">Dodaj Użytkownika</a></h2></div>';
}
}
IF(Site::_check_login())
{
$this->response['content'] .= '<br /><div style="text-align:center;"><h2><a href="'.site_url('site/logout/').'">Wyloguj</a></h2></div>';
}
else
{
$this->response['content'] .= '<br /><div style="text-align:center;"><h2><a href="'.site_url('site/login/').'">Zaloguj</a></h2></div>'; //------LINIA 107 !!
}
$this->load->view('index', $this->response);
}
// dodanie użytkownika
function user_add()
{
$data["login"] = array('name' => 'login'); $data['haslo'] = array('name' => 'haslo'); $data['email'] = array('name' => 'email');
$rules['login'] = "required|max_length[100]|xss_clean";
$rules['haslo'] = "required|max_length[100]|xss_clean";
$rules['email'] = "required|max_length[100]|xss_clean|valid_email";
$this->validation->set_rules($rules);
$ar = $this->User->get_user_by_login($this->input->post('login'))->result_array();
if ($this->validation->run() == FALSE)
{
$data['login']['value'] = $this->input->post('login');
$data['haslo']['value'] = $this->input->post('haslo');
$data['email']['value'] = $this->input->post('email');
$this->response['content'] = $this->load->view('user_add', $data, True);
}
{
$this->User->add_user(array('user_login' => $this->input->post('login'), 'user_email' => $this->input->post('email'), 'user_password' => sha1
(md5($this->input->post('haslo'))), 'user_active' => '1')); $this->response['content'] = '<h1>Dane zapisane</h1><META HTTP-EQUIV="Refresh" CONTENT="1; URL='.site_url('site').'">';
}
else
{
$this->response['content'] = '<h1>Użytkownik już istnieje w bazie danych</h1>';
}
$this->load->view('index', $this->response);
}
//edycja konta
function user_edit()
{
$id = $this->uri->segment(3);
{
$ar = $this->User->get_user_by_id($id)->result_array();
$data["login"] = array('name' => 'login'); $data['haslo'] = array('name' => 'haslo'); $data['email'] = array('name' => 'email'); $data['perms'] = array('name' => 'perms');
$rules['login'] = "required|max_length[100]|xss_clean";
$rules['perms'] = "xss_clean";
$rules['haslo'] = "max_length[100]|xss_clean";
$rules['email'] = "required|max_length[100]|xss_clean|valid_email";
$this->validation->set_rules($rules);
if ($this->validation->run() == FALSE)
{
IF(strlen($this->input->post('tytul')) > 0
) {
$data['login']['value'] = $this->input->post('login');
$data['haslo']['value'] = $this->input->post('haslo');
$data['email']['value'] = $this->input->post('email');
$data['perms']['value'] = $this->input->post('perms');
}
else
{
$data['login']['value'] = $ar[0]['user_login'];
$data['email']['value'] = $ar[0]['user_email'];
$data['perms']['value'] = $ar[0]['user_perms'];
}
$this->response['content'] = $this->load->view('user_edit', $data, True);
}
else
{
IF(strlen($this->input->post('haslo')) > 0
) {
$this->User->update_user($id, array('user_login' => $this->input->post('login'), 'user_email' => $this->input->post('email'), 'user_perms' => $this->input->post('perms'), 'user_password' => sha1
(md5($this->input->post('haslo'))))); }
else
{
$this->User->update_user($id, array('user_login' => $this->input->post('login'), 'user_email' => $this->input->post('email'), 'user_perms' => $this->input->post('perms'))); }
$this->response['content'] = '<h1>Zmiany zapisane</h1><META HTTP-EQUIV="Refresh" CONTENT="1; URL='.site_url('site').'">';
}
}
else
{
$this->response['content'] = '<h1>Niepoprawny URL</h1>';
}
$this->load->view('index', $this->response);
}
// usunięcie usera
function user_delete()
{
$id = $this->uri->segment(3);
{
$this->User->delete_user($this->uri->segment(3));
$this->response['content'] = '<h1>User skasowany</h1><META HTTP-EQUIV="Refresh" CONTENT="1; URL='.site_url('site').'">';
$this->load->view('index', $this->response);
}
}
################################################################
// czy jestem zalogowany
function _check_login()
{
IF($cookie = $this->input->cookie('cicookie', True))
{
{
$ar = $this->User->get_user_by_login($dane['user'])->result_array();
//echo $ar[0]['user_perms'];
//echo 'sesja '.$this->session->set_userdata($ar[0]['user_perms']);
// echo $rola;
IF(isset($ar[0
]) and
$ar[0]['user_last_login_ip'] == $this->input->ip_address() and sha1
(md5($ar[0]['user_login'].$ar[0]['user_password'])) == $dane['pass']) {
return true;
}
else
{
return false;
}
}
else
{
return false;
}
}
else
{
return false;
}
}
// czy mam uprawnienie $perm
function _check_perm($perm)
{
IF($cookie = $this->input->cookie('cicookie', True))
{
{
$ar = $this->User->get_user_by_login($dane['user'])->result_array();
IF(isset($ar[0
]) and
$ar[0]['user_last_login_ip'] == $this->input->ip_address() and sha1
(md5($ar[0]['user_login'].$ar[0]['user_password'])) == $dane['pass']) {
IF(strrchr($ar[0]['user_perms'], $perm)) {
return true;
}
else
{
return false;
}
}
else
{
return false;
}
}
else
{
return false;
}
}
else
{
return false;
}
}
// logowanie
function login()
{
$data["login"] = array('name' => 'login'); $data['pass'] = array('name' => 'pass');
$rules['login'] = "required|max_length[100]|xss_clean";
$rules['pass'] = "required|max_length[100]|xss_clean";
$this->validation->set_rules($rules);
$fields['login'] = 'Login';
$fields['pass'] = 'Hasło';
$this->validation->set_fields($fields);
if ($this->validation->run() == FALSE)
{
$data['login']['value'] = $this->input->post('login');
$data['pass']['value'] = $this->input->post('pass');
$this->response['content'] = $this->load->view('login', $data, True);
}
else
{
$ar = $this->User->get_user_by_login($this->input->post('login'))->result_array();
IF(isset($ar[0
]) and
$ar[0]['user_password'] == sha1
(md5($this->input->post('pass')))) {
$a = array('user' => $this->input->post('login'), 'pass' => sha1
(md5($this->input->post('login').$ar[0]['user_password']))); $this->User->update_login_ip($this->input->post('login'), $this->input->ip_address());
$this->response['content'] = '<h1>Zalogowany</h1><META HTTP-EQUIV="Refresh" CONTENT="1; URL='.site_url('site').'">';
}
else
{
$this->response['content'] = '<h1>Błąd logowania</h1><META HTTP-EQUIV="Refresh" CONTENT="1; URL='.site_url('site').'">';
}
}
$this->load->view('index', $this->response);
}
//wylogowanie
function logout()
{
header('Location: '.site_url
('site')); }
}
Nie mam pojęcia jak się pozbyć tego błędu proszę o pomoc i czym ten błąd jest spowodowany.
edit 1 :
udało mi się rozwiązać problem, co prawda metodą prób i błędów ale teraz działa.
W funkcji index() usunęłam kropki (.) przy response content a także usunięcie wartości True przy response->content = load->view.
Jak ktoś ma pomysł dlaczego tak się dzieje i czy może to zostać proszę o opinie.
Ten post edytował agata 14.07.2010, 11:26:39