PHP code example of auntiewarhol / mvcish

1. Go to this page and download the library: Download auntiewarhol/mvcish 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/ */

    

auntiewarhol / mvcish example snippets



  use \AuntieWarhol\MVCish\MVCish;


  # outside scope of MVCish but we recommend using this with csrf-magic
  # which can be used with beforeRender as shown below, so here's 
  # some setup for that, otherwise unrelated to MVCish

  if (php_sapi_name() != "cli") {

    // instruct PHP to use secure cookie if possible
    // honestly don't remember if for MVCish of csrf or why,
    // but leaving here for now at least...
    $secure = ((!empty($_SERVER['HTTPS'])) && $_SERVER['HTTPS'] !== 'off') ||
        (isset($_SERVER['SERVER_PORT']) && ($_SERVER['SERVER_PORT'] == 443)) ||
	    (isset($_SERVER['HTTP_X_FORWARDED_PROTO']) && $_SERVER['HTTP_X_FORWARDED_PROTO'] == 'https')
	  ? true : false;
    session_set_cookie_params(
      ini_get('session.cookie_lifetime'),
      ini_get('session.cookie_path'),
      ini_get('session.cookie_domain'),
      $secure,
      true
    );

    // only do this after setting cookie params
    //function csrf_startup() {
      # configure csrf magic as needed
    //}
        => $db['USER'],
          'password' => $db['PASS']
        ]));
      },
    ],

    'beforeRender' => function($MVCish) {

      if (function_exists('csrf_conf')) {
        if ($MVCish->View()->view() == 'html') {

          if (($name  = $GLOBALS['csrf']['input-name']) &&
            ($token = \BF\CSRFMagic::getTokens())
          ) {
            // stash csrf vars where Render can find them. Render will add them 
            // to body_attr, where our js can pick them up to add to ajax calls.
            $MVCish->options['CSRF'] = [
              'data-sectkn-name'  => $name,
              'data-sectkn-token' => $token
            ];
          }
        }
        else {
          //turn off csfr writing
          csrf_conf('rewrite',false);
        }
      }
      return true;
    }
  ]);

  // provide our Auth object to MVCish
  $MVCish->Auth(new \MyApp\Auth($MVCish));

  // If not