Witaj Gościu! ( Zaloguj | Rejestruj )

Forum PHP.pl

 
Reply to this topicStart new topic
> [php/mvc]problem z dziedziczeniem w klasach
MadHatter
post
Post #1





Grupa: Zarejestrowani
Postów: 20
Pomógł: 1
Dołączył: 15.02.2007

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


Witam,

Mam jakis banalny problem. Dwie kalsy kontrolera, jedna maciezysta, druga dziedziczaca po niej, do samej obslugi stron. Chcialbym zby wywolanie ze strony indexowej(kod ponizej) wywolywalo funkcje defaultMethod() klasy potomnej. narazie niestety wywoluje tylko ta metode ale klasy bazowej. Blad jest chyba banalny i gdzies popelniam karygony bad w podejsciu do OOP, niemniej prosze o pomoc i wyrozumialosc:

klasa bazowa:
  1. <?php
  2. class Controller{
  3. protected $model;
  4. protected $action;
  5. protected $requestParams;
  6. protected function __construct(){
  7. $this->requestParams=$_GET;
  8. }
  9. public function doAction(){
  10. $method=$this->requestParams['action'];
  11. if(empty($method)){
  12. $this->defaultMethod();
  13. }
  14. else if(method_exists($this,$method)){
  15. call_user_func(array(&$this,$method));
  16. }
  17. else{
  18. $this->nonExistingMethod($method);
  19. }
  20. }
  21. public function defaultMethod(){
  22. echo'This is default action.';
  23. }
  24. public function nonExistingMethod($method){
  25. echo"Sorry, that method $method does not exist";
  26. }
  27. }
  28. ?>


klasa potomna:

  1. <?php
  2. require'controller.php';
  3. require'./models/pagesModel.php';
  4. require'Smarty-2.6.18/libs/Smarty.class.php';
  5. class PagesController extends Controller{
  6. public $view;
  7. public $leftContent;
  8. public $mainContent;
  9. public function __construct(){
  10. parent::__construct();
  11. $this->model=new PagesModel();
  12. $this->view=new Smarty();
  13. $this->doAction();
  14. $this->leftContent=null;
  15. $this->mainContent=null;
  16. $this->requestParams['id']=null;
  17. }
  18. public function defaultAction(){
  19. $this->index();
  20. }
  21. /*
  22. public function setMainContent(){
  23. $id=$_GET['id'];
  24. if(!isset($id)){
  25. $this->mainContent=$this->model->getDefaultMainContent();
  26. }
  27. else{
  28. $this->mainContent=$this->model->mainContent;
  29. }
  30. }
  31.  */
  32. public function assignData($id){
  33. $id=$this->requestParams['id'];
  34. if(empty($id)||!isset($id)){
  35. }
  36. else{
  37. echo" id jest rowne $id"; //do testow
  38. }
  39. }
  40. public function index(){
  41. $this->view->assign('content','index.tpl');
  42. $this->view->display('main.tpl');
  43. $this->assignData($id);
  44. }
  45. ?>


index.php:

  1. <?php
  2. require'controllers/pagesController.php';
  3. $c=new PagesController();
  4. ?>
Go to the top of the page
+Quote Post
thornag
post
Post #2





Grupa: Zarejestrowani
Postów: 504
Pomógł: 2
Dołączył: 31.03.2006
Skąd: Londyn

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


Metoda defaultMethod nie jest przeciazana w klasie potomnej co oznacza ze jest dziedziczona w takiej samej postaci.

Widze ze w jednej klasie masz defaultAction w drugiej defaultMethod, moze po prostu literowka ?

re down: Pierwszy tongue.gif

Ten post edytował thornag 24.07.2007, 10:20:32


--------------------
"Wizja czasu jest szeroka, lecz kiedy sie przez nia przechodzi, czas staje sie waskimi drzwiami"

Go to the top of the page
+Quote Post
Ziels
post
Post #3





Grupa: Zarejestrowani
Postów: 235
Pomógł: 2
Dołączył: 30.06.2006

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


Bo jak ma wywołać metodęklasy potomnej skoro ta nie jest nadpisywana? smile.gif
Go to the top of the page
+Quote Post
MadHatter
post
Post #4





Grupa: Zarejestrowani
Postów: 20
Pomógł: 1
Dołączył: 15.02.2007

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


Cytat(thornag @ 24.07.2007, 11:17:34 ) *
Widze ze w jednej klasie masz defaultAction w drugiej defaultMethod, moze po prostu literowka ?


Witaj,

Dzieki, no wlasnie to byl ten kretynski blad... Juz wszystko OK.

Jeszcze raz dziekuje!
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: 20.08.2025 - 08:48