This is a 'Reading Journal' web application built with MongoDB and CodeIgniter. You can also follow the step-by-step tutorial for building this application.
To run this application, follow the instructions below.
Grab the code from Github and navigate to the cloned directory:
git clone git@github.com:mongodb-developer/mongodb-codeigniter.git
cd mongodb-codeigniter
The MongoDB PHP Driver consists of two components: the extension and the library.
To install the extension and load it in your php.ini
file, run the following commands:
pecl install mongodb
echo "extension=mongodb.so" >> `php --ini | grep "Loaded Configuration" | sed -e "s|.*:\s*||"`
Then, install the library with Composer:
brew install composer
composer require mongodb/mongodb
Copy env
to .env
and replace ATLAS_URI
with your own Atlas URI connection string. Make sure you also replace the username and password placeholders with your own credentials.
To start the local development server, run the following command:
php spark serve
Open the browser on http://localhost:8080/.
The application consist of a few notable building blocks:
The DatabaseConnector
class located in app/Libraries/DatabaseConnector.php
is responsible for connecting to the MongoDB database. It gets the connection string and database name from the .env
file. Then, it connects to the database using the MongoDB PHP Driver.
The BooksModel
class located in app/Models/BooksModel.php
implements the CRUD (Create, Read, Update, Delete) functionality for the books
collection.
The Books
class located in app/Controllers/Books.php
is the controller for the books pages in our application. It's responsible for fetching data through the BooksModel
and passing it to the view. It also handles the form submission and validates the form data.
The application routes are configured in the app/Config/Routes.php
file.
Use at your own risk; not a supported MongoDB product