user2566502
user2566502

Reputation: 3

CakePHP: View without model from external API

I need help directing me to the best way to accomplish this. I have a third party API that I want to use for data. I want to call the API using AJAX to display information only when necessary so that I don't have to store it in the database.

I'd like to have a separate view or element so that the view is set up and the data returned can be placed into the view.

Should I create a controller to do this? Can you have a controller without a model? I'm sure this is not an ideal MVC method but I don't really know the best way.

Upvotes: 0

Views: 278

Answers (1)

floriank
floriank

Reputation: 25698

What you write does not make any sense at all:

I want to call the API using AJAX to display information

You do not need anything on the php server side when you do an AJAX call to a 3rd party site. Your server and Cake app is not even called in this case. Just modify the returned data as needed and injected it in the DOM tree where needed.

Can you have a controller without a model?

Yes

public $uses = array();

If you would not want to use AJAX, MVC wise it would be the best to create a Datasource for the API and use it together with a model. The example on this page shows a complete implementation of using data from a remote source.

Upvotes: 1

Related Questions