I have a large number of CakePHP 2 web applications, many of them use remote data over the custom DataSource. I'm reading the documentation of CakePHP 3, but I can not find instructions for creating custom datesource.
My next project also requires a custom DataSource (ArangoDB), so I planned to build it with the new version of CakePHP.
Please do specify where and how to build a DataSource in CakePHP 3.
Thank You.
Just look at the code of any existing database driver and see how it is built? There is nothing in the book yet about how to create your own datasource.
ArangoDB seems to be yet another NoSQL DB, so take a look at how this Elastic Search datasource is done. By a quick look I think you can use it as a base for your implemention, they seem to be similar.
I was facing the same problem so I decided to write my own models in CakePHP 3.x. If you want you can use it from here. hope you like it.
Related
I have to integrate Solr search in one of my CakePHP project. I have installed Solr and Solarium using composer but could not find how to start searching using Solr. Is there any example code in CakePHP?
First thing you need to figure out is how to expose the Solarium API in your CakePHP application. Typically this means saving some third-party PHP files into the Vendor directory of your application (take peek here for more information).
Once you've done this, you have two options:
Interact with the Solarium API directly in your controller's actions.
Implement a Solarium datasource so you can use CakePHP's model constructs.
Option 1
This option is less consistent with how the developers of CakePHP would like you to do MVC and you will have to generate a fair bit of code each time you want to put something in Solr or query it (e.g. connect to the Solr database). If you have minimal interaction with your Solr database, then I would recommend going down this route. Perhaps you could wrap up your access in separate helper class or function so instead of this:
public function void myControllerAction() {
// create a client instance
$client = new Solarium\Client($config);
// get a select query instance
$query = $client->createQuery($client::QUERY_SELECT);
// this executes the query and returns the result
$resultset = $client->execute($query);
// expose the result set to your view
$this->set('records', $resultset);
}
you could have this:
public function void myControllerAction() {
$resultset = solarium_get_records();
// expose the result set to your view
$this->set('records', $resultset);
}
Option 2
This option is a bit more involved and requires you to write a Solarium datasource just like the developers have written for MySql and Postgres. This does require you to thoroughly understand the inner workings of CakePHP's model engine but by taking a look at how the other datasources work, it shouldn't be rocket science. Rest assured that if you did this and made your code open-source, other developers will love to use it in their own CakePHP applications!
The benefit of this approach is that you will successfully abstract your application from the specific database implementation. So if you decided you didn't fancy using Solr and preferred a different search engine, you could migrate your data, write a new datasource (if one didn't exist already) and you're all set.
This probably doesn't exactly answer your question but instead steer you in the right direction and highlight some aspects you should consider.
I have integrated Solr with Option 1. However option 2 is doable but due to some time restriction I have to choose option 1. We can directly include Solarium vendor and include its class in our controller wherever required and use solr's add/get queries.
There are basically 3 major steps: 1: Install Solr. 2: Install Solarium using composer 3: User your scripts within controller or component files to get results.
You can get complete reference and example codebase from here:
http://findnerd.com/list/view/Solr-integration-in-CakePHP-with-solarium-client/1946/
Thanks.
I've integrated Solr using Sam's Option 2 (as DataSource)
https://github.com/Highstrike/cakephp-solr-datasource
You can also find there instructions on how to use it with examples
I am using CakePHP 2.2 and I will probably need to use SMTP with TTL which is only available at CakePHP 2.3.0.
The additions for this new feature are documented here:
https://github.com/cakephp/cakephp/pull/734
And i was wondering where should I add this code in my CakePHP project as I guess the core folders should stay untouched.
Could I do it using the app\lib folder? In that case, how should I add the content? Do I need to follow any structure? How Cake would detect it?
Thanks.
Just follow the CakePHP Migration guide and update to 2.3.
Honestly, I didn't even read through the migration guide, I just swapped into 2.3 and everything has just worked. It doesn't appear that there are many changes to existing code - just improvements / additions, so you'll likely not have to do any code modification.
I like to keep my versions of Cake separate (see advanced installation), but if you're on the normal install, just replace the files within /lib/Cake/ with the new versions files.
I have an application and I want to use a table of Informix in my cakephp application. Is it possible?
I just want the users table of informix, the others tables i'll use mysql. Is it possible?
Thanks.
It can be done but it needs information about how you can access the data. Is it standardised like REST/SOAP or something? Or do you need hard database access?
In general in CakePHP you build a custom datasource for it: http://book.cakephp.org/2.0/en/models/datasources.html or you can work with behaviours which you attach to models.
There are some examples of this approach like this for REST:
http://www.neilcrookes.com/2010/06/01/rest-datasource-plugin-for-cakephp/
When Joomla 1.6 came out and onwards I started using the joomla profile plugin to manage my user's profile data.
I have been wondering for quite a while about the pros and cons of such a table where the data is stored in rows and not in fields.
The pro is definitely that I can add new profile fields very easily.
The con is how do you search on the information when different field types are stored in a text field - ie: the dob of the user is stored in a text field.
Perhaps this question is more database than joomla related?
But it boils down to - should I be using the joomla profile table for large numbers of users?
Thanks,
Mat
It really depends on the project you are working on.
If you use a plugin to get the work done, cons are
You will have to spend some time to get to know the plugin.
It will take more time to make changes since you don't know the internal structure of the plugin.
pros are,
Plugin does everything for you. Faster development.
Most probably error free and tested well.
In my opinion if you are to do a lot of data manipulation and if the plugin does what you want to do exactly use the plugin. That's the best part of joomla. Faster development. If you have any problems please ask.
You can use the Joomla extended profile if you want to, or you can use Community Builder which also extends user profiles.
Out of all honest, might be better for lots of users, as you might want to install other extensions in the future, such as the Kunena forum for example, which it integrates with fully, along with lots of other extensions.
I'm working on project and need to implement custom database driver, but can't find any guidelines which interfaces i should to implement.
Is there any resourses available that could help writing custom driver rather thank just diving in code and trying to figure out how current drivers are implemented?
EDIT
By saying "driver" i mean support for example NoSQL dabase using standart Laravel's methods ( Eloquent model and Query builder ), for example:
User::take(10)->get();
For Mysql Laravel uses eloquent
laravel - eloquent
For NoSql like MongoDB, you can use laravel-mongodb
jenssegers - laravel-mongodb
It's even support Hybrid relations between MySql and MongoDB
I have worked on MongoDB (a NoSQL database) in one of my project, where I have to use a jenssengers package https://github.com/jenssegers/laravel-mongodb to use the functionalities. I was not able to use Eloquent in that.
Laravel - eloquent/ jenssegers - Laravel-MongoDB can manage hybrid relations as well.