Subversion Repositories PHPX

Rev

Rev 30 | Rev 51 | Go to most recent revision | Show entire file | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 30 Rev 43
Line 30... Line 30...
30
  /**
30
  /**
31
   * Default action of the controller
31
   * Default action of the controller
32
   * @var string
32
   * @var string
33
   */
33
   */
34
  protected $_defaultAction = 'index';
34
  protected $_defaultAction = 'index';
35
 
35
36
  /**
36
  /**
37
   * If an array, maps an action name to an action method of the controller.
37
   * If an array, maps an action name to an action method of the controller.
38
   *
38
   *
39
   * Fallback for IE 7 where the content of a <code>button</code> element
39
   * Fallback for IE 7 where the content of a <code>button</code> element
40
   * is submitted as value.
40
   * is submitted as value.
41
   *
41
   *
42
   * @var array
42
   * @var array
43
   */
43
   */
44
  protected $_actionMap = null;
44
  protected $_actionMap = null;
45
 
45
46
  /**
46
  /**
47
   * The {@link View} used by this controller
47
   * The {@link View} used by this controller
48
   * @var View
48
   * @var View
49
   */
49
   */
50
  protected $_view = null;
50
  protected $_view = null;
51
 
51
52
  /**
52
  /**
53
   * Constructs a controller, initializes the related view,
53
   * Constructs a controller, initializes the related view,
54
   * and calls the controller's URI-indicated action method.
54
   * and calls the controller's URI-indicated action method.
55
   *
55
   *
56
   * @param string $viewClass
56
   * @param string $viewClass
57
   *   View class.  The default is <code>'View'</code>.
57
   *   View class.  The default is <code>'View'</code>.
58
   * @param string $template
58
   * @param string $template
59
   *   Resource path of the template for the view.  The default
59
   *   Resource path of the template for the view.  The default
-
 
60
   *   is to <code>null</code> (no template).
-
 
61
   *
60
   *   is the empty string.
62
   * @see View::__construct()
61
   */
63
   */
62
  protected function __construct($viewClass = 'View', $template = null)
64
  protected function __construct($viewClass = 'View', $template = null)
63
  {
65
  {
64
    $this->_view = new $viewClass($template);
66
    $this->_view = new $viewClass($template);
65
67
66
    Application::getInstance()->setCurrentController($this);
68
    Application::getInstance()->setCurrentController($this);
67
   
69
68
    $action = Application::getParam('action', $_REQUEST);
70
    $action = Application::getParam('action', $_REQUEST);
69
   
71
70
    /* NOTE: No `==='; treat empty action like no specific action */
72
    /* NOTE: No `==='; treat empty action like no specific action */
71
    if ($action == null)
73
    if ($action == null)
72
    {
74
    {
73
      $action = $this->_defaultAction;
75
      $action = $this->_defaultAction;
74
    }
76
    }
75
77
76
    $actionMethod = lcfirst($action) . 'Action';
78
    $actionMethod = lcfirst($action) . 'Action';
77
   
79
78
    /* Fallback for IE 7 where the content of a `button' element is submitted as value */
80
    /* Fallback for IE 7 where the content of a `button' element is submitted as value */
79
    if (!method_exists($this, $actionMethod))
81
    if (!method_exists($this, $actionMethod))
80
    {
82
    {
81
      if (is_array($this->_actionMap) && array_key_exists($action, $this->_actionMap))
83
      if (is_array($this->_actionMap) && array_key_exists($action, $this->_actionMap))
82
      {
84
      {
83
        $actionMethod = $this->_actionMap[$action];
85
        $actionMethod = $this->_actionMap[$action];
84
      }
86
      }
85
    }
87
    }
86
   
88
87
    $this->$actionMethod();
89
    $this->$actionMethod();
88
  }
90
  }
89
   
91
90
  /**
92
  /**
91
   * Assigns a value to a template variable (after this,
93
   * Assigns a value to a template variable (after this,
92
   * <var>$value</var> is available through
94
   * <var>$value</var> is available through
93
   * <code>$this-><var>$name</var></code> in the view's template).
95
   * <code>$this-><var>$name</var></code> in the view's template).
94
   * <code>Controller</code>s should call this method instead of
96
   * <code>Controller</code>s should call this method instead of
Line 107... Line 109...
107
   */
109
   */
108
  protected function assign($name, $value, $encodeHTML = false)
110
  protected function assign($name, $value, $encodeHTML = false)
109
  {
111
  {
110
    return $this->_view->assign($name, $value, $encodeHTML);
112
    return $this->_view->assign($name, $value, $encodeHTML);
111
  }
113
  }
112
 
114
113
  /**
115
  /**
114
   * Renders the {@link View} associated with this controller
116
   * Renders the {@link View} associated with this controller
115
   * by including the <code>View</code>'s template.
117
   * by including the <code>View</code>'s template.
116
   * <code>Controller</code>s should call this method instead of
118
   * <code>Controller</code>s should call this method instead of
117
   * <code>View::render()</code>.
119
   * <code>View::render()</code>.