1

What is the best way to use codeIgniter with BoilerplateJS? should I put the codeIgniter folder in a BoilerplateJS folder or the contrary? Or something else? Need to make an authentifcation page in codeigniter and redirect the application in boilerplateJS. Thanks.

1 Answers1

1

File Structure

I tried BoilerplateJS with CI in the following way:

Basically this is including BoilerplateJS in CodeIgniter folder.

I included all the BoilerplateJS code except the index file in to a folder named public which is in the root folder of CodeIgniter. The index file is placed in the views folder and will be loaded by a controller. (See the image)

For this to work some file paths had to be tweaked.

  1. File paths in boilerplatejs index file (boilerplate.html in my case) had to be changed as follows:

    ./libs/jquery/jquery-min.js >>to>> public/libs/jquery/jquery-min.js

    ./libs/underscore/underscore-1.3.3.js >>to>> public/libs/underscore/underscore-1.3.3.js and so on.

  2. In main.js requirejs path configurations should be changed to:

    require.config({
        //Let's define short alias for commonly used AMD libraries and name-spaces. 
        paths : {
            // requirejs plugins in use
            text : 'libs/require/text',
            i18n : 'libs/require/i18n',
            path : 'libs/require/path',
            // namespace that aggregate core classes that are in frequent use
            Boiler : './app/core/_boiler_'
        }
    });
    

And in your controller you can load boilerplatejs by: $this->load->view('boilerplate.html');

I was thinking of integrating BoilerplateJS and CodeIgniter and probably use codeignighter-rest server for some time.

If all goes well I will share the code within the week.

A sample project is available at: https://github.com/slayerjay/codeigniter-boilerplatejs

EDIT Adding my view on CodeIgniter and BoilerplateJS

Firstly I have not (yet) done any major projects with BoilerplateJS and Codeigniter. But I have done projects using CI and the CI REST Server and know BoilerplateJS in and out.

I do not have much experience with other PHP frameworks (I have meddled with cakePHP and some others) but for me CI helps me to organize my code according to MVC pattern in a clean way, and provides excellent helper libraries and documentation.

As the OP rightly said, authentication is handled best outside BoilerplateJS and this can be done nicely with something like ion-auth for CI. After the user is authenticated and the SPA is loaded, the rest of the calls will be handled by the CodeIgniter REST server. In this case you won’t be using much of the View aspect of your MVC architecture, but CI’s models and helpers would be of great help.

If you just need a simple REST server you can go with some lightweight solution that just provides REST type routing, but in many cases you will need to interact with a database and do some data processing.

So if you have decided to have a PHP backend for your application, Codeigniter with the REST server is a good choice.

janith
  • 1,025
  • 5
  • 21
  • Maybe you can shed some insight on this issue. BoilerPlateJS is designed for Single-Page-Applications whereas CodeIgniter is designed for managing a multi-page dynamic website. I don't know much about BoilerPlateJS, but based on your experience, what is advantage of using CodeIgniter within a SPA architecture? Thank you for your insight. – Marc Audet Mar 07 '13 at 17:56
  • Ok, I want to use codeIgniter for his MVC structure and because i'm doing with a databases. – Thierry Otis Mar 08 '13 at 11:27
  • Thanks Janith. Now that boilerplatejs is integrated, i've made a connexion page in codigniter's view directory and the user is redirected into boilerplatejs after a successuful login. are cookies the best(only) way to read user information in boilerplatejs? – Thierry Otis Mar 09 '13 at 12:53
  • Cookies will be simple and easy (Strictly speaking, cokies will not be very RESTfull), but there are many methods. See [this](http://stackoverflow.com/questions/12545476/boilerplatejs-recommended-way-to-handle-authorization-and-authentication) and [this](http://stackoverflow.com/questions/319530/restful-authentication) – janith Mar 10 '13 at 12:12