コード例 #1
0
ファイル: ak_url_helper.php プロジェクト: bermi/akelos
 /**
  * Returns the URL for the set of +$options+ provided. This takes the same options 
  * as url_for. For a list, see the documentation for AKActionController::urlFor.
  * Note that it'll set ('only_path' => true) so you'll get /controller/action instead of the 
  * http://example.com/controller/action part (makes it harder to parse httpd log files)
  */
 public function url_for($options = array(), $parameters_for_method_reference = null)
 {
     if ($options instanceof AkBaseModel) {
         $options = AkRouterHelper::getUrlParamsForModel($options);
     }
     $default_options = array('only_path' => true);
     $options = array_merge($default_options, $options);
     return $this->_controller->urlFor($options, $parameters_for_method_reference);
 }
コード例 #2
0
ファイル: action_controller.php プロジェクト: bermi/akelos
 /**
  * Redirects the browser to the target specified in +options+. This parameter can take one of three forms:
  *
  * * <tt>Array</tt>: The URL will be generated by calling $this->urlFor with the +options+.
  * * <tt>String starting with protocol:// (like http://)</tt>: Is passed straight through
  * as the target for redirection.
  * * <tt>String not containing a protocol</tt>: The current protocol and host is prepended to the string.
  * * <tt>back</tt>: Back to the page that issued the Request-> Useful for forms that are
  * triggered from multiple places.
  *   Short-hand for redirectTo(Request->env["HTTP_REFERER"])
  *
  * Examples:
  *   redirectTo(array('action' => 'show', 'id' => 5));
  *   redirectTo('http://www.bermilabs.com');
  *   redirectTo('/images/screenshot.jpg');
  *   redirectTo('back');
  *
  * The redirection happens as a "302 Moved" header.
  */
 public function redirectTo($options = array(), $parameters_for_method_reference = null)
 {
     if ($options instanceof AkBaseModel) {
         $options = AkRouterHelper::getUrlParamsForModel($options);
     }
     $this->_handleFlashAttribute($parameters_for_method_reference);
     $this->_closeSession();
     if (is_string($options)) {
         if (preg_match('/^\\w+:\\/\\/.*/', $options)) {
             if ($this->hasPerformed()) {
                 $this->_doubleRenderError();
             }
             AK_LOG_EVENTS && !empty($this->_Logger) ? $this->_Logger->message('Redirected to ' . $options) : null;
             $this->Response->redirect($options);
             $this->Response->redirected_to = $options;
             $this->performed_redirect = true;
         } elseif ($options == 'back') {
             $this->redirectTo($this->Request->getReferer());
         } else {
             $this->redirectTo($this->Request->getProtocol() . $this->Request->getHostWithPort() . $options);
         }
     } else {
         if (empty($parameters_for_method_reference)) {
             $this->redirectTo($this->urlFor($options));
             $this->Response->redirected_to = $options;
         } else {
             $this->redirectTo($this->urlFor($options, $parameters_for_method_reference));
             $this->Response->redirected_to = $options;
             $this->Response->redirected_to_method_params = $parameters_for_method_reference;
         }
     }
 }
コード例 #3
0
ファイル: ak_form_helper.php プロジェクト: bermi/akelos
 /**
  *
  * Creates a form and a scope around a specific model object, which is then used as a base for questioning about
  * values for the fields. Examples:
  *
  *   <?php $f = $form_helper->form_for('person', $Person, array('url' => array('action' => 'update'))); ?>
  *     First name: <?= $f->text_field('first_name'); ?>
  *     Last name : <?= $f->text_field('last_name'); ?>
  *     Biography : <?= $f->text_area('biography'); ?>
  *     Admin?    : <?= $f->check_box('admin'); ?>
  *   <?= $f->end_form_tag(); ?>
  *
  * The form_for yields a form_builder object, in this example as $f, which emulates the API for the stand-alone
  * FormHelper methods, but without the object name. So instead of <tt>$form_helper->text_field('person', 'name');</tt>,
  * you get away with <tt>$f->text_field('name');</tt>.
  *
  * That in itself is a modest increase in comfort. The big news is that form_for allows us to more easily escape the instance
  * variable convention, so while the stand-alone approach would require <tt>$form_helper->text_field('person', 'name', array('object' => $Person));</tt>
  * to work with local variables instead of instance ones, the form_for calls remain the same. You simply declare once with
  * <tt>'person', $Person</tt> and all subsequent field calls save <tt>'person'</tt> and <tt>'object' => $Person</tt>.
  *
  * Also note that form_for doesn't create an exclusive scope. It's still possible to use both the stand-alone FormHelper methods
  * and methods from FormTagHelper. Example:
  *
  *   <?php $f = $form_helper->form_for('person', $Person, array('url' => array('action' => 'update'))); ?>
  *     First name: <?= $f->text_field('first_name'); ?>
  *     Last name : <?= $f->text_field('last_name'); ?>
  *     Biography : <?= $f->text_area('person', $Biography); ?>
  *     Admin?    : <?= $form_helper->check_box_tag('person[admin]', $Person->company->isAdmin()); ?>
  *   <?= $f->end_form_tag(); ?>
  *
  * Note: This also works for the methods in FormOptionHelper and DateHelper that are designed to work with an object as base.
  * Like collection_select and datetime_select.
  */
 public function form_for($object_name, &$object = null, $options = array())
 {
     $this->object_name = $object_name;
     if (empty($object)) {
         $object = $this->_controller->{$object_name};
     }
     if (!$object instanceof AkBaseModel) {
         throw new Exception('$object is of type ' . gettype($object) . '. Expected instance of AkBaseModel.');
     }
     if (empty($options['url'])) {
         $options['url'] = AkRouterHelper::getUrlParamsForModel($object);
     }
     $url_for_options = $options['url'];
     $_SESSION['_csrf_token'] = sha1(Ak::uuid() . AK_REMOTE_IP . time());
     echo $this->_controller->ak_form_tag_helper->form_tag($url_for_options, $options);
     echo '<div style="margin:0;padding:0;display:inline"><input name="authenticity_token" type="hidden" value="' . $_SESSION['_csrf_token'] . '" /></div>';
     if (!$object->isNewRecord()) {
         echo '<div style="margin:0;padding:0;display:inline"><input name="_method" type="hidden" value="put" /></div>';
     }
     return $this->fields_for($object_name, $object);
 }