Witaj Gościu! ( Zaloguj | Rejestruj )

Forum PHP.pl

> Jak sprawdzić, czy da się wykonać funkcję wewnątrz klasy
Asmox
post 22.06.2009, 14:21:55
Post #1





Grupa: Zarejestrowani
Postów: 359
Pomógł: 12
Dołączył: 16.01.2009

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


Robię sobie kontroler dla mojej strony, nie wiem czy dobrze, ale wygląda on tak:
  1. <?php
  2. class FrontController
  3. {
  4.  private $requests = array();
  5.  private $action;
  6.  private $action_parameters = array();
  7.  
  8.  private function __construct() {
  9.    GLOBAL $_GET;
  10.    GLOBAL $_POST;
  11.    $this->requests['get'] = $_GET;
  12.    $this->requests['post'] = $_POST;
  13.    $this->action = $this->requests['get']['ac'];
  14.    foreach($this->requests['get'] as $key => $val) {
  15.      if($key == "ac") continue;
  16.      $action_parameters[$key] = $val;
  17.    }
  18.  }
  19.  
  20.  static function GetInstance() {
  21.    static $controller;
  22.    
  23.    if(!isset($controller)) {
  24.      $controller = new FrontController();
  25.    }
  26.    return $controller;
  27.  }
  28.  
  29.  public function Dispatch() {
  30.    $funcName = '$this' . 'Action' . $this->action;
  31.    echo $funcName;
  32.    if(is_callable(array("$this", "Action{$this->action}")))
  33.    echo 'ok';
  34.  }
  35.  
  36.  public function Action00() {
  37.    echo "in action 00";
  38.  }
  39. }
  40. ?>

Nie wiem tylko jak sprawdzić, czy funkcję Action00 da się wykonać (patrz przedostatnia linijka funkcji Dispatch)


--------------------
Go to the top of the page
+Quote Post

Posty w temacie


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 Wersja Lo-Fi Aktualny czas: 19.07.2025 - 08:41