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:
<?php
class Controller{
protected $model;
protected $action;
protected $requestParams;
protected function __construct(){
$this->requestParams=$_GET;
}
public function doAction(){
$method=$this->requestParams['action'];
$this->defaultMethod();
}
else if(method_exists($this,$method)){
call_user_func
(array(&$this,$method)); }
else{
$this->nonExistingMethod($method);
}
}
public function defaultMethod(){
echo'This is default action.'; }
public function nonExistingMethod($method){
echo"Sorry, that method $method does not exist"; }
}
?>
klasa potomna:
<?php
require'controller.php';
require'./models/pagesModel.php';
require'Smarty-2.6.18/libs/Smarty.class.php';
class PagesController extends Controller{
public $view;
public $leftContent;
public $mainContent;
public function __construct(){
parent::__construct();
$this->model=new PagesModel();
$this->view=new Smarty();
$this->doAction();
$this->leftContent=null;
$this->mainContent=null;
$this->requestParams['id']=null;
}
public function defaultAction(){
$this->index();
}
/*
public function setMainContent(){
$id=$_GET['id'];
if(!isset($id)){
$this->mainContent=$this->model->getDefaultMainContent();
}
else{
$this->mainContent=$this->model->mainContent;
}
}
*/
public function assignData($id){
$id=$this->requestParams['id'];
}
else{
echo" id jest rowne $id"; //do testow }
}
public function index(){
$this->view->assign('content','index.tpl');
$this->view->display('main.tpl');
$this->assignData($id);
}
?>
index.php:
<?php
require'controllers/pagesController.php';
$c=new PagesController();
?>