8 Best PHP Frameworks For Developer in 2021

Do you want to build a website in the PHP framework?

Is the PHP framework necessary?

PHP framework is one of the oldest and most popularly used frameworks. Looking towards the complexities rising in website development, PHP is gaining more and more importance by ensuring convenience in building relevant codes.

So, let’s learn in detail about what is PHP framework and a few of the commonly used frameworks for developers in 2021.

What is a PHP framework?

PHP Framework is a platform where you can create websites and applications with the most advanced features and functions. It is the world’s most popular scripting language that ensures flexibility, ease of usage and reusable coding.

What is a PHP framework used for?

PHP framework is ideally used for creating web applications that ultimately speed up the development process. It offers pre-built modules for performing coding tasks easily and quickly within a lesser period of time.

You can definitely hire professional Web and Mobile App Development who specializes in a PHP framework that delivers you a seamless website with the most advanced facilities.

What is a framework in PHP for beginners?

Some of PHP frameworks that are actually good for beginner’s are- Yii Framework, Zend, Laravel and Symphony that ensure convenience in usage and maintainability.

1. Laravel

Laravel is one of the Best PHP Framework that can safely handle complex web applications at a faster pace than any other framework. It is an open source PHP web framework that build scalable web applications by simplifying common tasks like security, authentication, caching, security, and routing.

Features of Laravel

  • PHP framework Laravel has its own light weighted template called ‘Blade’
  • Offers a reusable, maintainable and flexible code
  • Works on MVC pattern for separation of presentation and logic

Who uses Laravel?

  • 9GAG
  • E-Commerce
  • MasterCard
  • Bitpanda
  • Razorpay

2. Codeigniter

Codeigniter is one of the lightweight PHP framework that comes with a simple, straightforward and quick installation process requires only minimal configuration or so.

Licensed under MIT license, this PHP backend framework gives a complete flexibility to use at no cost.

As a top PHP frameworks, it comes with complete packet libraries that contribute significantly in manipulating images, sending mails, form validation and others.

Features of Codeigniter

•It is compatible with most web servers
•Holds a strong community forums
•It is swift, convenient and easy to use framework

3. Symphony

Symphony being the Best PHP Framework, comes with a set of reusable PHP components. It includes routing, object configuration, Templating, authentication, form creation and many others to perform diverse tasks.
Features of Symphony

  • Symphony is independent of database engine
  • Easier maintainability and even new developers can manage it
  • It comes with an enhanced security and timely upgrades

4. CakePHP

CakePHP is a decade old most popular PHP framework that adopts the change and keeps up with the time. It is quite straightforward and easy to learn and easy to install that even a beginner won’t face any complexity.
Features:

  • Offers a vast range of features and functions
  • It has an improved modularity and advanced libraries
  • Serves as a good option for commercial application projects

5. Slim

Slim is one of the Best PHP Framework that helps you in quickly writing simple yet powerful web applications. Known as a micro PHO framework, it assists developers even in the most complex scenarios.

Features of Slim

  • Improves the load time and overall performance of your website
  • Protect applications from cross-site requests and validates requests
  • It has a professional community of users and developers

6. Yii framework

Yii Framework is an object oriented PHP framework that contributes significantly for large scale website development. Besides that, this simple PHP framework helps in case of rapid prototyping and generating desired code interactively.

Features of Yii Framework

  • Offers a multiple package of security
  • Easy-to-use theming and skinning mechanism
  • This PHP front-end framework comes with AJAX enabled features

7. Phalcon

Phalcon is one of the Best PHP Framework written in C and C++ language that boosts up the execution speed, triggers the overall performance and at the same time reduces the resource usage.

Among the PHP frameworks list, Phalcon is suitable for building high-configuration web applications by incorporating limited resources.

Features of Phalcon

  • It has auto loading, security translation and asset management features
  • It is one of the fastest PHP framework that comes with outstanding features and architecture
  • Easy to add modules and libraries whenever you want to

8. Zend Framework

Zend framework is one the most popular PHP frameworks that fits perfectly for complex and enterprise level projects. This PHP-MVC-Framework is built on an agile methodology that lets you deliver high quality web applications with the most advanced features and functions.

Features of Zend Framework

  • It can easily integrate with external libraries
  • Offers an extremely good documentation
  • It is highly customizable where you can add any project specific functionalities

The conclusion

Did you make a PHP framework comparison?

Well, all the above discussed frameworks are trusted by millions of companies and industries.

However, if you ever wondered, which framework I should use for web application development, note that, you need to understand your business requirements and accordingly make the decision to select the best one.

The scope of PHP Framework is wide and it gives you an opportunity to stand out from the crowd. Therefore, hire the best of all PHP Developers now and get started to build your business application and website now!

What Is The Saas Life Cycle-Application And Development

A SaaS Project Management & Team Communication tool, the enterprises that purchase the services of SaaS providers will always come out on top with efficient operations and organized teamssaid by Basecamp.

The Saas Life Cycle is a term used in the software industry to describe the process of creating a new software product. It’s a generic way of understanding the different phases that a software project goes through from the moment you start developing a new application to the moment you release it for users.

If you’re new to the Saas Life Cycle, you might be wondering what exactly it means. Or you might be wondering how you can take your new project through this process to make it more successful. Either way, you’ll learn more about the Saas Life Cycle and how it can help your new software project succeed with this article.

SaaS Development

From the view of experts, SaaS development is unique. It requires a specific skill-set and an open-minded approach.

Never miss an update from us. Join 10,000+ marketers and leaders.

Here are some benefits of using a SaaS:

  • Lower costs. Since SaaS is a “cloud” solution the prices customers are required to pay are much lower than on-premise solutions.
  • Scalability. SaaS is an already developed solution, customers do not need to do much planning, as SaaS are highly scalable.
  • Upgrades. SaaS provides all the upgrades themselves, which is highly convenient for the users.
  • Integration. SaaS are perfect platforms for integration with other services
  • User Experience. SaaS solutions always try to make their UX enjoyable. Which lets their customers spend less time learning how to use the software.

The SaaS Development Life Cycle Must Begin With A Vision

You need to conduct a lot of research if you are willing to develop a great tool. Beginning with, identifying the needs of an organization is a crucial part to fulfill.

Gathering the ideas and evaluating the market will give you an idea of a product that is going to be useful and successful.

The Planning Stage

You can’t develop a SaaS Application much without having a great plan. You and your developing authority must understand how are you going to develop your SaaS, how much it will cost, when will you be able to launch it, and how is the marketing strategy going to look.

Software Development Strategies for your SaaS solution may help with answering those questions.

The Subscription Stage

After all decisions regarding cost and architecture have been finalized comes the time to choose your cloud provider. While there are many decisions to be made regarding a SaaS platform, the cloud provider selection is, probably, the most important one.

Subscription

The Development Stage

The Development stage is a complex stage. There are many decisions to make regarding the project’s architecture.

Actually, there is no point in developing a SaaS application unless it is suitable for all targeted users and has the potential to scale.

Below I have listed some of the essential requirements for a SaaS development to meet to be considered valuable for users and profitable for developers as well:

  • User Experience. The software must be easy to use and user-friendly.
  • Security. SaaS must to provide a high level of security, and its customers must believe in the exceptional security of their data.
  • Customer Support. The Built-in support processes, 24-hour access, and frequent, non-disruptive updates must all take place in a SaaS Application.

By keeping these basic practices in mind, the SaaS development process will mean the following:

Selection Af A Development Methodology

There is a large amount of methodologies available and that are known as the “Software Development Lifecycle”. Let’s break down some of the most common ones below:

  • Rapid – quickly to put together and speed-up the development, and then tested.
  • Spiral – here development divided into cycles, each of which is evaluated to then later influence the next cycle and better the methodology.
  • Agile – development methodology where each iteration gets evaluated after it ends, so that positive change and adaptation of plans can take place before the next iteration begins.

Agile Methodology

SaaS Will Mean HTML5

New products mean using the HTML5 technology. It is one of the most suitable for today’s environment. This technology provides rich Internet applications so, do not need the legacy plugins.

“When back in 2014 Microsoft announced that they will be discontinuing the support of Windows XP, Microsoft platforms that could not support HTML5 slowly began to die off.”

But there still may be some glitch issues with the use of HTML5 on mobile devices, but there are less and less of those each day. If there are any issues, then a native mobile app may be the best course of action.

SaaS Requires Published API’s

SaaS products must have API’s that provide for the development of external widgets and extensions by value-added resellers and other third-party developers.

APIs have to be consistent and should be maintained after publishing. Developers should ensure that APIs must be extended, which requires a very accurate architecture.

SaaS And Stateless Architecture

Stateless architecture is preferred because it provides smooth performance, elasticity, scalability, and fault tolerance. If applications are stateless, there is no need to allocate storage of previous requests, making the cost lower.

These applications can also scale easily, making it perfect for dealing with spikes in usage. Stateful architecture, on the other hand, requires more management and takes up more infrastructure resources.

Stateless architecture is not a requirement for SaaS, though it just may provide the best performance.

SaaS Upgrades

Upgrades must be built into the architecture in a way that will not disrupt user experience.

SaaS companies do not put out different version there – usually there are only two. If a new version is developed, it can be done on a separate server without any migrated clients to minimize disruptions.

Operations – Requirements For Development

New tenant on-boarding and billing services must be built into the SaaS architecture. IaaS and PaaS providers (if they are used), and third-party tools may help with managing that, though their integration must be in the software product itself. There isn’t a defined model for all of this, which means that the developers will have to get creative.

SaaS Implementation Methodology And Deployment

Once the software is deployed, frequent updates and security patches should take place to keep the support requests to a minimum while continually improving the UX.

Helpdesk calls and/or support tickets all result in increased operational costs, so the goal is to automate those tasks as much as possible and. Remember – constant monitoring and patches/updates will keep your customers happy.

SaaS Development, Operations, And Management Are Unique

Everyone must consider SaaS development, invest heavily in the talent of the people developing it.

This is the most expensive part of the endeavor – the requirement for a very specific skill set.

And, if you intend to have a top-rated piece of software – robust, expansion-ready, innovative, with well-received UI and UX, secure, and reliable in its implementation – then you must be prepared for the high costs involved.

Saas Development Tools

SaaS projects are usually complex and oftentimes unique. It means there is no defined stack of tools mandatory for SaaS development. You can build your SaaS development stack off of your project requirements, your architecture and your marketing strategy.

I’ve worked with the team at Andolasoft on multiple websites. They are professional, responsive, & easy to work with. I’ve had great experiences & would recommend their services to anyone.

Ruthie Miller, Sr. Mktg. Specialist

Salesforce, Houston, Texas

LEARN MORE

Nevertheless, some of the more popular tools for SaaS development are listed below:

Server-side development:

Conclusion

SaaS solutions have become the best options for many businesses these days. Their availability, scalability, and pricing policies all provide their users with an abundance of benefits.

Whether you are looking to adopt a SaaS in your business, or you are planning to develop a SaaS of your own, the concept is as innovative as it gets and it is worth all the attention it has recently been getting.

Things You Should Know Before Hiring A PHP Developer

“It’s always cost-effective and secured to go with PHP development and convert your business ideas into reality. Experienced PHP developer can take you to the next level with advance technique. So it’s your time to cross check various aspects, like developer’s knowledge, ability, experience and the hiring process of company/agency while you are going to hire a developer”.

As you know, PHP is one of the most popular and robust framework to develop beautiful and user-friendly websites and applications for any size of business.

The demand of PHP developers are growing now days and their numbers are increasing also. In the mean time you need to choose the right developer for your business.

“The best programmers are up to 28 times better than the worst programmers”

                                                                                                              – Robert. L. Glass

It’s not advisable for you if you will throw money according to your requirement and discuss with him/her at the end for your output. You need to have few idea/documentation, so that your developer can make it live with code. A good developer has very well future vision and he/she develop website and applications which can be accommodate many of future changes and updates.

Never miss an update from us. Join 10,000+ marketers and leaders.

So, don’t be so aggressive or hurry while you are hiring someone. Here in this article we will cover the core things of a developer before or at the time of hiring.

1. Technical Expertise:

A PHP developer must have wide knowledge on various technical aspects like content management systems (CMS), Java Script, HTML/HTML5, CSS/CSS3 and Ajax etc and should have exposure to the latest technology trends. Must have expertise in understanding your requirements.

As a webmaster or entrepreneur you must have goal and what you want to implement in your website or application, but don’t know the exact time frame, budget and scope of work. In this situation an experience developer can be of help and can manage within your budgets.

No doubt you will get thousand of PHP Development Company in Google search but choosing the right one is the key; you can measure them from their previous works.

2. Industrial Knowledge

An ideal PHP developer expected to be on top of the latest technology trends relating to website designing, development and industry experience. Your developer must be aware about, what is going on the industry and how to catch or impress the target audience. Attractive, friendly and engaging information are much needed to grab the attention of users for eCommerce or any other websites.

3. Time Management

Time Management in delivering projects within a specific time frame is one of the most important skills of a good PHP developer. Managing time not only delivers quality output but also estimating and setting up expectation is of most important. This helps keeping up a brand name of company. Sometimes developers handle multiple projects at same time and fail to meet the expectation.

4. Work Portfolio

It’s very important for you to check the PHP Developer company portfolio or previous PHP work before planning to take PHP development service. Portfolio gives clear picture about developer’s previous work and how good are they in the domain.

5. Communication

Communication is the way to represent your thoughts. A good developer must be a good listener and speaker also. Communication with good temperament, understanding the requirement and justifying the action are signs of a developer.

6. Ability to learn Quick and adopting new challenges

A good developer is always a self learner. They do research to get alternative solutions for your specs. If you ask questions to them, you can find they are very much open to adopt or learn the new technologies. Another quality is if he is able to use the researches in the implementations. In such cases you can consider that you’re going with right guy.

7. Work and Hiring Process

Each company’s working process of and hiring developers are different from other and based on a specific model. You need to get idea on their development process and communication options before hiring developers to get good results.

At Andolasoft we follow agile methodology and our flexible engagement models have been designed keeping the exact need of the prospects in mind.

I’ve worked with the team at Andolasoft on multiple websites. They are professional, responsive, & easy to work with. I’ve had great experiences & would recommend their services to anyone.

Ruthie Miller, Sr. Mktg. Specialist

Salesforce, Houston, Texas

LEARN MORE

We have three different engagement models to hire our PHP developers,

  • Dedicated Developers – You can hire single or multiple full-stack developers to work in your project dedicatedly according to your requirement,
  • Fixed-bid – You can hire developers when your requirements with each module and tasks are clearly outlined.
  • Time & Material–You can hire developers, when project’s scope and specification cannot be defined from the beginning but the requirements keep on changing as the development progresses.

Conclusion:

The demand of PHP developers are growing and it’s completely upto you to choose the right developer and company among the growing numbers. Some companies are still adopting traditional model in their work process and some are adopting new. We at Andolasoft are adopting the best models for you.

Are you looking to hire PHP Developer! Consult Now

Whether it may eCommerce shopping carts development, CMS Development, or CRM Application development, we are the best PHP development company to fulfill your business needs.

How To Access Remote Amazon RDS With PHPMyAdmin

Amazon Relational Database Service (Amazon RDS) is a web service that makes it easy to set up, operate, and scale a relational database in the cloud. It provides cost-efficient and resizable capacity while managing time-consuming database management tasks, freeing you up to focus on your applications and business.

First of all we need to install PHPMyAdmin in ec2 instance (CentOS, Fedora, Amazon Linux AMI)

Step:1

First we need to enable the RPMforge repository on our CentOS system as PHPMyAdmin is not available in the official CentOS/Fedora/Amazon Linux AMI repositories:

Import the RPMforge GPG key:

# rpm --import  http://dag.wieers.com/rpm/packages/RPM-GPG-KEY.dag.txt

On x86_64 systems:

#  yum install http://pkgs.repoforge.org/rpmforge-release/rpmforge-release-0.5.2-2.el6.rf.x86_64.rpm

On i386 systems:

# yum install http://pkgs.repoforge.org/rpmforge-release/rpmforge-release-0.5.2-2.el6.rf.i686.rpm

Step:2

PHPMyAdmin can now be installed as follows:

# yum install phpmyadmin

Step:3

Now, we configure PHPMyAdmin. We change the Apache configuration so that PHPMyAdmin allows connections not just from localhost (by commenting out the <Directory “/usr/share/phpmyadmin”> stanza):

vi /etc/httpd/conf.d/phpmyadmin.conf
#
# Web application to manage MySQL
#
 
#<Directory "/usr/share/phpmyadmin">
# Order Deny, Allow
# Deny from all
# Allow from 127.0.0.1
#</Directory>
 
Alias /phpmyadmin /usr/share/phpmyadmin
Alias /phpMyAdmin /usr/share/phpmyadmin
Alias /mysqladmin /usr/share/phpmyadmin

Step:4

Next, we change the authentication in PHPMyAdmin from cookie to http: and host from local to RDS host url:

vi /usr/share/phpmyadmin/config.inc.php
[...]
/* Authentication type */
$cfg['Servers'][$i]['auth_type'] = 'http';
[...]
/* Server parameters */
$cfg['Servers'][$i]['host'] = '*******.******.us-east-1.rds.amazonaws.com';

Step:5

Restart Apache service:

# /etc/init.d/httpd restart

Step:6

Now we can browse RDS database.

# http://<IPADDRESS> /phpmyadmin

Or

# http://<Domain name>/phpmyadmin

Advantages Of PHPMyAdmin Over Command line Interface.

  • One of the advantages of using PHPMyAdmin is that it has a user interface and you can run queries within the SQL.
  • It is also used in checking referential integrity in MyISAM tables.
  • One can execute, edit and bookmark any SQL-statement, even batch-queries (This will work only in the latest version of PHPMyAdmin).
  • Multiple MySQL servers can be managed by PHPMyAdmin.
  • One can export data to various formats: CSV, SQL, XML, Excel and more.
  • Using Query-By-Example(QBE), create complex queries automatically connecting required tables.
  • One can Browse, view and drop databases, tables, views, fields and indexes.
  • It supports InnoDB tables and foreign keys.

Also See: How to install and configure Jaspersoft in Linux Server(RHEL/Centos/Fedora)

I hope you will find this useful. Feel free to give your valuable feedback.

If you want to update your traditional IT infrastructure to cloud computing, then you can hire expert cloud engineers from Andolasoft.

How To Do Custom Pagination In CakePHP

Sometimes we need to do pagination in CakePHP using a traditional SQL query, thereby the CakePHP predefined pagination functionality is lost.

We can implement pagination method in the Model or Behavior when we are using standard SQL query in CakePHP. Just need to make sure that the result cannot be obtained with core model methods, or a custom finder before implementing custom queries pagination.

But we can’t just use the standard pagination on the custom queries, we have to override the paginate functions in model or behavior.

To use our own method/logic to override the CakePHP pagination in the model, we need to add two functions: paginate() and paginateCount().

In these functions, we can implement our own paginate logic.

Overriding paginate() function in CakePHP Post Model:

[php]public function paginate($conditions, $fields, $order, $limit, $page = 1, $recursive = null, $extra = array()) {
$orderStr = ”;
foreach($order as $k =&amp;amp;amp;amp;amp;amp;amp;amp;amp;amp;amp;amp;amp;amp;amp;amp;amp;amp;amp;gt; $ord) {
$orderStr[] = $k . ‘ ‘ . $ord;
}
$orderStr = ‘ORDER BY ‘. implode(‘, ‘, $orderStr);

$qryCond = ‘1’;
if (isset($conditions[‘Post.title LIKE’])) {
$qryCond = ‘title LIKE \”.$conditions[‘Post.title LIKE’].’\”;
}

$qryFlds = ‘*’;
if ($fields) {
$qryFlds = implode(‘, ‘, $fields);
}

$sql = ‘SELECT ‘.$qryFlds.’ FROM posts as Post WHERE ‘.$qryCond.’ ‘.$orderStr . ‘ LIMIT ‘ . (($page-1) * $limit) . ‘, ‘ . $limit;
$results = $this-&amp;amp;amp;amp;amp;amp;amp;amp;amp;amp;amp;amp;amp;amp;amp;amp;amp;amp;amp;gt;query($sql);
return $results;
}[/php]

Overriding paginateCount() function in CakePHP Post Model:

[php]public function paginateCount($conditions = null, $recursive = 0, $extra = array()) {
$qryCond = ‘1’;
if (isset($conditions[‘Post.title LIKE’])) {
$qryCond = ‘title LIKE \”.$conditions[‘Post.title LIKE’].’\”;
}

$sql = ‘SELECT COUNT(*) as count FROM posts as Post WHERE ‘.$qryCond;

$this-&amp;amp;amp;amp;amp;amp;amp;amp;amp;amp;amp;amp;amp;amp;amp;amp;amp;amp;amp;gt;recursive = -1;

$results = $this-&amp;amp;amp;amp;amp;amp;amp;amp;amp;amp;amp;amp;amp;amp;amp;amp;amp;amp;amp;gt;query($sql);
return $results[0][0][‘count’];
}[/php]

Using in the Post Controller: We can adjust the fields to get, column ordering, add certain conditions or adjust row limit per page.

[php]public function index() {
$this-&amp;amp;amp;amp;amp;amp;amp;amp;amp;amp;amp;amp;amp;amp;amp;amp;amp;amp;amp;gt;paginate = array(
‘limit’ =&amp;amp;amp;amp;amp;amp;amp;amp;amp;amp;amp;amp;amp;amp;amp;amp;amp;amp;amp;gt; 10,
‘fields’ =&amp;amp;amp;amp;amp;amp;amp;amp;amp;amp;amp;amp;amp;amp;amp;amp;amp;amp;amp;gt; array(‘Post.id’, ‘Post.title’, ‘Post.created’),
‘conditions’ =&amp;amp;amp;amp;amp;amp;amp;amp;amp;amp;amp;amp;amp;amp;amp;amp;amp;amp;amp;gt; array(‘Post.title LIKE’ =&amp;amp;amp;amp;amp;amp;amp;amp;amp;amp;amp;amp;amp;amp;amp;amp;amp;amp;amp;gt; ‘%search_keyword%’),
‘order’ =&amp;amp;amp;amp;amp;amp;amp;amp;amp;amp;amp;amp;amp;amp;amp;amp;amp;amp;amp;gt; array(‘Post.title’ =&amp;amp;amp;amp;amp;amp;amp;amp;amp;amp;amp;amp;amp;amp;amp;amp;amp;amp;amp;gt; ‘asc’, ‘Post.id’ =&amp;amp;amp;amp;amp;amp;amp;amp;amp;amp;amp;amp;amp;amp;amp;amp;amp;amp;amp;gt; ‘asc’)
);
try {
$this-&amp;amp;amp;amp;amp;amp;amp;amp;amp;amp;amp;amp;amp;amp;amp;amp;amp;amp;amp;gt;set(‘posts’, $this-&amp;amp;amp;amp;amp;amp;amp;amp;amp;amp;amp;amp;amp;amp;amp;amp;amp;amp;amp;gt;paginate(‘Post’));
} catch (NotFoundException $e) {
$this-&amp;amp;amp;amp;amp;amp;amp;amp;amp;amp;amp;amp;amp;amp;amp;amp;amp;amp;amp;gt;redirect(‘index_custom’);
}
}[/php]

The above example is based on specific model and requirement, need to adjust the methods according to the requirements.

See Also: Creating a custom handler session in CakePHP 2.x

Best of luck and happy pagination.

Hope you liked this. Let me know if you want to add anything?

How To Setup CakePHP DataSource For Solr?

Imagine that you have millions of data and your SQL database is not optimized enough to handle them, then “Solr” is your best data source. Apache Solr is a fast search platform. It’s major features include full-text search faceted search, dynamic clustering, database integration, rich document handling. Solr is highly scalable and it is the most popular enterprise search engine.

This document will guide you through DataSource setup for Solr in CakePHP. Set-up the Solr DataSource in CakePHP and query Solr with your CakePHP model “find” function, just similar to querying any other SQL database.

/app/Config/database.php:

Configuring your the DataSource for Solr database connection:

  • host: Solr server address.
  • port: Solr server port.
  • datasource: This should match with your DataSource at /app/Model/Datasource/SolrSource.php

[php]class DATABASE_CONFIG {
public $solr = array(
‘datasource’ =&amp;amp;amp;gt; ‘SolrSource’,
‘host’ =&amp;amp;amp;gt; ‘192.168.2.131’,
‘port’ =&amp;amp;amp;gt; ‘9983’,
‘path’ =&amp;amp;amp;gt; ‘/solr/’
);
}[/php]

/app/Model/Solr.php:

Use the database config in your models like:

[php]class Solr extends AppModel {
 public $useTable = false;
 public $useDbConfig = ‘solr’;
 }[/php]

/app/Model/Datasource/SolrSource.php:

Below code describes only the most required functions.

  • You can find other required functions at http://book.cakephp.org/2.0/en/models/datasources.html
    Like: calculate($model, $func, $params) and others create(), update(), delete().
  • Below DataSource only implements read() function.
  • Create a file called SolrSource.php and use below code:

[php]App::uses(‘HttpSocket’, ‘Network/Http’);
require_once($_SERVER[‘DOCUMENT_ROOT’].’/root_folder/app/Vendor/Apache/Solr/Service.php’);
class SolrSource extends DataSource {

protected $_schema = array();
protected $_host;
protected $_port;

public function __construct($config){
parent::__construct($config);
$this-&amp;amp;amp;gt;Http = new HttpSocket();

$this-&amp;amp;amp;gt;host = $config[‘host’];
$this-&amp;amp;amp;gt;port = $config[‘port’];
$this-&amp;amp;amp;gt;_schema = $config[‘path’];

$this-&amp;amp;amp;gt;solr=new Apache_Solr_Service($this-&amp;amp;amp;gt;host, $this-&amp;amp;amp;gt;port, $this-&amp;amp;amp;gt;_schema);
}

public function read(Model $model, $queryData = array(), $recursive = null) {
$results = array();
$query = $queryData[‘conditions’][‘solr_query’];
if (Configure::read(‘log_solr_queries’) === true) {
CakeLog::write(‘debug’, $query); /* Logs the solr query in app/tmp/logs/debug.log file */
}

try {
$solr_docs = $this-&amp;amp;amp;gt;solr-&amp;amp;amp;gt;search($query, $queryData[‘offset’], $queryData[‘limit’], array(‘sort’ =&amp;amp;amp;gt; $queryData[‘order’]));
} catch (Exception $e) {
CakeLog::write(‘error’, $e-&amp;amp;amp;gt;getMessage()); /* Logs the solr errors message in app/tmp/logs/error.log file */
CakeLog::write(‘error’, $query); /* Logs the solr query in app/tmp/logs/error.log file */
}
$model-&amp;amp;amp;gt;params = $solr_docs-&amp;amp;amp;gt;responseHeader-&amp;amp;amp;gt;params;
$model-&amp;amp;amp;gt;numFound = $solr_docs-&amp;amp;amp;gt;response-&amp;amp;amp;gt;numFound;
$docs = $solr_docs-&amp;amp;amp;gt;response-&amp;amp;amp;gt;docs;
foreach ($docs as $doc) {
$document = array();
foreach ($doc as $fieldName =&amp;amp;amp;gt; $fieldValue) {
$document[$fieldName] = $fieldValue;
}
$results[] = $document;
}
return array($model-&amp;amp;amp;gt;alias =&amp;amp;amp;gt; $results);
}
}[/php]

/app/Controller/UsersController.php:

Getting data from Solr server by using above SolrSource.

[php]App::uses(‘AppController’, ‘Controller’);
class UsersController extends AppController {

public $name = ‘Users’; //Controller name
public $uses = array(‘Solr’); //Model name

function beforeFilter(){
parent::beforeFilter();
$this-&amp;amp;amp;gt;Auth-&amp;amp;amp;gt;allow(‘index’);
}

public function index(){
$cond = "active:1";
$sort = "timestamp desc";

$params = array(
‘conditions’ =&amp;amp;amp;gt;array(
‘solr_query’ =&amp;amp;amp;gt; $cond
),
‘order’ =&amp;amp;amp;gt; $sort,
‘offset’ =&amp;amp;amp;gt; 0,
‘limit’ =&amp;amp;amp;gt; 1
);

$result = $this-&amp;amp;amp;gt;Solr-&amp;amp;amp;gt;find(‘all’, $params);
$this-&amp;amp;amp;gt;layout = ‘ajax’;
header(‘Content-Type: application/json; charset=utf-8’); /* To send response in json format */
echo json_encode($result);
die;
}
}[/php]

See Also : How to use ‘neighbors’ with ‘find’ method

Debugging:

The above code has been tested and validated with CakePHP 2.2.3, PHP 5.3.1 .
Incase you face any problems:

  • First check the DataSource configuration in /app/Config/database.php.
  • Check /app/Model/Solr.php for this line: public $useDbConfig = ‘solr’;
  • Make sure Solr Service Vendor loaded in /app/Model/Datasource/SolrSource.php.
  • Check the path is correct for the Solr vendor.

Hope you liked this. Let me know if you want to add anything?