Witaj Gościu! ( Zaloguj | Rejestruj )

Forum PHP.pl

 
Reply to this topicStart new topic
> [PHP]Problem z poprawnym wyświetlaniem
papik11
post
Post #1





Grupa: Zarejestrowani
Postów: 3
Pomógł: 0
Dołączył: 16.05.2014

Ostrzeżenie: (0%)
-----


Cześć, mam pewien problem z poprawnym wyświetlaniem stron...
Próbuję napisać stronke w PHP(Wamp/eclipse) i piszę ją według tutoriala, jednak w filmiku działa jak należy a mnie nie:/
Aktualnie jestem przy tworzeniu okna do logowania użytkowników.
To co mam stworzone:

Baza danych - > Users

2 pliki w View/Users ->register.ctp i login.ctp (to co ma się wyświetlać na stronce)

Model/Users.php
  1. <?php
  2. class User extends AppModel{
  3. var $name='User';
  4. }
  5. ?>


Component/UsersController.php
  1. <?php
  2. class UsersController extends AppController{
  3. var $name = 'Users';
  4. var $components = array('Auth');
  5. function beforeFilter(){
  6. $this ->Auth->userModel = 'User';
  7. $this ->Auth->allow('*');
  8. }
  9. function register(){
  10. if(!empty($this->data)){
  11. if($this ->User->validates()){
  12. $this ->User->save($this->data);
  13. $data = $this->User->read();
  14. $this->Auth->login($data);
  15. $this->redirect('/sheets');
  16. }
  17. }
  18. }
  19. function login(){
  20. if (!empty($this->data)){
  21. if($this->Auth->login($this->data)){
  22. $this->redirect('/sheets');
  23. }
  24. else{
  25. $this->User->invalidate('username', 'login i/lub haslo nie poprawne');
  26. }
  27. }
  28. }
  29. function logout(){
  30. $this ->Auth->logout();
  31. $this ->redirect('/');
  32. }
  33. }
  34. ?>


Problem pojawia się w momencie gdy próbuje wyświetlić zawartość "register"
wpisując w adresie strony:
localhost/metal/users/register
za każdym razem przekierunkowywuje mnie na:
localhost/metal/users/login
i niewiem za bardzo dlaczego, siedze nad już kilka godzin i nic:/
Jeżeli ktoś wie co mam źle/czego brakuje to proszę pomoc.
Go to the top of the page
+Quote Post
nospor
post
Post #2





Grupa: Moderatorzy
Postów: 36 557
Pomógł: 6315
Dołączył: 27.12.2004




Tak troche nie na temat choc kto wie...


Zmien tutorial.... ten kod co tu masz byl pisany 100 lat temu, jeszcze w epoce php łupanego. Tylko nabierzesz zlej wiedzy odnosnie klas i pewnie calej masy innych rzeczy
Go to the top of the page
+Quote Post
Xart
post
Post #3





Grupa: Zarejestrowani
Postów: 267
Pomógł: 6
Dołączył: 8.04.2013

Ostrzeżenie: (0%)
-----


Nospor ma rację w PHP nie używa się już np słowa kluczowego var (IMG:style_emoticons/default/smile.gif) a u Ciebie w kodzie pełno...
Go to the top of the page
+Quote Post
papik11
post
Post #4





Grupa: Zarejestrowani
Postów: 3
Pomógł: 0
Dołączył: 16.05.2014

Ostrzeżenie: (0%)
-----


Ok, zmieniłem tutorial na nowszy ale nadal mam problem:/
kod z usersController
  1. public function login() {
  2. if ($this->Auth->loggedIn()) {
  3. $this->redirect(array('controller' => 'index', 'action' => 'index'));
  4. }
  5. if ($this->request->is('post')) {
  6. if ($this->Auth->login()) {
  7. if ($this->request->data['User']['remember_me'] == 1) {
  8. unset($this->request->data['User']['remember_me']);
  9. $this->request->data['User']['password'] = $this->Auth->password($this->request->data['User']['password']);
  10. $this->Cookie->write('remember_me_cookie', $this->request->data['User'], true, '2 weeks');
  11. }
  12. $this->User->id = $this->Auth->user('id');
  13. $this->User->saveField('last_login', date('Y-m-d H:i:s'));
  14. $this->redirect($this->Auth->redirect());
  15. } else {
  16. $this->Session->setFlash('Nieprawidłowy login lub hasło');
  17. }
  18. }
  19. }

AppController
  1. public $components = array(
  2. 'Cookie',
  3. 'Auth',
  4. 'Session'
  5. );
  6. public function beforeFilter() {
  7. $this->Auth->deny();
  8. if (!$this->Auth->loggedIn() && $this->Cookie->read('remember_me_cookie')) {
  9. $cookie = $this->Cookie->read('remember_me_cookie');
  10. $user = $this->User->find('first', array(
  11. 'conditions' => array(
  12. 'User.username' => $cookie['username'],
  13. 'User.password' => $cookie['password']
  14. )
  15. ));
  16.  
  17.  
  18. if ($user && !$this->Auth->login($user['User'])) {
  19. $this->redirect(array('controller' => 'users', 'action' => 'login'));
  20. }
  21. }
  22. $this->Auth->loginAction = array('controller' => 'users', 'action' => 'login');
  23. $this->Auth->logoutRedirect = array('controller' => 'users', 'action' => 'login');
  24. $this->Auth->loginRedirect = array('controller' => 'index', 'action' => 'index');
  25. }

przy próbie zalogowania na stworzone w phpmyadmin konto, za każdym razem wyskakuje "Nieprawidłowy login lub hasło"...
phpmyadmin
  1. CREATE TABLE IF NOT EXISTS `users` (
  2. `id` int(10) NOT NULL AUTO_INCREMENT,
  3. `username` varchar(255) NOT NULL,
  4. `name` varchar(255) NOT NULL,
  5. `password` varchar(255) NOT NULL,
  6. `email` varchar(255) NOT NULL,
  7. `last_login` datetime NOT NULL,
  8. `created` datetime NOT NULL,
  9. PRIMARY KEY (`id`),
  10. UNIQUE KEY `username` (`username`),
  11. UNIQUE KEY `email` (`email`)
  12. ) ENGINE=InnoDB DEFAULT CHARSET=latin2;
Go to the top of the page
+Quote Post
nospor
post
Post #5





Grupa: Moderatorzy
Postów: 36 557
Pomógł: 6315
Dołączył: 27.12.2004




Widac metoda $this->Auth->login() zwraca ci FALSE....

ps: tabele to tez koles od tutka robił?
Go to the top of the page
+Quote Post
Xart
post
Post #6





Grupa: Zarejestrowani
Postów: 267
Pomógł: 6
Dołączył: 8.04.2013

Ostrzeżenie: (0%)
-----


Jeżeli ta tabelka była robiona przez kolesia od tutka to zmień tuta. No niestety większość tutów jest niektualna na YT. Ja niedługo ruszam z nagrywaniem kursu PHP od podstaw (IMG:style_emoticons/default/smile.gif)
Go to the top of the page
+Quote Post
papik11
post
Post #7





Grupa: Zarejestrowani
Postów: 3
Pomógł: 0
Dołączył: 16.05.2014

Ostrzeżenie: (0%)
-----


Tylko że na necie niema już sensownych tutoriali, które pokazują jak robić stronkę od podstaw...:/
Go to the top of the page
+Quote Post
Xart
post
Post #8





Grupa: Zarejestrowani
Postów: 267
Pomógł: 6
Dołączył: 8.04.2013

Ostrzeżenie: (0%)
-----


Jeśli chodzi o programowanie obiektowe to rzeczywiście jest ciężko ale jeśli chodzi tylko o naukę podstaw PHP i ważnych jego elementów nie jest najgorzej.

http://www.youtube.com/user/uwteamorg - Na tym kanale znajdują się bardzo dobre kursy programowania i nie tylko. Sam z nich kiedyś korzystałem. Proponuję zacząć od obejrzenia kursów PHP, SQL z tego właśnie kanału. Jeśli natomiast chodzi o programowanie obiektowe to żeby je zrozumieć wspierałem się tym tutem z tego kanału http://www.youtube.com/user/MinDControlDx aczkolwiek są tam też błędy - np w przypadku metod magicznych __set, __get etc. A potem manual forum i poszło

Pozdrawiam
Go to the top of the page
+Quote Post

Reply to this topicStart new topic
2 Użytkowników czyta ten temat (2 Gości i 0 Anonimowych użytkowników)
0 Zarejestrowanych:

 



RSS Aktualny czas: 18.09.2025 - 11:47