Pomoc - Szukaj - Użytkownicy - Kalendarz
Pełna wersja: [Błąd] Fatal error: Call to undefined method
Forum PHP.pl > Forum > Przedszkole
aleks124
Witam,
Postawiłem sobie na pewien skrypt. Przy próbie zalogowania do panelu administracyjnego skrypt zwraca błąd:
Cytat
Fatal error: Call to undefined method Users_model::get_user_function() in C:\xampp\htdocs\app\controllers\administrator\auth.php on line 105


Linia 105 w pliku auth.php wygląda następująco:
Cytat
$query = $this->Users_model->get_user_function($login);


A tu fragment pliku users_model.php:
Cytat
function get_user_by_id($user_id)
{

$this->db->where('id', $user_id);

$result = $this->db->get($this->_table);

if($result->num_rows()!=0)
{
return $result;
}
else {
return false;
}
}

/*function get_user_by_username($username)
{
$this->db->where('username', $username);
return $this->db->get($this->_table);
}*/
function get_user_by_username($username)
{
$this->db->where('username', $username);
return $this->db->get($this->_table);
}
function get_user_by_email($email)
{
$this->db->where('email', $email);
return $this->db->get($this->_table);
}


Proszę o pilną pomoc sad.gif
nospor
A widzisz gdzies w pliku deklaracje funkcji get_user_function? Bo ja nie, php tez nie, i o tym wyraźnie cie informuje, że wywolujesz metodę, ktora nigdzie nie jest zadeklarowana.
aleks124
A mógłbyś mi pomoć tą funkcję zadeklarować?

Dziękuję.
nospor
Skoro podajesz tam LOGIN, to pewnie chodzilo ci o funkcje get_user_by_username() a te funkcję juz masz...
aleks124
W 102 linijce w pliku auth.php mam:
Kod
$get_user_function = "get_user_by_username";


Mimo wszystko próbowałem Twoich sugestii i nie pomogły, chyba, że robię to źle, oc jest możliwe, słabo to ogarniam i nie jestem przygotowany na tego typu przygody... Jeżeli możesz to opisz w miarę łopatologicznie.

Dzięki!
mls
Wobec tego zmień:
  1. $query = $this->Users_model->get_user_function($login);
na
  1. $query = $this->Users_model->$get_user_function($login);
aleks124
Zmieniłem, teraz błąd pojawia się na ułamek sekundy i wygląda tak:


niezdefiniowana zmienna login? jak i gdzie ją zdefiniować?
Rysh
Pokaż większy kawałek tego pliku używając tym razem [ php][ /php]
aleks124
Całość auth.php:
  1. <?php
  2. /**
  3.  * Script Auth Controller Class
  4.  *
  5.  * It helps to show the user account details
  6.  *
  7.  * @package Script
  8.  * @subpackage Controllers
  9.  * @category Auth
  10.  * @author Team
  11.  * @version 1.6
  12.  
  13.  
  14.  */
  15.  
  16. if (!defined('BASEPATH'))
  17. exit('No direct script access allowed');
  18.  
  19. class Auth extends CI_Controller
  20. {
  21.  
  22. public $min_username = 4;
  23. public $max_username = 20;
  24. public $min_password = 4;
  25. public $max_password = 20;
  26.  
  27. public function Auth()
  28. {
  29. parent::__construct();
  30.  
  31. $this->load->library("Form_validation");
  32. $this->load->library("DX_Auth");
  33. $this->load->helper("url");
  34. $this->load->helper("form");
  35. $this->load->library("session");
  36. $this->load->model("Users_model");
  37. $this->load->model("dx_auth/user_temp", "user_temp");
  38. $this->load->model("dx_auth/login_attempts", "login_attempts");
  39. }
  40.  
  41. public function index()
  42. {
  43. $this->login();
  44. }
  45.  
  46. public function username_check($username)
  47. {
  48. $result = $this->dx_auth->is_username_available($username);
  49. if (!$result) {
  50. $this->form_validation->set_message("username_check", "Username already exist. Please choose another username.");
  51. }
  52. return $result;
  53. }
  54.  
  55. public function email_check($email)
  56. {
  57. $result = $this->dx_auth->is_email_available($email);
  58. if (!$result) {
  59. $this->form_validation->set_message("email_check", "Email is already used by another user. Please choose another email address.");
  60. }
  61. return $result;
  62. }
  63.  
  64. public function captcha_check($code)
  65. {
  66. $result = TRUE;
  67. if ($this->dx_auth->is_captcha_expired()) {
  68. $this->form_validation->set_message("captcha_check", "Your confirmation code has expired. Please try again.");
  69. $result = FALSE;
  70. } else {
  71. if (!$this->dx_auth->is_captcha_match($code)) {
  72. $this->form_validation->set_message("captcha_check", "Your confirmation code does not match the one in the image. Try again.");
  73. $result = FALSE;
  74. }
  75. }
  76. return $result;
  77. }
  78.  
  79. public function recaptcha_check()
  80. {
  81. $result = $this->dx_auth->is_recaptcha_match();
  82. if (!$result) {
  83. $this->form_validation->set_message("recaptcha_check", "Your confirmation code does not match the one in the image. Try again.");
  84. }
  85. return $result;
  86. }
  87.  
  88. public function login()
  89. {
  90. $val = $this->form_validation;
  91. if ($this->input->post()) {
  92. $val->set_rules("usernameli", "Username", "trim|required|xss_clean");
  93. $val->set_rules("passwordli", "Password", "trim|required|xss_clean");
  94. $val->set_rules("remember", "Remember me", "integer");
  95. if ($this->form_validation->run()) {
  96. if ($this->config->item("DX_login_using_username") && $this->config->item("DX_login_using_email")) {
  97. $get_user_function = "get_login";
  98. } else {
  99. if ($this->config->item("DX_login_using_email")) {
  100. $get_user_function = "get_user_by_email";
  101. } else {
  102. $get_user_function = "get_user_by_username";
  103. }
  104. }
  105. $query = $this->Users_model->$get_user_function($login);
  106. if ($query && $query->num_rows() == 1) {
  107. $row = $val;
  108. if ($row->banned > 0) {
  109. $this->session->set_flashdata("flash_message", $this->Common_model->admin_flash_message("error", "Login failed! you are banned"));
  110. redirect_admin("login", "refresh");
  111. } else {
  112. $password = $this->dx_auth->_encode($password);
  113. $stored_hash = $row->password;
  114. if (crypt($password, $stored_hash) === $stored_hash) {
  115. $this->dx_auth->_set_session($row, "ALLOW");
  116. if ($row->newpass) {
  117. $this->users->clear_newpass($row->id);
  118. }
  119. if ($remember) {
  120. $this->dx_auth->_create_autologin($row->id);
  121. }
  122. $this->dx_auth->_set_last_ip_and_last_login($row->id);
  123. $this->dx_auth->_clear_login_attempts();
  124. $this->dx_auth_event->user_logged_in($row->id);
  125. $this->session->set_flashdata("flash_message", $this->Common_model->admin_flash_message("success", "Logged in successfully."));
  126. redirect_admin("", "refresh");
  127. } else {
  128. $this->session->set_flashdata("flash_message", $this->Common_model->admin_flash_message("error", "Login failed! Incorrect username or password"));
  129. redirect_admin("login", "refresh");
  130. }
  131. }
  132. } else {
  133. $this->session->set_flashdata("flash_message", $this->Common_model->admin_flash_message("error", "Login failed! Incorrect username or password"));
  134. redirect_admin("login", "refresh");
  135. }
  136. }
  137. }
  138. $data['message_element'] = "administrator/view_login";
  139. $data['auth_message'] = "You are already logged in.";
  140. $this->load->view("administrator/admin_template", $data);
  141. }
  142.  
  143. public function logout()
  144. {
  145. $this->dx_auth->logout();
  146. $data['auth_message'] = "You have been logged out.";
  147. $this->load->view($this->dx_auth->logout_view, $data);
  148. }
  149.  
  150. public function cancel_account()
  151. {
  152. if ($this->dx_auth->is_logged_in()) {
  153. $val = $this->form_validation;
  154. $val->set_rules("password", "Password", "trim|required|xss_clean");
  155. if ($val->run() && $this->dx_auth->cancel_account($val->set_value("password"))) {
  156. redirect_admin("", "location");
  157. } else {
  158. $this->load->view($this->dx_auth->cancel_account_view);
  159. }
  160. } else {
  161. $this->dx_auth->deny_access("login");
  162. }
  163. }
  164.  
  165. public function custom_permissions()
  166. {
  167. if ($this->dx_auth->is_logged_in()) {
  168. echo "My role: " . $this->dx_auth->get_role_name() . "<br/>";
  169. echo "My permission: <br/>";
  170. if ($this->dx_auth->get_permission_value("edit") != NULL && $this->dx_auth->get_permission_value("edit")) {
  171. echo "Edit is allowed";
  172. } else {
  173. echo "Edit is not allowed";
  174. }
  175. echo "<br/>";
  176. if ($this->dx_auth->get_permission_value("delete") != NULL && $this->dx_auth->get_permission_value("delete")) {
  177. echo "Delete is allowed";
  178. } else {
  179. echo "Delete is not allowed";
  180. }
  181. }
  182. }
  183.  
  184. }
  185.  
  186. ?>


Plik users_model.php za długi do wklejenia, więc pozwoliłem sobie na pastebin:
Kod
http://pastebin.com/v5e9my5E
Rysh
Spróbuj tak:
  1. $query = $this->Users_model->$get_user_function($this->input->post('usernameli');
aleks124
Teraz sypie 3 błędami przez ułamek sekundy


DX_Auth.php:
Kod
http://pastebin.com/kD9UMYpZ
To jest wersja lo-fi głównej zawartości. Aby zobaczyć pełną wersję z większą zawartością, obrazkami i formatowaniem proszę kliknij tutaj.
Invision Power Board © 2001-2025 Invision Power Services, Inc.