Why PHP Web Development Is Top Priority For Developers

Any company that wants to succeed must maintain a robust digital presence because the world is more digitally connected than ever. And, it is not possible to create a strong brand image without a good website.

PHP Programming  language is a server side language. Whenever a new programming language is developed the demand for PHP comes to an end. It is true that the PHP language does not remain on the top list of top programming languages, from 5th position in 2017 to 8th position to 2020 as per a survey by Stack Overflow annual developer.

Also PHP continues to be used for 80% of all websites. However, it is the best language for website development.

PHP Market Position

To meet this end, businesses hire web development services. Many technologies are being used in developing websites today. A lot of developers prefer to use PHP website development because it offers numerous benefits.

Why PHP is used in web development?

PHP allows developers to create dynamic and interactive websites. PHP is a server-side scripting language used for developing fast and reliable websites and web apps. 

The following are the reasons why developers prefer PHP for web development.

Time to Development

When adopting any technology for web development, the cost and development time are the important considerations to make the right choice. Thus cutting down on the cost and development time is on priority to make an informed decision.

Failure in this aspect is the key reason for project delays in schedules. To cut down on development time, developers choose specific technologies like PHP that enable them to work efficiently and deliver top-notch solutions.

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

PHP gives an edge in web development for particular areas. 

PHP Frameworks

Many PHP frameworks are there to build feature-rich and complex web applications. Laravel, CakePHP, and CodeIgniter are some of the top PHP web development frameworks. Developers use these frameworks to build top-notch websites or web applications for their clients in a simple way. These frameworks follow MVC (Model, View, Controller) approach that simplifies the coding process.

With this approach, the presentation layer is separated from the business logic. Consequently, the web development process is faster and streamlined. Hence, when it comes to speeding up the development process, PHP web development services provide many advantages. 

Versatile:

With the use of PHP you can get many benefits one such benefit is that the platform is independent, which means it can be used on Mac OS, Linux, Windows and supports other web servers.

This feature makes the use of PHP easy to deploy on various systems and platforms with some additional cost

Easy to Learn

Another thing responsible for making the PHP language attractive to developers is that it is easy to learn. It does not require a large number of learning materials or reference resources to get proficient in this language.

With some moderate efforts, developers can get a good hang of it and create the desired solutions for clients. So, the ease of learning and usage has also made it a popular technology for developers worldwide.

Developers accustomed to other programming languages may find learning PHP easier than they think. It is the reason why PHP developers are in high demand. 

Open-source Technology

PHP is an open-source server-side scripting language. The open-source nature of this technology makes it a sought-after solution for various projects.

Being an open-source tech, it is available for free and can be used for a dynamic range of web development projects. PHP developers are available easily, and a business can hire PHP developer to create unmatched solutions.

PHP’s open-source implementation is unparalleled to other similar languages. Since it is available for free, it is accessible to many companies and individuals who would not otherwise consider using any different language. For many people, PHP is the most widely used general-purpose language. 

Support & Community

It is always wise to choose a web development technology that comes with a community to help grow and address issues. So, the technologies with more wikis, tutorials, and active forums are more popular than those without these kinds of support.

PHP has a large community that is actively involved in the growth of this language as well as addressing the issues of existing or new users. With this robust support system, developers find PHP a beneficial solution for any website development project.

Community support is quite beneficial in development, maintenance, and keeping the web solution up and running. 

Cost-effective Technology

When people think about why PHP is a priority for many developers for web development, they should also think about the cost. PHP is open-source and free, making it an attractive choice for many businesses to develop their web solutions.

PHP solutions are affordable, and you can even choose low-budget PHP developers for creating a decent web solution. Not only many affordable web solutions are available, but also there are many open-source alternatives. 

Fast and Secure: 

As every organization needs their website or application to be secured and safe. But with the use of PHP in web development, you can save lots of space. As the PHP uses it’s own memory and competes well with the speed, especially with the newer version.

PHP is not inherently less or more secure than other programming languages. One such advantage of PHP is that because of its widespread use and community support, there aren’t many tools, frameworks and best practices that help to fix the vulnerabilities and protest any cyber-attacks.

Support for multiple files types and databases

PHP is handy for using different types of databases, including MySQL, PostgreSQL, MongoDB, Oracle, and more. It offers POD (PHP Data Object) that provides a simple way to connect with various databases and work with them.

Apart from this, it also supports XML besides HTML, JavaScript, and many other file types that unlock a lot of potential for developers to create more than web solutions. 

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

Wrapping up!

As the world is becoming more digitalized, the need of the hour for every business is to set up their online presence to stay competitive and keep growing. When it comes to creating a website, choosing the right technology is very crucial.

PHP is one of the topmost web development technologies that has been used in developing numerous web solutions for a long time. Many developers prefer PHP because of the multiple benefits and features it offers.

Hiring a PHP website development company is also easy because there are plenty of these companies. 

Looking forward to developing your website choose Andolasoft to develop your PHP website from our professional PHP developer.

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!

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 Install, Setup And Implement NodeJS In PHP Application

What Is NodeJS?

Typically in web response paradigm, the client always initiates communication, but with the help of NodeJS now both the client and server can initiate communication, allowing them to exchange data freely.

In simple words, after a database update the client needs to request the server to get the latest data. But using NodeJS, a client can send the updated data to NodeJS and the NodeJS will distribute the data across all the clients. So, no need to initiate request by each client to the server to get the latest data.

Where We Can Use NodeJS?

Below are the few examples where you can get the best out of Node.js,

  • A counter which updates after a record insert into database.
  • Show real-time activity like Twitter or Facebook.
  • Implement Desktop notification to notify users about what others are doing.
  • You can build a chatting tool using the non-blocking, event-driven I/O paradigm of NodeJS

Install And Setup NodeJS

  1. Install NodeJS and NPM
  2. Install socket.io using NPM
  3. Install Forever

Run the below notification.js file forever using the “Forever”. (it should not stop)

notification.js

var fs = require('fs');
/* If you are using SSL, uncomment the below lines*/
/*
var options = {
    key: fs.readFileSync('/var/www/html/YOUR_CERTIFICATE_FOLDER/your_project_key.key'),
    cert: fs.readFileSync('/var/www/html/YOUR_CERTIFICATE_FOLDER/your_project_crt.crt'),
    ca: fs.readFileSync('/var/www/html/YOUR_CERTIFICATE_FOLDER/your_project_ca-bundle.ca-bundle')
};
var app = require('https').createServer(options, handler);
*/

var app = require('http').createServer(handler); // For non-ssl server
var io = require('socket.io').listen(app);
app.listen(3002);
function handler (req, res) {
	res.writeHead(200);
	res.end("Welcome to socket.io.");
}
/** This section is for receiving and sending message **/
var Room;
io.sockets.on('connection', function (socket) {
	socket.on('subscribeTo', function (data) {
		if(Room){
			socket.leave(Room);
		}
		Room = data.channel;
		console.log('Connecting client to: '+data.channel);
		socket.join(data.channel);
	});
	socket.on('iotoserver', function (data) {
		console.log('here we are in action event and data is: \n-----------------------------------------------------');
		//var dataJSON = JSON.parse(data);
		//socket.broadcast.emit(dataJSON.channel, { message: 'A new socket added and sending message.' });
		socket.broadcast.to(data.channel).emit('iotoclient', { message: data.message });
		//io.sockets.in('game').emit('message', 'cool game');
		console.log(data);
	});
});

NOTE: Your Node.js should run with the port “3002”. Try to use another sub-domain/domain to call your Node.js server. Another server is always a good option.

Implement NodeJS In Your Application

Use Elephant.io (a socket.io client) to send message to NodeJS.
Get the ElephantIO package from, https://github.com/Wisembly/elephant.io/tree/master/src
You need the Client.php and the AbstractPayload.php file only.

<?php
use ElephantIO\Client as ElephantIOClient;
include("ElephantIO/Client.php");

$elephant = new ElephantIOClient('http://www.your-node-server.com:3002', 'socket.io', 1, false, false, true);
$elephant->setHandshakeTimeout(1000);
$elephant->init();
$elephant->send(
ElephantIOClient::TYPE_EVENT, null, null, json_encode(array('name' => 'iotoserver', 'args' => array('channel' => 'my_first_channel', 'message' => 'my message to all the online users')))
	);
$elephant->close();
?>

Put this JavaScript in the page, where you want to receive the real-time notification

<script src="http://cdnjs.cloudflare.com/ajax/libs/socket.io/0.9.16/socket.io.min.js"></script>
<script>
try{
  var client = io.connect('http://www.your-node-server.com:3002');
  
  client.on('connect',function (data) {
  	client.emit('subscribeTo', { channel: 'my_first_channel' });
  });
  
  client.on('iotoclient', function (data) {
    alert(data.message);
  });
} catch(e){
	console.log('Socket ERROR\n');
	console.log(e);
}
</script>

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

Are you looking to Install, setup and implement NodeJS in your PHP application? We are here to help you. We have experienced NodeJS developers to provide all types of JavaScript solutions. Let’s discuss

Like this blog? I’d love to hear about your thoughts on this. Thanks for sharing your comments.

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 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?