Witaj Gościu! ( Zaloguj | Rejestruj )

Forum PHP.pl

 
Reply to this topicStart new topic
> [ZF][ZendFramework] Tworzenie plików php dla widoku
l3szcz
post
Post #1





Grupa: Zarejestrowani
Postów: 16
Pomógł: 0
Dołączył: 19.08.2012

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


Witam, od razu chciałbym zaznaczyć, że pierwszy raz tworzę w Zend.
Chciałbym zrobić oddzielny plik, dokładniej user.php i wyrenderować widok z /view/scripts/user oraz oczywiście użyć kontrolera UserController.php. Nie wiem jak się za to zabrać a projekt muszę wykonać jak najszybciej. Pomocy! facepalmxd.gif
Go to the top of the page
+Quote Post
Turson
post
Post #2





Grupa: Zarejestrowani
Postów: 4 291
Pomógł: 829
Dołączył: 14.02.2009
Skąd: łódź

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


w UserController.php
  1. public function userAction(){}


i user.php tam gdzie podałeś
Go to the top of the page
+Quote Post
l3szcz
post
Post #3





Grupa: Zarejestrowani
Postów: 16
Pomógł: 0
Dołączył: 19.08.2012

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


user.php mam w /public - kontroler zrobiony lecz nie wyświetla zawartości.
Go to the top of the page
+Quote Post
Turson
post
Post #4





Grupa: Zarejestrowani
Postów: 4 291
Pomógł: 829
Dołączył: 14.02.2009
Skąd: łódź

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


Pokaż dokładnie jaki masz kontroler, jak się nazywa i gdzie masz widok
Widok ma mieć rozszerzenie phtml a nie php!

Ten post edytował Turson 18.07.2014, 11:49:40
Go to the top of the page
+Quote Post
l3szcz
post
Post #5





Grupa: Zarejestrowani
Postów: 16
Pomógł: 0
Dołączył: 19.08.2012

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


Widok ma rozszerzenie .phtml, plik index.phtml dokładnie.
Plik php trzymam w public, przed application, kontroler to:
  1. <?php
  2. class UserController extends Zend_Controller_Action
  3. {
  4. public function indexAction()
  5. {
  6.  
  7. $this->view->assign('name', 'Panel klienta');
  8.  
  9. $this->view->assign('title', 'Panel klienta');
  10.  
  11. }
  12. }
  13. ?>

Zawartość pliku user.php
  1. <?php
  2.  
  3. $view = new Zend_View();
  4.  
  5. $view->setScriptPath(getcwd() . '/views/scripts/user/');
  6.  
  7. $message = $view->render('index.phtml');
  8.  
  9. ?>


Nie wiem co zaincludować tongue.gif
Go to the top of the page
+Quote Post
Turson
post
Post #6





Grupa: Zarejestrowani
Postów: 4 291
Pomógł: 829
Dołączył: 14.02.2009
Skąd: łódź

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


W ogóle to o jakiej wersji Zenda mowa?

application/controllers/UserController.php
  1. <?php
  2. class UserController extends Zend_Controller_Action
  3. {
  4. public function indexAction()
  5. {
  6.  
  7. }
  8. }


application/views/scripts/user/index.phtml
  1. hello world


taka powinna być struktura

Masz kontroler Users więc katalog user w scripts, a akcja to index, więc index.phtml jako widok, a adres strona.domena/users

Ten post edytował Turson 18.07.2014, 17:09:05
Go to the top of the page
+Quote Post
l3szcz
post
Post #7





Grupa: Zarejestrowani
Postów: 16
Pomógł: 0
Dołączył: 19.08.2012

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


1.12
Go to the top of the page
+Quote Post
Turson
post
Post #8





Grupa: Zarejestrowani
Postów: 4 291
Pomógł: 829
Dołączył: 14.02.2009
Skąd: łódź

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


Mój poprzedni post odnosi się do tej wersji.
Go to the top of the page
+Quote Post
l3szcz
post
Post #9





Grupa: Zarejestrowani
Postów: 16
Pomógł: 0
Dołączył: 19.08.2012

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


Dobra, zadziałało pod adresem http://adres.pl/users/
ale jak chcę wykonać akcję, np. auth - wyskakuje bład z error controllerem:
Call to a member function hasResource() on a non-object in

Szukałem w necie rozwiązania, jednakże znaleźć nie mogłem.
Go to the top of the page
+Quote Post
Turson
post
Post #10





Grupa: Zarejestrowani
Postów: 4 291
Pomógł: 829
Dołączył: 14.02.2009
Skąd: łódź

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


Jak masz akcję auth, to mego authAction() w kontrolerze i adres www.adres.pl/users/auth
Oczywiście jeszcze w scripts/user/ ma być widok auth.phtml
Go to the top of the page
+Quote Post
l3szcz
post
Post #11





Grupa: Zarejestrowani
Postów: 16
Pomógł: 0
Dołączył: 19.08.2012

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


Controller auth:
  1. public function authAction()
  2.  
  3. {
  4.  
  5. $request = $this->getRequest();
  6.  
  7. $registry = Zend_Registry::getInstance();
  8.  
  9. $auth = Zend_Auth::getInstance();
  10.  
  11. $DB = Zend_Registry::get("DB");
  12.  
  13. $authAdapter = new Zend_Auth_Adapter_DbTable($DB);
  14.  
  15. $authAdapter->setTableName('users')
  16.  
  17. ->setIdentityColumn('email')
  18.  
  19. ->setCredentialColumn('password');
  20.  
  21. $email = $request->getParam('email');
  22.  
  23. $password = $request->getParam('password');
  24.  
  25. $hash = md5('placki'.sha1($password).'dobreJoinnty124');
  26.  
  27. $authAdapter->setIdentity($email);
  28.  
  29. $authAdapter->setCredential($hash);
  30.  
  31. $result = $auth->authenticate($authAdapter);
  32.  
  33. if($result->isValid()){
  34.  
  35. //print_r($result);
  36.  
  37. $data = $authAdapter->getResultRowObject(null,'password');
  38.  
  39. $auth->getStorage()->write($data);
  40.  
  41. $this->_redirect('/users');
  42.  
  43. } else {
  44.  
  45. $this->_redirect('/users/login');
  46.  
  47. }
  48.  
  49. }


Jestem w dupie, kuźwa :/

Refresh :/
Go to the top of the page
+Quote Post
Turson
post
Post #12





Grupa: Zarejestrowani
Postów: 4 291
Pomógł: 829
Dołączył: 14.02.2009
Skąd: łódź

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


ALe jaki jest problem
Go to the top of the page
+Quote Post

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

 



RSS Aktualny czas: 21.08.2025 - 09:08