Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6650229
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T00:52:05+00:00 2026-05-26T00:52:05+00:00

I wanted to add a function to my Slim application but I’m not familiar

  • 0

I wanted to add a function to my Slim application but I’m not familiar enough with PHP to know the best way to structure something like this. This is not production ready code and I obviously will not be hard coding my username and password into the script. I made this simply to illustrate the concept.

$options = array(
    'username' => 'admin',
    'password' => 'password'
);

$app = new Slim(array(
    'view' => new TwigView()
));

$app->config($ptions);

function authenticate($app, $username, $password) {
    if($username==$app->config('username') && $password==$app->config('password')){
        return true;
    } else {
        return false;
    }
}

$app->get('/', function () use ($app) { // ... }
// ... other routes
$app->post('/login', function() use ($app) {
    $username = $app->request()->post('username');
    $password = $app->request()->post('password');
    if(authenticate($app, $username,$password)) {
        $app->redirect('/');
    }
    $app->redirect('/login');
});

$app->run();

Does it make sense to have to pass $app to authenticate() or is there a better way? authenticate() would not be middleware, but a function called in the POST route for pressing submit on a login form.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-26T00:52:06+00:00Added an answer on May 26, 2026 at 12:52 am

    I suggest you use registry method.. ohbtw $app->config($ptions); should be $app->config($options);

    as for “registry”, I use the following class:

    <?
    class Registry {
      private static $data;
    
      /**
      * Returns saved variable named $key
      * @param string $key
      * @return mixed
      */
        public static function get($key) {
          if(!empty(self::$data[$key])) {
            return self::$data[$key];
          }
          return null;
        }
    
      /**
      * Saves variable to registry with the name $key
      * @param string $key
      * @param mixed $value
      * @return boolean
      */
      public static function set($key, $value) {
        if(!empty($value)) {
          self::$data[$key] = $value;
            return true;
          }
          return false;
      }
    }
    ?>
    

    to save use

    Registry::set('key', $value);
    

    to retrieve use

    Registry::get('key');
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

DataSet DataSet1 = new DataSet(); DataTable t = DataSet1.Tables.Add(employee); textBox1.DataBindings.Add(Text,t,salary); i wanted to know
I created a function in my controller called addToPlaylist($songName). I wanted to add these
HI guys, I wanted to add an AJAX Event to my Homepage, but it
I know there is this question that is very similar, but I wanted to
I wanted to add a constant to the prototype of a function constructor (class)
Is there way to override jQuery's core functions ? Say I wanted to add
Is there way to override jQuery's core functions ? Say I wanted to add
I'm not sure the title explains it well enough, but was trying to keep
Quick question. I just read that if you wanted to add a function to
I've been working on a CMS and wanted to add a backup/restore function. I

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.