### Install a package Source: https://learn.userfrosting.com/going-live/cron Use `apt-get install` to install a new software package. ```bash apt-get install ``` -------------------------------- ### Setup Automated Renewal Environment Source: https://learn.userfrosting.com/going-live/vps-production-environment/ssl Commands to install dependencies and prepare directories for automated certificate renewal. ```bash sudo apt install moreutils ``` ```bash sudo mkdir /var/log/certbot ``` ```bash sudo crontab -e ``` -------------------------------- ### Create .env File from Example Source: https://learn.userfrosting.com/configuration/environment-vars Manually create the .env file by copying the provided example file in the app directory. ```bash $ cp app/.env.example app/.env ``` -------------------------------- ### Install Frontend Dependencies Source: https://learn.userfrosting.com/cli/commands The `assets:install` command installs frontend dependencies based on `packages.lock`, equivalent to `npm install`. ```bash $ php bakery assets:install ``` -------------------------------- ### Generated Script Tags Example Source: https://learn.userfrosting.com/asset-management/asset-bundles Example of the HTML output generated by UserFrosting for entrypoint bundles. ```html ``` -------------------------------- ### Nginx Configure Arguments Example Source: https://learn.userfrosting.com/going-live/vps-production-environment/additional-recommendations An example of the configure arguments output from `nginx -V`. These are crucial for rebuilding Nginx with the same options plus new modules. ```bash --with-cc-opt='-g -O2 -fPIE -fstack-protector-strong -Wformat -Werror=format-security -Wdate-time -D_FORTIFY_SOURCE=2' --with-ld-opt='-Wl,-Bsymbolic-functions -fPIE -pie -Wl,-z,relro -Wl,-z,now' --prefix=/usr/share/nginx --conf-path=/etc/nginx/nginx.conf --http-log-path=/var/log/nginx/access.log --error-log-path=/var/log/nginx/error.log --lock-path=/var/lock/nginx.lock --pid-path=/run/nginx.pid --http-client-body-temp-path=/var/lib/nginx/body --http-fastcgi-temp-path=/var/lib/nginx/fastcgi --http-proxy-temp-path=/var/lib/nginx/proxy --http-scgi-temp-path=/var/lib/nginx/scgi --http-uwsgi-temp-path=/var/lib/nginx/uwsgi --with-debug --with-pcre-jit --with-ipv6 --with-http_ssl_module --with-http_stub_status_module --with-http_realip_module --with-http_auth_request_module --with-http_addition_module --with-http_dav_module --with-http_geoip_module --with-http_gunzip_module --with-http_gzip_static_module --with-http_image_filter_module --with-http_v2_module --with-http_sub_module --with-http_xslt_module --with-stream --with-stream_ssl_module --with-mail --with-mail_ssl_module --with-threads ``` -------------------------------- ### Composer configuration examples Source: https://learn.userfrosting.com/sprinkles/customize Examples of the composer.json file structure, showing both the default skeleton configuration and a modified version with a custom namespace. ```json { "name": "userfrosting/userfrosting", "type": "project", "description": "A secure, modern user management system for PHP.", "keywords": ["php user management", "usercake", "bootstrap"], "homepage": "https://github.com/userfrosting/UserFrosting", "license" : "MIT", "authors" : [ { "name": "Alexander Weissman", "homepage": "https://alexanderweissman.com" }, { "name": "Louis Charette", "homepage": "https://bbqsoftwares.com" }, { "name": "Jordan Mele", "email": "SiliconSoldier@outlook.com.au", "homepage": "https://djmm.me" } ], "require": { "php": "^8.1", "ext-gd": "*", "userfrosting/framework": "^5.1", "userfrosting/sprinkle-core": "^5.1", "userfrosting/sprinkle-account": "^5.1", "userfrosting/sprinkle-admin": "^5.1", "userfrosting/theme-adminlte": "^5.1" }, "require-dev": { "friendsofphp/php-cs-fixer": "^3.0", "phpstan/phpstan": "^1.1", "phpstan/phpstan-deprecation-rules": "^1.0", "phpstan/phpstan-mockery": "^1.0", "phpstan/phpstan-phpunit": "^1.0", "phpstan/phpstan-strict-rules": "^1.0", "phpunit/phpunit": "^9.5", "mockery/mockery": "^1.2", "league/factory-muffin": "^3.0", "league/factory-muffin-faker": "^2.0" }, "minimum-stability": "dev", "prefer-stable": true, "autoload": { "psr-4": { "UserFrosting\\App\\": "app/src" } }, "autoload-dev": { "psr-4": { "UserFrosting\\Tests\\App\\": "app/tests/" } }, "scripts": { "post-create-project-cmd" : "php bakery bake" } } ``` ```json { "name": "owlfancy/site", "type": "userfrosting-sprinkle", "description": "Site sprinkle for owlfancy.com.", "license" : "MIT", "authors" : [ { "name": "David Attenborough", "homepage": "https://attenboroughsreef.com" } ], "require": { "php": "^8.1", "ext-gd": "*", "userfrosting/framework": "^5.1", "userfrosting/sprinkle-core": "^5.1", "userfrosting/sprinkle-account": "^5.1", "userfrosting/sprinkle-admin": "^5.1", "userfrosting/theme-adminlte": "^5.1" }, "require-dev": { "friendsofphp/php-cs-fixer": "^3.0", "phpstan/phpstan": "^1.1", "phpstan/phpstan-deprecation-rules": "^1.0", "phpstan/phpstan-mockery": "^1.0", "phpstan/phpstan-phpunit": "^1.0", "phpstan/phpstan-strict-rules": "^1.0", "phpunit/phpunit": "^9.5", "mockery/mockery": "^1.2", "league/factory-muffin": "^3.0", "league/factory-muffin-faker": "^2.0" }, "minimum-stability": "dev", "prefer-stable": true, "autoload": { "psr-4": { "Owlfancy\\Site\\": "app/src" } }, "autoload-dev": { "psr-4": { "Owlfancy\\Site\\Tests\\": "app/tests/" } } } ``` -------------------------------- ### Start Development Server Source: https://learn.userfrosting.com/cli/commands Launches the PHP built-in web server for local testing. ```bash $ php bakery serve [options] ``` -------------------------------- ### Install React Dependencies Source: https://learn.userfrosting.com/asset-management/advance-use Install the core React packages via npm. ```bash npm install react react-dom prop-types --save ``` -------------------------------- ### CLI: setup:db Source: https://learn.userfrosting.com/cli/commands Configures database settings interactively or via command-line options. ```APIDOC ## CLI setup:db ### Description The `setup:db` command can be used to setup the database configuration interactively. This configuration will be saved in the `app/.env` file. ### Command `php bakery setup:db [options]` ### Options - **--force** - Force setup if db is already configured - **--db_driver** - The database driver ["mysql","pgsql","sqlsrv","sqlite"] - **--db_name** - The database name - **--db_host** - The database hostname - **--db_port** - The database port - **--db_user** - The database user - **--db_password** - The database password ``` -------------------------------- ### Install UserFrosting with Composer Source: https://learn.userfrosting.com/ Use Composer to create a new UserFrosting project. This command clones the skeleton repository and initiates the installation process. Ensure your Composer version is 2 or higher. ```bash composer create-project userfrosting/userfrosting UserFrosting "^5.1" ``` -------------------------------- ### Initialize UserFrosting Configuration Source: https://learn.userfrosting.com/configuration/environment-vars Run the Bakery setup command to initialize the environment configuration. ```bash $ php bakery setup ``` -------------------------------- ### Install PyDrive Source: https://learn.userfrosting.com/going-live/backup Installs PyDrive, a Python library for Google Drive API authentication, using pip. Ensure python-pip is installed first. ```bash sudo apt-get install python-pip sudo -H pip install pydrive ``` -------------------------------- ### English Language File Example Source: https://learn.userfrosting.com/i18n/translator Example of English language file structure for 'COLOR' and 'MY_CATS' translations, demonstrating how to set up basic and pluralized strings. ```php "COLOR" => [ "RED" => "red", "WHITE" => "white", [...] ]; "MY_CATS" => [ 0 => "I have no cats", 1 => "I have a {{color}} cat", 2 => "I have {{plural}} {{color}} cats" ]; ``` -------------------------------- ### bake Command Source: https://learn.userfrosting.com/cli/commands The `bake` command is a general installation command that combines several other setup and build commands. ```APIDOC ## bake ### Description A general installation command that combines `setup:db`, `setup:mail`, `debug`, `migrate`, `create:admin-user`, `assets:build`, and `clear-cache`. ### Method CLI Command ### Endpoint `php bakery bake` ### Notes This command should be executed after `composer update`, asset changes, new migrations, or when adding/installing sprinkles. ``` -------------------------------- ### Install Timestamp Tool Source: https://learn.userfrosting.com/going-live/ssl Install the moreutils package to access the ts command for logging. ```bash sudo apt install moreutils ``` -------------------------------- ### Verify Node.js Installation Source: https://learn.userfrosting.com/installation/environment/native/requirements Check the installed version of Node.js to ensure it meets the minimum requirements. ```bash $ node -v ``` -------------------------------- ### Organize Migration Files Source: https://learn.userfrosting.com/database/extending-the-database Example directory structure for organizing migration files in subdirectories. ```text src/Database/Migrations/SneksNStuff/ ├── SneksTable.php └── VolesTable.php src/Database/Migrations/V4/ ├── MembersTable.php └── OwlsTable.php src/Database/Migrations/V5/ ├── OwlsTable.php └── MembersTable.php ``` -------------------------------- ### Initialize and Configure ufModal Source: https://learn.userfrosting.com/client-side-code/components Example showing how to fetch modal content from a URL and handle post-render events. ```javascript // Fetch and launch the modal $('body').ufModal({ // URL that serves the modal HTML sourceUrl: site.uri.public + '/modals/users/roles', // Additional request parameters ajaxParams: { user_name: userName }, // Target element to display any errors generated by the modal request msgTarget: $('#alerts-page') }); // Additional code to run after the modal has been retrieved and displayed. // For example, setting up a form submission: $('body').on('renderSuccess.ufModal', function (data) { var modal = $(this).ufModal('getModal'); var form = modal.find('.js-form'); ... }); ``` -------------------------------- ### Install Nginx Build Dependencies Source: https://learn.userfrosting.com/going-live/vps-production-environment/additional-recommendations Install the necessary development libraries required for compiling Nginx with specific modules like GeoIP, XSLT, and Image Filter. Ensure you have `unzip` installed as well. ```bash sudo apt-get install libpcre3-dev libxslt1-dev libgd-dev libgeoip-dev unzip ``` -------------------------------- ### Manage packages Source: https://learn.userfrosting.com/going-live/unix-primer-ubuntu Installs or upgrades software packages using apt-get. ```bash apt-get install ``` ```bash apt-get upgrade ``` -------------------------------- ### Install Node.js compatibility package Source: https://learn.userfrosting.com/going-live/vps-production-environment/server-setup Install the nodejs-legacy package on Ubuntu to resolve naming collisions and ensure npm compatibility with Node.js. ```bash sudo apt-get install nodejs-legacy ``` -------------------------------- ### Verify Composer Installation Source: https://learn.userfrosting.com/installation/environment/native/requirements Check the installed version of Composer to confirm it is correctly configured. ```bash $ composer --version ``` -------------------------------- ### Example HTTP Response Headers Source: https://learn.userfrosting.com/going-live/vps-production-environment/additional-recommendations Sample output showing the X-Page-Speed header confirming successful Pagespeed integration. ```http HTTP/1.1 200 OK Server: nginx/1.13.3 Content-Type: text/html;charset=UTF-8 Connection: keep-alive Vary: Accept-Encoding Strict-Transport-Security: max-age=15768000 Date: Sat, 05 Aug 2017 19:45:15 GMT X-Page-Speed: 1.12.34.2-0 Cache-Control: max-age=0, no-cache ``` -------------------------------- ### Install PHP modules and restart Nginx Source: https://learn.userfrosting.com/going-live/vps-production-environment/server-setup Installs required PHP extensions and restarts the Nginx service to apply changes. ```bash sudo apt-get install php8.3-gd sudo apt-get install php-curl sudo service nginx restart ``` -------------------------------- ### Install and Bake Sprinkles Source: https://learn.userfrosting.com/sprinkles/community Use Composer to download and Bakery to install the sprinkle files after updating dependencies. ```bash composer update php bakery bake ``` -------------------------------- ### French Language File Example Source: https://learn.userfrosting.com/i18n/translator Example of French language file structure for 'COLOR' and 'MY_CATS' translations, showing how to handle plural forms for adjectives. ```php "COLOR" => [ "RED" => [ 1 => "rouge", 2 => "rouges" "WHITE" => [ 1 => "blanc", 2 =. "blancs" ]. [...] ]; "MY_CATS" => [ 0 => "I have no cats", 1 => "I have a {{color}} cat", 2 => "I have {{plural}} {{color}} cats" ]; ``` -------------------------------- ### View migration output Source: https://learn.userfrosting.com/cli/commands Example output showing the SQL queries generated during a migration process. ```text UserFrosting\Sprinkle\Core\Database\Migrations\v400\SessionsTable > select * from information_schema.tables where table_schema = ? and table_name = ? > create table `sessions` (`id` varchar(255) not null, `user_id` int null, `ip_address` varchar(45) null, `user_agent` text null, `payload` text not null, `last_activity` int not null) default character set utf8 collate utf8_unicode_ci > alter table `sessions` add unique `sessions_id_unique`(`id`) ``` -------------------------------- ### Install WSL2 Distro on Windows Source: https://learn.userfrosting.com/installation/environment/docker Use this command in Windows Terminal to install a WSL2 Linux distribution. Remember the Unix user and password you set. ```bash wsl --install ``` -------------------------------- ### Install or update npm dependencies Source: https://learn.userfrosting.com/asset-management/webpack-encore Standard command-line operations to install or update frontend packages defined in package.json. ```bash $ npm install # or $ npm update ``` -------------------------------- ### Configure Environment Mode Source: https://learn.userfrosting.com/cli/commands Sets the application environment mode using the setup:env command. ```bash $ php bakery setup:env [options] ``` ```bash php bakery setup:env --mode=production ``` -------------------------------- ### Automate Composer Install in Git Hook Source: https://learn.userfrosting.com/going-live/vps-production-environment/application-setup Add this line to your `post-receive` Git hook to automatically run `composer install` after pushing changes. ```bash # Install or update packages specified in the lock file composer install --working-dir=/var/www/ >> /var/log/deploy.log 2>&1 ``` -------------------------------- ### CLI: setup:mail Source: https://learn.userfrosting.com/cli/commands Configures outgoing email settings for the application. ```APIDOC ## CLI setup:mail ### Description The `setup:mail` command can be used to setup the outgoing email configuration. This configuration will be saved in the `app/.env` file. ### Command `php bakery setup:mail [options]` ### Options - **--force** - Force setup if SMTP appears to be already configured - **--smtp_host** - The SMTP server hostname - **--smtp_user** - The SMTP server user - **--smtp_password** - The SMTP server password - **--smtp_port** - The SMTP server port - **--smtp_auth** - The SMTP server authentication - **--smtp_secure** - The SMTP server security type ``` -------------------------------- ### Install Composer Globally Source: https://learn.userfrosting.com/installation/environment/native/requirements Move the Composer PHAR file to a system-wide directory to enable the 'composer' command. ```bash mv composer.phar /usr/local/bin/composer ``` -------------------------------- ### Test JSON Routes (GET) Source: https://learn.userfrosting.com/testing/writting-tests/testcase Example of testing a JSON GET route. It involves creating a JSON request, handling it, and then using various JSON assertion methods to validate the response status and body. ```PHP $request = $this->createJsonRequest('GET', '/api/foo'); $response = $this->handleRequest($request); // Assert response status & body $this->assertResponseStatus(200, $response); $this->assertJsonCount(1, $response); $this->assertJsonStructure(['bar'], $response); $this->assertJsonResponse(['bar' => true], $response); $this->assertJsonResponse(true, $response, 'bar'); // Equivalent to previous line $this->assertJsonNotEquals(['bar' => false], $response); ``` -------------------------------- ### Requesting constrained data via API Source: https://learn.userfrosting.com/database/data-sprunjing Example of a GET request URL using query parameters to specify sorting, page size, and page index. ```http GET http://example.com/api/users?size=5&page=0&sorts%5Bname%5D=asc ``` -------------------------------- ### Create a directory Source: https://learn.userfrosting.com/going-live/cron Use `mkdir` to create a new directory. ```bash mkdir path/ ``` -------------------------------- ### assets:install Command Source: https://learn.userfrosting.com/cli/commands The `assets:install` command is an alias for NPM scripts used to install frontend dependencies locally based on `packages.lock`. ```APIDOC ## assets:install ### Description Installs all required frontend dependencies locally, based on `packages.lock`. This command is an alias for `npm install`. ### Method CLI Command ### Endpoint `php bakery assets:install` ``` -------------------------------- ### Install PHP 8.3 on MacOS with Homebrew Source: https://learn.userfrosting.com/installation/environment/native/requirements Installs PHP 8.3 on MacOS using Homebrew. Ensure Xcode Command Line Tools and Homebrew are installed first. ```bash xcode-select --install ``` ```bash brew install shivammathur/php/php@8.3 ``` -------------------------------- ### Create the application working directory Source: https://learn.userfrosting.com/going-live/vps-production-environment/git-for-deployment Commands to create the web-accessible directory and assign ownership to the deployment user. ```bash sudo mkdir /var/www/ sudo chown : /var/www/ ``` -------------------------------- ### Install Less Dependencies Source: https://learn.userfrosting.com/asset-management/advance-use Install the required npm package for Less support. ```bash npm install less-loader@^11.0.0 --save-dev ``` -------------------------------- ### Initialize a bare Git repository Source: https://learn.userfrosting.com/going-live/vps-production-environment/git-for-deployment Commands to create a directory for bare repositories and initialize a new bare Git repository on the server. ```bash sudo mkdir /var/repo sudo mkdir /var/repo/.git sudo chown : /var/repo/.git cd /var/repo/.git git init --bare ``` -------------------------------- ### Install Sass Dependencies Source: https://learn.userfrosting.com/asset-management/advance-use Install the required npm packages for Sass support. ```bash npm install sass-loader@^13.0.0 sass --save-dev ``` -------------------------------- ### Create Backup Subdirectory and Set Permissions Source: https://learn.userfrosting.com/going-live/backup Creates a subdirectory for backups and assigns ownership and permissions to the 'backup' group. Ensure you replace `` with your repository's name. ```bash sudo mkdir /var/backups/ sudo chgrp backup /var/backups/ ``` ```bash sudo chmod g+rw /var/backups/ ``` ```bash sudo usermod -aG backup ``` -------------------------------- ### Configure database settings Source: https://learn.userfrosting.com/cli/commands Interactively sets up database configuration in the app/.env file. Options allow for non-interactive configuration. ```bash $ php bakery setup:db [options] ``` ```bash php bakery setup:db --db_driver=mysql --db_name=userfrosting --db_port=3306 --db_host=localhost --db_user=userfrosting --db_password=secret ``` -------------------------------- ### Install dependency via NPM Source: https://learn.userfrosting.com/recipes/external-js Use the command line to install the package and save it to your project dependencies. ```bash $ npm i darkreader --save ``` -------------------------------- ### Create PyDrive configuration directory Source: https://learn.userfrosting.com/going-live/backup Initializes the directory and file for storing Google API credentials. ```bash mkdir ~/.duplicity nano ~/.duplicity/credentials ``` -------------------------------- ### Install Duplicity Source: https://learn.userfrosting.com/going-live/backup Installs Duplicity, a tool for incremental backups, from a PPA. This ensures you have a recent version available. ```bash sudo add-apt-repository ppa:duplicity-team/ppa sudo apt-get update sudo apt-get install duplicity ``` -------------------------------- ### Start Docker Containers Source: https://learn.userfrosting.com/installation/environment/docker Starts the Docker containers in detached mode (-d), allowing them to run in the background. ```bash docker-compose up -d ``` -------------------------------- ### Verify Git repository initialization Source: https://learn.userfrosting.com/going-live/vps-production-environment/git-for-deployment Expected output after successfully initializing an empty bare Git repository. ```text Initialized empty Git repository in /var/repo/.git ``` -------------------------------- ### Install PHP Zip Package Source: https://learn.userfrosting.com/going-live/vps-production-environment/application-setup If Composer errors relate to the `php-zip` package, install it using apt-get and restart nginx. ```bash sudo apt-get install zip unzip php7.0-zip sudo service nginx restart ``` -------------------------------- ### Manual Monolog Object Creation Source: https://learn.userfrosting.com/dependency-injection/the-di-container Demonstrates the manual instantiation process for a Monolog logger, highlighting the complexity of nested dependencies. ```php // 1° Create formatter $formatter = new LineFormatter(null, null, true); // 2° Create Handler, give him the formatter $handler = new StreamHandler('userfrosting.log'); $handler->setFormatter($formatter); //3° Create the Logger, give him the handler $logger = new Logger('debug'); $logger->pushHandler($handler); ``` -------------------------------- ### Define Configuration File Structure Source: https://learn.userfrosting.com/sprinkles/customize Create a config directory and a default.php file within the sprinkle. ```text app └── config └── default.php ``` -------------------------------- ### Install Composer Dependencies Source: https://learn.userfrosting.com/going-live/vps-production-environment/application-setup Install PHP dependencies from the lock file in the project directory. This ensures consistent dependency versions in production. ```bash cd /var/www/ composer install ``` -------------------------------- ### View first 100 lines of a file Source: https://learn.userfrosting.com/going-live/cron Use `head` to display the beginning of a file, limited to the first 100 lines. ```bash head -n 100 file.txt ``` -------------------------------- ### Create UserFrosting Project with Composer in Docker Source: https://learn.userfrosting.com/installation/environment/docker This command uses Docker to run Composer and create a new UserFrosting project skeleton in a 'UserFrosting' subdirectory. The --no-scripts and --no-install flags speed up the initial creation. ```bash docker run --rm -it -v "$(pwd):/app" composer create-project userfrosting/userfrosting "^5.1" --no-scripts --no-install --ignore-platform-reqs ``` -------------------------------- ### Install PHP Dependencies with Composer in Docker Source: https://learn.userfrosting.com/installation/environment/docker Executes Composer to install the project's PHP dependencies within the running application container. ```bash docker-compose exec app composer update ``` -------------------------------- ### Enable Nginx Configuration Source: https://learn.userfrosting.com/going-live/vps-production-environment/application-setup Move the configuration file to the sites-available directory, create a symbolic link to sites-enabled, and reload the Nginx service. ```bash sudo mv ~/.conf /etc/nginx/sites-available/.conf sudo ln -s /etc/nginx/sites-available/.conf /etc/nginx/sites-enabled/.conf sudo service nginx reload ``` -------------------------------- ### Start UserFrosting Development Server Source: https://learn.userfrosting.com/ Run the built-in PHP development server to access your UserFrosting application locally. The application will be available at http://localhost:8080. ```bash php bakery serve ``` -------------------------------- ### Create Log Directory Source: https://learn.userfrosting.com/going-live/ssl Create a directory for storing Certbot renewal logs. ```bash sudo mkdir /var/log/certbot ``` -------------------------------- ### Create UserFrosting Project Source: https://learn.userfrosting.com/recipes/advanced-tutorial/base-setup Use Composer to create a new UserFrosting project with the specified version. Ensure the default skeleton app is functional before proceeding. ```bash $ composer create-project userfrosting/userfrosting UserFrosting "^5.1" ``` -------------------------------- ### Create or edit a file with nano Source: https://learn.userfrosting.com/going-live/cron Launches the `nano` text editor for creating or modifying files. Use Ctrl+X to exit. ```bash nano file.txt ``` -------------------------------- ### Define English locale messages Source: https://learn.userfrosting.com/i18n/introduction Example of an English language file defining account-related message keys, including one not present in the Spanish example. ```php return [ "ACCOUNT_SPECIFY_USERNAME" => "Please enter your user name.", "ACCOUNT_SPECIFY_DISPLAY_NAME" => "Please enter your display name.", "ACCOUNT_SPECIFY_AGE" => "Please enter your age.", ]; ``` -------------------------------- ### Install PHP 8.3 and Extensions on Ubuntu Source: https://learn.userfrosting.com/installation/environment/native/requirements Installs PHP 8.3 and common extensions required for web development on Ubuntu. Ensure you have added the Ondřej Surý PPA first. ```bash sudo add-apt-repository ppa:ondrej/php sudo apt update ``` ```bash sudo apt install php8.3 php8.3-gd php8.3-dom php8.3-zip php8.3-sqlite3 php8.3-pdo_mysql php8.3-curl php8.3-mbstring unzip ``` -------------------------------- ### Navigate to UserFrosting Directory Source: https://learn.userfrosting.com/ Change the current directory to the newly created UserFrosting project folder. ```bash cd UserFrosting ``` -------------------------------- ### Create Default Configuration File Source: https://learn.userfrosting.com/sprinkles/first-site Create a new configuration file in `app/config/default.php` to set custom application properties like site title and author. ```php [ 'admin' => [ 'name' => 'Squawkbot' ] ], 'debug' => [ 'smtp' => true ], 'site' => [ 'author' => 'David Attenborough', 'title' => 'Owl Fancy', // URLs 'uri' => [ 'author' => 'https://attenboroughsreef.com' ] ], 'php' => [ 'timezone' => 'Europe/London' ] ]; ``` -------------------------------- ### Define a GET Route with Authentication in PHP Source: https://learn.userfrosting.com/building-pages Define a GET route for '/members' that requires user authentication using AuthGuard middleware. This tells UserFrosting to invoke the PageMembers controller for this route. ```php use UserFrosting\Sprinkle\Site\Controller\PageMembers; // <-- Add this use UserFrosting\Sprinkle\Account\Authenticate\AuthGuard; // <-- Add this //... public function register(App $app): void { $app->get('/', [AppController::class, 'pageIndex'])->setName('index'); $app->get('/about', [AppController::class, 'pageAbout'])->setName('about'); $app->get('/legal', [AppController::class, 'pageLegal'])->setName('legal'); $app->get('/privacy', [AppController::class, 'pagePrivacy'])->setName('privacy'); // Add this: $app->get('/members', PageMembers::class)->add(AuthGuard::class); } ``` -------------------------------- ### Run UserFrosting Installation Script Source: https://learn.userfrosting.com/installation/environment/docker Executes the UserFrosting 'bakery' script to perform database configuration, migrations, and create an admin user. You will be prompted for admin user details. ```bash docker-compose exec app php bakery bake ``` -------------------------------- ### Traditional PHP 'Spaghetti Code' Example Source: https://learn.userfrosting.com/routes-and-controllers/introduction This example demonstrates a common, older PHP pattern where database logic and HTML presentation are mixed within a single file, often leading to difficult-to-maintain code. ```php if (isset($_POST)) { $stmt = $db->prepare("INSERT INTO users (:username, :email)"); $stmt->execute([ ':username' => $_POST['username'], ':email' => $_POST['email'] ]); } else { echo ""; $stmt = $db->prepare("SELECT * FROM users"); $stmt->execute(); while ($r = $stmt->fetch(PDO::FETCH_ASSOC)) { echo ""; } echo "
UsernameEmail
$r['user_name']$r['email']
" } ``` -------------------------------- ### Config Get Methods Return Null on Key Not Found Source: https://learn.userfrosting.com/upgrading/50-to-51/changelog The `getBool`, `getString`, `getInt`, and `getArray` methods in the Config class now return `null` if the specified key does not exist, aligning with the parent `get` method's behavior. ```php // Example of how the behavior change might be observed: $configValue = $config->getString('non_existent_key'); // Now returns null instead of throwing an exception or returning an empty string ``` -------------------------------- ### Select Users by Criteria Source: https://learn.userfrosting.com/database/overview Use the query builder's static methods on a model to filter records. Chain methods like `where()` and `get()` to construct and execute queries. The `get()` method returns a Collection of model instances. ```php ', 2)->get(); // Iterate over the collection foreach ($users as $user) { echo $user->first_name . "
"; } ``` -------------------------------- ### Define a GET Route with a Placeholder Source: https://learn.userfrosting.com/routes-and-controllers/front-controller Use this to define a GET route that accepts a placeholder in the URL and conditionally returns JSON or a plain text message based on a query parameter. Ensure the User model and necessary Slim/PHP-DI services are available. ```php $app->get('/api/users/u/{username}', function (string $username, Request $request, Response $response, array $args) { $getParams = $request->getQueryParams(); $result = User::where('user_name', $username)->get(); if ($getParams['format'] == 'json') { $payload = json_encode($result, JSON_THROW_ON_ERROR | JSON_PRETTY_PRINT); $response->getBody()->write($payload); } else { return $response->getBody()->write("No format specified"); } }); ``` -------------------------------- ### Verify npm Version Source: https://learn.userfrosting.com/installation/environment/native/requirements Check the currently installed version of npm. ```bash $ npm -v ```