Skip to content

Instantly share code, notes, and snippets.

@m4rcsch
Created December 11, 2011 10:51
Show Gist options
  • Save m4rcsch/1459916 to your computer and use it in GitHub Desktop.
Save m4rcsch/1459916 to your computer and use it in GitHub Desktop.

Revisions

  1. m4rcsch revised this gist Dec 11, 2011. 1 changed file with 14 additions and 1 deletion.
    15 changes: 14 additions & 1 deletion custom_save.php
    Original file line number Diff line number Diff line change
    @@ -1,6 +1,17 @@
    <?php

    // ATTENTION: this is pseudocode alike!
    // witten inside the gist textbox without php validation!

    /**
    * This is a models vutsom save method
    * The models validation rules should contain at least one 'on' => 'publish' rule!
    *
    * @param Object $entity
    * @param mixed $data
    * @param array $options
    * @return booolean
    */
    public function publish($entity, $data = null, array $options = array()) {
    $default_data = array(
    'published' = 'true'
    @@ -17,4 +28,6 @@ public function publish($entity, $data = null, array $options = array()) {
    */
    $valid = $this->validates($entity,$data,$options);
    return (!$valid)?:$this->save($entity,$data,$options);
    }
    }

    ?>
  2. m4rcsch created this gist Dec 11, 2011.
    20 changes: 20 additions & 0 deletions custom_save.php
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,20 @@
    // ATTENTION: this is pseudocode alike!
    // witten inside the gist textbox without php validation!

    public function publish($entity, $data = null, array $options = array()) {
    $default_data = array(
    'published' = 'true'
    )
    $default_options = array(
    'events' = 'publish'
    )

    $options += $default_options;
    $data += $default_data;

    /**
    * Validation would be obsolte, if saving does know about the 'event'
    */
    $valid = $this->validates($entity,$data,$options);
    return (!$valid)?:$this->save($entity,$data,$options);
    }