Cakephp Classroom image

deepa
 
To post your Question Join Classroom
 
Lesson Topics's No:-  First|70 | 71 | 72 | 73 | 74 | 75 | 76 | 77 | 78|Last
Lessons:-Models

}
We can then configure the datasource in our app/Config/database.php file by adding something
like this:
public $faraway = array(
’datasource’ => ’FarAwaySource’,
’apiKey’ => ’1234abcd’,
);
Then use the database config in our models like this:
class MyModel extends AppModel {
public $useDbConfig = ’faraway’;
}
We can retrieve data from our remote source using the familiar model methods:
// Get all messages from ’Some Person’
$messages = $this->MyModel->find(’all’, array(
’conditions’ => array(’name’ => ’Some Person’),
));
Similarly we can save a new message:
$this->MyModel->save(array(
’name’ => ’Some Person’,
’message’ => ’New Message’,
));
Update the previous message:
$this->MyModel->id = 42;
$this->MyModel->save(array(
’message’ => ’Updated message’,
));
And delete the message:
$this->MyModel->delete(42);
Plugin DataSources
You can also package Datasources into plugins.
Simply place your datasource file into Plugin/[YourPlugin]/Model/Datasource/[YourSource].php
and refer to it using the plugin notation:
public $faraway = array(
’datasource’ => ’MyPlugin.FarAwaySource’,
’apiKey’ => ’abcd1234’,
);

 
 
 

deepa

Skills    Cakephp

Qualifications :-
Location :-,,,
Description:-
Explore
 

  Students (0)