This example allows you to add/edit/delete new members to your NoSQL database.
I’m not going to describe how to create and manage Controllers/Models/Views as these are CodeIgniter basics.
In your controller you populate your constructor:
This calls basic helpers to manage urls and date formatting.
Also I have called my Model Users here as each function requires access to this data.
Then in the index function:
This calls my Model to retrieve the data, loops through all results and enters it into an array to pass to the view.
One point to note is that I am using $member[“_id”]->__toString() This is the unique id for each record created by MongoDB so there is no need to create an additional field called ID to our data.
Now to create the Model.
These are some general functions that would be useful for many different requests that you require.
Inside the constructor I connect to Mongo with localhost:27012, create a database called blog (can be any name you wish) and set the table name as users.
This now means that all calls made to $this->posts will now be made on the users table.
As you can see in the function getAll() call we get all data inside the users table with the call $this->posts->find();
After that point you can then limit, order by and other functions if you require.
Then on the View you only need to add
This will list out all the results in the $members array displaying the name of the member.
Have a look through the GitHub repo to see how to add/edit/delete members.
Its all very similar just with different syntax.