PHP code example of footup / framework

1. Go to this page and download the library: Download footup/framework library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

footup / framework example snippets


// using get function to get the page=3 present in the url
$this->request->get("page");

// you can use like this to get the page
$this->request->page;

// What ? you typing enough ? and that ?
request()->page;

// And What ? how to get file with name: image ?
// You can use as below
$this->request->image; // or $this->request->file('image')

// And What if image[] as multiple files ?
// You can use as below
$this->request->files('image');

# Yes you can access the request using the global function request()

// using get function to validate the page=3 present in the url
$this->request->withGetInput()->validate(["page" => "is:int"]);

// What ? you typing enough ? and that ?
request()->withGetInput()->validate(["page" => "is:int"]);

# Yes you can access the request using the global function request()

// using get function to validate the page=3 present in the url
$this->response->json(["page" => 2]); // second parameter to echo directly

# Yes you can access the response using the global function response()

// using set function to set session value
$this->session->set(["page" => 2]); // or $this->session->page = 2

// What ? you typing enough ? and that ?
session("page", 2); // session()->set("page", 2); or session()->page = 2;

// What ? i want to get the page ?
// So
session("page"); // session()->get("page"); or session()->page;

# Yes you can access the session using the global function session() as shown

// Via request
// with post data
$this->request->withPostInput()->validate(["page" => "is:int"]);

// With post and get data
request()->withInput()->validate(["page" => "is:int"]);

// With other data
request()->with(["page" => 2])->validate(["page" => "is:int"]);

// So how to get Error ?
// Simple
validator()->getError("page"); // request()->getValidator()->getErrors(); to grab all

# Yes you can access the validator using the global function validator()
# You can validate using the global function validate() too



namespace App\Model;
use Footup\Model;

class Contact extends Model{
  // If not defined, the name of this class is used
  protected $table = 'contact';
  /**
   * PrimaryKey
   *
   * @var string
   */
  protected $primaryKey = 'idcont';

  protected $beforeInsert         = [];
  protected $beforeFind           = [];
  protected $beforeDelete         = [];
  protected $beforeUpdate         = [];
  protected $afterInsert          = [];
  protected $afterFind            = [];
  protected $afterDelete          = [];
  protected $afterUpdate          = [];
}

// Using the model Contact
.....
  use App\Model\Contact;
  ....
  // Retrouve tout | retrieve all
  $contacts = Contact::all();
  ------------ others methods --------------
  $c = new Contact();
  $contacts = $c->get();
  foreach($contacts as $contact)
    echo $contact->email;
  
  # you can also use 
  $contact->setEmail("[email protected]");

  // Generating form ******
  $contact->getForm();

  var_dump($c->firstByEmail('[email protected]'));
  ..........................
  

  /**
   * Une fonction pour exposer l'objet Request
   *
   * @param mixed $index
   * @param mixed $arg
   * @return Footup\Http\Request|mixed
   */
  request($index = null, $arg = null)

  /**
   * Retrouve le controlleur en cours d'utilisation
   *
   * @param boolean $withNamespace
   * @return string
   */
  calledController($withNamespace = true)

  /**
   * Retrouve la méthode couremment utilisée
   *
   * method of the current called controller
   * 
   * @return string
   */
  calledMethod()

  #eg. file field = image
  # @uses one below
  request('image') or request()->image or request()->file('image')

  # remember that request is available directly in the controller so :
  $this->request->image

  # et pour enregistrer le fichier | and for saving :
  request('image')->save(?string $destinationName = null, bool $replace = true) or request()->image->save(?string $destinationName = null, bool $replace = true) or request()->file('image')->save(?string $destinationName = null, bool $replace = true)

  # remember that request is available directly in the controller so :
  $this->request->image

  $contact = new ContactModel();
  $contact->getForm("#", [], true /* true to print */ )
  # or use
  echo $contact->getForm();

    /**
      * @param string|array $key
      * @param null $operator
      * @param null $val
      * @return $this
      */
    public function whereOr($key, $val = null, $operator = null, $escape = true)
  

    /**
     * @param $key
     * @param array $val
     * @return $this
     */
    public function whereIn($key, array $val, $escape = true)
  

    /**
     * @param string $str
     * @return $this
     */
    public function whereRaw($str)
  

    /**
     * @param $key
     * @param array $val
     * @return $this
     */
    public function whereNotIn($key, array $val, $escape = true)
  

    /**
     * @param string $key
     * @return $this
     */
    public function whereNotNull($key)
  

    /**
     * @param string $key
     * @return $this
     */
    public function whereNull($key)
  

    /**
     * Adds an ascending sort for a field.
     *
     * @param string $field Field name
     * @return object Self reference
     */
    public function asc($field)
  

    /**
     * Adds an descending sort for a field.
     *
     * @param string $field Field name
     * @return object Self reference
     */
    public function desc($field)
  

    /**
     * Adds fields to order by.
     *
     * @param string $field Field name
     * @param string $direction Sort direction
     * @return object Self reference
     */
    public function orderBy($field, $direction = 'ASC')
  

    /**
     * Builds an insert query.
     *
     * @param array $data Array of key and values to insert
     * @return bool
     */
    public function insert(array $data = [])
  

    /**
     * Builds an update query.
     *
     * @param array $data Array of keys and values, or string literal
     * @return bool
     */
    public function update($data)
  

    /**
     * Builds a delete query.
     *
     * @param string|int|array $where Where conditions
     * @return bool
     */
    public function delete($where = null)
  

    /**
     * Gets or sets the SQL statement.
     *
     * @param string|array SQL statement
     * @return self|string SQL statement
     */
    public function sql($sql = null)
  

    /**
     * Saves an object to the database.
     *
     * @param object $objet Class instance
     * @param array $db_fields Select database fields to save (insert or update)
     * @return boolean
     */
    public function save($objet = null, array $db_fields = null)
  

    /**
     * Removes an object from the database.
     *
     * @param object
     * @return boolean
     */
    public function remove($objet = null)
  


/**
 * Gets the database connection instance PDO.
 *
 * @return object Database connection
 */
public function getDb()

  /**
   * Executes a sql statement.
   *
   * @return object Query results object
   * @throws Exception When database is not defined
   */
  public function execute(array $params = [])

  /**
   * Perform a query
   *
   * @param string $select
   * @param array|string $where
   * @param int $limit
   * @param int $offset
   * @return array - of object class
   */
  public function get($select = "*", $where = null, $limit = null, $offset = null)

  # Autres Méthodes
  ==================

  /**
   * Get the table name for this ER class.
   * 
   * @access public
   * @return string
   */
  getTable ()

  /**
   * Get the primaryKey
   * 
   * @access public
   * @return string
   */ 
  getPrimaryKey()

  /**
   * Get model property fields by data table.
   *
   * @access public
   * @return array of available columns
   */
  getFields()

  /**
   * Create new data row.
   *
   * @access public
   * @param array $properties
   * @return object Model instance
   * @return bool
   */
  create(Array $properties)

  /**
   * Find one model in the database.
   * or create if not exists.
   *
   * @access public
   * @param array $properties
   * @return object Model instance
   * @return array|bool if error occured
   */
  findOrCreate(Array $properties = null)

  /**
   * Find all model in the database.
   *
   * @access public
   * @param mixed $where
   * @return array|object
   */
  public static function all($where = null)



namespace App\Controller;
use App\Model\Contact;

class Home extends BaseController{

  public function index(){
    // Retrouve la méthod utilisée | HTTP Verb
    if($this->request->method() === 'post'){

      // retrouve un fichier | retrouve uploaded file
      $image = $this->request->file('image');
      // save
      $image->save();
      // get the name of the moved file 
      echo $image->name;
    }

    // Using model Contact
    // all() est la seule méthode statique | all() is the only static method
    $contacts = Contact::all();
    $contacts = (new Contact())->get());
    
    // Afficher la vue | display the vue
    return $this->view("accueil", [
        "titre" => "Accueil"
    ]);
  }

}
  
bash
nuka@hacker_pc:~$ php footup 
bash
nuka@hacker_pc:~$ php footup controller controllerName