JianYA
JianYA

Reputation: 3024

Codeigniter splitting between application and web server

I know this is quite a weird question but I was hoping that someone could advise me on how I can split my Codeigniter application between 2 different servers?

The solution I have in mind now is this

Web Server - The model won't be used. The View and Controller will be used. The controller will make a REST request to the Application server that will return json data to it and will push to the view

Application Server - The View won't be used. The Controller is where the business logic is at and will communicate with the model.

Is my thinking correct?

There is another way that uses PHP FPM but I am unsure of how that works.

Upvotes: 2

Views: 168

Answers (1)

Alex Mac
Alex Mac

Reputation: 2993

Please go through below mentioned solution.

IN this case you need to create REST Server where all your database related activities will be happen. You can implement REST Server in codeigniter by below mentioned link.

https://github.com/chriskacerguis/codeigniter-restserver

In rest server your controller will handle specific http operation with methods. like GET, POST, PUT, UPDATE

class Books extends REST_Controller
{
  public function index_get()
  {
    // Display all books
  }

  public function index_post()
  {
    // Create a new book
  }
}

Now in your view part you need to implement rest client. So that you can make request for CRUD operations depends on requirement.

https://github.com/philsturgeon/codeigniter-restclient

While beauty of rest client is below.

// Load the library
$this->load->library('rest');

// Run some setup
$this->rest->initialize($config);

// Pull in an array of tweets
$tweets = $this->rest->get('statuses/user_timeline/'.$username.'.xml');

You can get response in multiple format. like Json, CSV, XML etc.

I have used this both and it working pretty much awesome.

Let me know if you need any help during implementation.

Upvotes: 0

Related Questions