Packages

  • Nette
    • Application
      • Diagnostics
      • Responses
      • Routers
      • UI
    • Caching
      • Storages
    • ComponentModel
    • Config
      • Adapters
      • Extensions
    • Database
      • Diagnostics
      • Drivers
      • Reflection
      • Table
    • DI
      • Diagnostics
    • Diagnostics
    • Forms
      • Controls
      • Rendering
    • Http
    • Iterators
    • Latte
      • Macros
    • Loaders
    • Localization
    • Mail
    • Reflection
    • Security
      • Diagnostics
    • Templating
    • Utils
      • PhpGenerator
  • NetteModule
  • None
  • PHP

Classes

  • AppForm
  • Control
  • Multiplier
  • Presenter
  • PresenterComponent

Interfaces

  • IRenderable
  • ISignalReceiver
  • IStatePersistent

Exceptions

  • BadSignalException
  • InvalidLinkException
  • Overview
  • Package
  • Class
  • Tree
  • Deprecated
  1: <?php
  2: 
  3: /**
  4:  * This file is part of the Nette Framework (http://nette.org)
  5:  *
  6:  * Copyright (c) 2004 David Grudl (http://davidgrudl.com)
  7:  *
  8:  * For the full copyright and license information, please view
  9:  * the file license.txt that was distributed with this source code.
 10:  * @package Nette\Application\UI
 11:  */
 12: 
 13: 
 14: 
 15: /**
 16:  * Web form adapted for Presenter.
 17:  *
 18:  * @author     David Grudl
 19:  *
 20:  * @property-read Presenter $presenter
 21:  * @package Nette\Application\UI
 22:  */
 23: class AppForm extends Form implements ISignalReceiver
 24: {
 25: 
 26:     /**
 27:      * Application form constructor.
 28:      */
 29:     public function __construct(IComponentContainer $parent = NULL, $name = NULL)
 30:     {
 31:         parent::__construct();
 32:         $this->monitor('Presenter');
 33:         if ($parent !== NULL) {
 34:             $parent->addComponent($this, $name);
 35:         }
 36:     }
 37: 
 38: 
 39: 
 40:     /**
 41:      * Returns the presenter where this component belongs to.
 42:      * @param  bool   throw exception if presenter doesn't exist?
 43:      * @return Presenter|NULL
 44:      */
 45:     public function getPresenter($need = TRUE)
 46:     {
 47:         return $this->lookup('Presenter', $need);
 48:     }
 49: 
 50: 
 51: 
 52:     /**
 53:      * This method will be called when the component (or component's parent)
 54:      * becomes attached to a monitored object. Do not call this method yourself.
 55:      * @param  IComponent
 56:      * @return void
 57:      */
 58:     protected function attached($presenter)
 59:     {
 60:         if ($presenter instanceof Presenter) {
 61:             $name = $this->lookupPath('Presenter');
 62: 
 63:             if (!isset($this->getElementPrototype()->id)) {
 64:                 $this->getElementPrototype()->id = 'frm-' . $name;
 65:             }
 66: 
 67:             $this->setAction(new Link(
 68:                 $presenter,
 69:                 $name . self::NAME_SEPARATOR . 'submit!',
 70:                 array()
 71:             ));
 72: 
 73:             // fill-in the form with HTTP data
 74:             if ($this->isSubmitted()) {
 75:                 foreach ($this->getControls() as $control) {
 76:                     if (!$control->isDisabled()) {
 77:                         $control->loadHttpData();
 78:                     }
 79:                 }
 80:             }
 81:         }
 82:         parent::attached($presenter);
 83:     }
 84: 
 85: 
 86: 
 87:     /**
 88:      * Tells if the form is anchored.
 89:      * @return bool
 90:      */
 91:     public function isAnchored()
 92:     {
 93:         return (bool) $this->getPresenter(FALSE);
 94:     }
 95: 
 96: 
 97: 
 98:     /**
 99:      * Internal: receives submitted HTTP data.
100:      * @return array
101:      */
102:     protected function receiveHttpData()
103:     {
104:         $presenter = $this->getPresenter();
105:         if (!$presenter->isSignalReceiver($this, 'submit')) {
106:             return;
107:         }
108: 
109:         $isPost = $this->getMethod() === self::POST;
110:         $request = $presenter->getRequest();
111:         if ($request->isMethod('forward') || $request->isMethod('post') !== $isPost) {
112:             return;
113:         }
114: 
115:         if ($isPost) {
116:             return Arrays::mergeTree($request->getPost(), $request->getFiles());
117:         } else {
118:             return $request->getParameters();
119:         }
120:     }
121: 
122: 
123: 
124:     /********************* interface ISignalReceiver ****************d*g**/
125: 
126: 
127: 
128:     /**
129:      * This method is called by presenter.
130:      * @param  string
131:      * @return void
132:      */
133:     public function signalReceived($signal)
134:     {
135:         if ($signal === 'submit') {
136:             if (!$this->getPresenter()->getRequest()->hasFlag(PresenterRequest::RESTORED)) {
137:                 $this->fireEvents();
138:             }
139:         } else {
140:             $class = get_class($this);
141:             throw new BadSignalException("Missing handler for signal '$signal' in $class.");
142:         }
143:     }
144: 
145: }
146: 
Nette Framework 2.0.8 (for PHP 5.2, un-prefixed) API API documentation generated by ApiGen 2.8.0