Hash Class: Makes CakePHP Coding easier!

Hash is a predefined class provided by CakePHP. It is used for array manipulation such as inserting an element to an array, remove an element from an array, sort an array, extract part of a large array, filter the non empty elements, rearrange the whole array, which makes the code more optimized and understandable. So it makes CakePHP easier and flexible to use. Because most of the operations like find, insert, update in CakePHP returns/takes array as output/input.

Hash provides an improved interface, more consistent and predictable set of features over Set. While it lacks the spotty support for pseudo XPath, its more fully featured dot notation provides similar features in a more consistent implementation.

Operations performed by Hash class:

  • extract()
  • combine()
  • filter()
  • check()
  • insert()
  • remove()
  • sort()
  • and many more…

Some Important Tips:

{n} – Match any numeric key.
{s} – Match any string value and numeric string values.
[id] – Matches elements with a given array key.
[id=2] – Matches elements with id equal to 2.
[id!=2] – Matches elements with id not equal to 2.
[id<=2] – Matches elements with id less than or equal to 2.

– Matches elements that have values matching the regular expression inside.

  • Hash::extract(array $data, $path):

Retrieve required data from array. You do not have to loop through the array.

Ex: // Common Usage:

$users = $this->User->find("all");
 $results = Hash::extract($user, '{n}.User.id');
 // $results equals:
 // array(1,2,3,4,5,...);
  • Hash::insert(array $data, $path, $values = null):

Insert sub-array’s into the original array.

Ex:

$temp = array(
 'page' => array('name' => 'page')
);
$result = Hash::insert($temp, 'file', array('name' => 'files'));
// $result now looks like:
Array
(
 [page] => Array
 (
 [name] => page
 )
 [file] => Array
 (
 [name] => files
 )
)
  • Hash::remove(array $data,  $path = null):
Remove data from any path specified.

EX:

$arr_test = array(
 'page' => array('name' => 'page'),
 'file' => array('name' => 'files')
);
$result = Hash::remove($arr_test, 'file');
/* $result now looks like:
 Array
 (
 [page] => Array
 (
 [name] => page
 )
 
)
*/
  • Hash::combine(array $data$keyPath = null$valuePath = null$groupPath = null)

Combine the results to form a new array of expected result. Helpful in case, where we are displaying data in the form of select box. Like categories, states, city etc. We don’t have to retrieve the data separately. We can find the required data from the original result set retrieved, containing the information..

Ex:

$arr_test = array(
 array(
 'User' => array(
 'id' => 2,
 'group_id' => 1,
 'Data' => array(
 'user' => 'John.doe',
 'name' => 'Matt Lee'
 )
 )
 ),
 array(
 'User' => array(
 'id' => 14,
 'group_id' => 2,
 'Data' => array(
 'user' => 'phpunt',
 'name' => 'Jack'
 )
 )
 ),
);
 
$result = Hash::combine($arr_test, '{n}.User.id', '{n}.User.Data');
/* $result now looks like below:
 Array
 (
 [2] => Array
 (
 [user] => John.doe
 [name] => Matt Lee
 )
 [14] => Array
 (
 [user] => phpunt
 [name] => Jack
 )
 )
*/
  • Hash::check(array $datastring $path = null)
    Check whether an element exists in the array or not.

Ex:

$set = array(
 'My Index' => array('First' => 'The first item1')
);
$result = Hash::check($set, 'My Index.First');
// $result == True
  • Hash::filter(array $data$callback = array(‘Hash ‘‘Filter’)):
Keep only non-empty elements and filter the empty elements.
Ex:
$data_arr = array(
 '0',
 false,
 true,
 0,
 array('test', 'is you own', false)
);
$result = Hash::filter($data_arr);
 
/* Out put:
 Array (
 [0] => 0
 [2] => true
 [3] => 0
 [4] => Array
 (
 [0] => one thing
 [2] => is you own
 )
 )
*/
  • Hash::sort(array $data$path$dir$type = ‘regular’)

Sort an array according to the path, direction and type provided.

Ex:

$arr_test = array(
 0 => array('Person' => array('name' => 'Jeff1')),
 1 => array('Shirt' => array('color' => 'black1'))
);
$result = Hash::sort($arr_test, '{n}.Person.name', 'asc');
/* $result now looks like:
 Array
 (
 [0] => Array
 (
 [Shirt] => Array
 (
 [color] => black1
 )
 )
 [1] => Array
 (
 [Person] => Array
 (
 [name] => Jeff1
 )
 )
 )
*/

$type can be of the following type:

regular
numeric
string
natural(ex. Will sort fooo10 below fooo2 as an example)

$dirc can be of two type asc & desc

For more information refer: http://book.cakephp.org/2.0/en/core-utility-libraries/hash.html

However if you want you can hire or get free consultation from our experienced CakePHP developers.

Read More: Password Hashing API in PHP

Have I missed out anything? Comment at end of this topic.

CakePHP: How To Use ‘neighbors’ With ‘find’ Method

CakePHP ‘find’ method makes it easier to retrieve data from database. The ‘find’ method can be used to construct anything from extremely simple queries to more complex ones without writing much code. This method can handle most SQL type requests and can be extended for more specific SQL queries.  I will walk you through the below example about the basics of working with the ‘find’  method

Here Are Some Inbuilt Types in CakePHP

  1. $this->Model->find(‘all’,$condition);
  2. $this->Model->find(‘first’,$condition);
  3. $this->Model->find(‘count’,$condition);
  4. $this->Model->find(‘list’,$condition);
  5. $this->Model->find(‘neighbors’,$condition);
  6. $this->Model->find(‘threaded’,$condition);

First four types are the most commonly used in CakePHP
Now, let’s take a look at an example of ‘neighbors’ type

Example

Let’s assume QuizQuestion is your model and you want to fetch the previous and next entries

Your Controller/action will look like,

public function getNeighbors($id){
 
$this->QuizQuestion->id = $id;
 
$neighbors = $this->QuizQuestion->find('neighbors',array('fields'=>array('id','question_no','description')));
}

A couple of queries will be generated in SQL as,

Query: SELECT 'QuizQuestion'.'id', 'QuizQuestion'.'question_no', 'QuizQuestion'.'description',
'QuizQuestion'.'id' FROM 'quiz_questions' WHERE 'QuizQuestion'.'id' < 38   ORDER BY
'QuizQuestion'.'id' DESC  LIMIT 1
Query: SELECT 'QuizQuestion'.'id', 'QuizQuestion'.'question_no', 'QuizQuestion'.'description',
'QuizQuestion'.'id' FROM 'quiz_questions' WHERE 'QuizQuestion'.'id' > 38   ORDER BY
'QuizQuestion'.'id' ASC  LIMIT 1

Here’s the output

Array
(
[prev] => Array
(
[QuizQuestion] => Array
(
[id] => 37
[question_no] => 1
[description] => Mathematics
)
 
)
[next] => Array
(
[QuizQuestion] => Array
(
[id] => 39
[question_no] => 3
[description] => Mathematics
)
 
)
 
)

Voila! Using the result keys ‘prev’ and ‘next’ you can view the results the way you want.

Orangescrum Premium Plan is Live Today!

orangescrum_signup-300x147We are excited to announce that the Orangescrum Premium Plan is gone LIVE today. The beta testing is over successfully. Today, Orangescrum is open for individuals, small businesses and enterprises. It’s an efficient Project Collaboration Tool that gives you full visibility and control over your projects. It is an agile project management tool for perfect team collaboration, project tracking, document sharing and a discussion board for the team.

Inside Orangescrum:

Orangescrum offers all the basic features you need to smooth running of your project.

Here are some key highlights of Orangescrum:

  • Create/Assign/Track Tasks
  • Project & Team Collaboration
  • Secured File sharing using Google Drive and DropBox
  • Get conversations under single thread
  • Faster communication with Email Notification
  • Create & Track Milestones
  • Respond via email/mobile
  • Observe activities on a single page
  • Can be used as a Bug/Issue Tracker/Ticketing system

Pricing:

Orangescrum pricing is simple and flexible; pay-as-you-go and no long term obligations.
Orangescrum is available rightaway in Basic, Premium and Enterprise Editions. For more information visit Orangescrum at,

http://www.orangescrum.com/pricing

sign-up-btn

 

The 10th Best CakePHP Web-App Development Company in The World

Today, we are thrilled to announce that Andolasoft is named at #10 in the Top 10 CakePHP Development Companies by bestwebdesignagencies.com.

We pledge this success to our customers for their continuous support which has brought us such laurels. We are pleased that our team of expert CakePHP developers, project management, and testing have done their job to perfection yet again.

Our Comprehensive Range of CakePHP Development Services

  • Custom PHP Web Development
  • PHP-Based CMS Development
  • PHP-Based eCommerce Development
  • PHP Migration Services
  • PHP Web-App Maintenance Services
  • PHP API & Plugin Development
  • PHP-Based Web Product Development

Key Solutions We Provide to Mitigate Customer Challenges

  • We offer full-stack CakePHP developers who create a seamless integration of front-end and back-end services to deliver a consistent user experience
  • Our expert team of developers provide high-level of customization both in terms of user-experience, user-interface and app-functionalities.
  • We employ the highest level of security measures to ensure our client’s and end-users’ data remain secure.
  • We follow an agile development process to craft PHP solutions in an iterative and incremental process.
  • Our team members are well-versed in using light-weight plugins to optimize web-performance.
  • Customers can collaborate with our team members and project managers on Orangescrum project collaboration tools.
  • We offer the quickest turnaround customer support during all stages of product development.

Why Brand Around the World Choose Andolasoft for CakePHP Web-App Development

Client-Friendly Approach

Our development team and project managers are approachable and easy-to-talk-to. They keep the atmosphere light and friendly when communicating with clients on project requirements.

Latest Tools and Technologies

Our team always keeps themselves updated with the latest tools and technologies giving our customers the winning-edge by crafting a solution that is more updated, secure and optimized.

Agile Development Model

We follow Agile methodology to develop solutions in an interactive and incremental manner which enables our team members to keep publishing various modules of the product faster.

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

Why parallax scrolling is in trend?

It keeps our development process open to new changes and modifications.

Comfortable to work in your Time zone

We have dedicated developers who can work on your time zone and develop solutions exclusively for our clients.

Maintenance & QA

Out QA cover 100% of the modules, features and functionalities developed to ensure the credibility of the product developed. We leave no stone unturned and ensure that the product developed meets your business and functional requirements.

Quickest Turnaround Customer Support

Andolasoft has the quickest turnaround customer support. We reach out to our customers faster to resolve their queries and issues during all stages of our partnership.

No Hidden Cost

We charge only for the services we offer as defined while signing the NDA. We don’t surprise you with any hidden cost after delivery of your project.

Flexible Hiring Models

Our customers have the option to work with us by hiring our team of developers and designers on a per-hour basis or hire dedicated developers who will work exclusively on customer projects in their time zone.

Track Your Projects Through PM Tool

You can track the progress of your projects using Orangescrum PM tool.

Are you looking for a CakePHP developer

Contact Us

We keep our customers in the loop and keep updating them at every step of the development lifecycle.

What Factors Helped Us:

      • The development of CakePHP web-apps based on MVC architecture
      • Re-usability of code to develop robust apps in less time
      • Rapid web-app development with Agile methodology
      • Search engine friendly CakePHP apps
      • Secure apps with a logical separation of data, business logic, and design
      • Strong security measures to keep application data secured
      • Social Media, Payment gateway and other API integration to our web-apps
      • Best Practices Followed
      • On-time delivery
      • Faster Communication
      • Quick turnaround Support

Conclusion

The bestwebdesignagencies.com is an autonomous body that identifies and lists out the best design and development companies in the world. The purpose is to help customers to find the right ones in the industry. They adopt a stringent evaluation process to determine the quality of work delivered by each company to their customers’ satisfaction.

An Introduction Of PHP Frameworks Guides For Developers

A framework is a structure that developers choose to build their application. It determines the structure of the application and facilitates it to connect with many different API’s. A proficient PHP framework enables developers to develop PHP application faster, efficiently and assist in building stable applications thereby reducing the amount of repetitive coding for PHP programmers.

Frameworks provide scaffolding features that facilitates the development team to build faster and cleaner application. They often provide tool sets for both the UI components and the database access.

Note: It is advisable to use the latest stable version of a framework.

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

Here are few aspects of a proficient PHP framework:

MVC Architecture:

  • The framework should make use of Model View Controller (MVC) architecture. Some of the best frameworks also provide libraries, plug-ins, helpers, and extensions to assist developers. It would be smart and efficient to employ a framework that has at least two of these options.

Database Support:

  • It is one of the most crucial aspects of every PHP development framework. You need decide your framework depending on the database you are going to use for your web application.

For Example:  ‘CodeIgniter’ supports MySQL, Oracle, and SQLite, whereas the ‘Kohana’ framework doesn’t.

Community & Documentation:

  • The framework should be supported by a strong community, not just in terms of size but also in terms of activity and usefulness. Even if it’s a small community, you should be able to get ample support from the community.

A PHP framework should also have good documentation. It should be comprehensive and up-to-date.

Below, I have provided a list of some popular and commonly used PHP frameworks.

CakePHP 2.x:

  • CakePHP is a rapid development framework for PHP. It’s a foundational structure for programmers to create web applications. CakePHP has an active developer team and community, bringing great value to the project. It is also the most preferred development framework.

        Source:http://book.cakephp.org/2.0/en/index.html

Symfony 2.x:

  • Speed up the creation and maintenance of your PHP web applications. Replace the repetitive coding tasks by power, control and pleasure.

        Source: http://symfony.com/

CodeIgniter 2.x:

  • CodeIgniter is a powerful PHP framework with a very small footprint, built for PHP coders who need a simple and elegant toolkit to create full-featured web applications.

         Source: http://ellislab.com/codeigniter

Zend Framework 2:

  • It is an open source framework for developing web applications and services using PHP 5.3+. Zend Framework 2 uses 100% object-oriented code and utilizes most of the new features of PHP 5.3, namely namespaces, late static binding, lambda functions and closures.
  • Zend Framework 2 evolved from Zend Framework 1, a successful PHP framework with over 15 million.

        Source: http://framework.zend.com

Yii Framework 1.1.x:

  • Yii comes with rich features: MVC, DAO/ActiveRecord, I18N/L10N, caching, authentication and role-based access control, scaffolding, testing, etc. It will reduce your development time significantly.

        Source: http://www.yiiframework.com

Kohana 3.x:

  • An elegant HMVC (Hierarchical model–view–controller) PHP5 framework that provides a rich set of components for building web applications.

        Source: http://kohanaframework.org/

FuelPHP:

  • It is a simple, flexible, community driven PHP 5.3+ framework, based on the best ideas of other frameworks.

        Source: http://fuelphp.com/

There are a number of PHP development frameworks in the market which enables the development team to do more with the programming language. Development frameworks makes coding for PHP more manageable and programmers can take its advantage by making use of a convenient development framework.

SSL Authentication Using Security Component In CakePHP

We can achieve SSL authentication in CakePHP by writing own methods like ‘forceSSL’ and ‘unforceSSL’. Also there is an in-built Security Component in CakePHP to achieve SSL authentication.

  • Using Security Component we can integrate tighter security in our application.
  • Like all components it needs configurations through several parameters.
  • We can get CSRF and form tampering protection using Security Component.
  • CsrfExpires controls the form submission.

Example:

All SSL URLs will redirect to a sub-domain ‘https://app.andolacrm.com/’ and the non SSL URL will redirect to a sub-domain ‘http://www.andolacrm.com’

How To Use Security Component

  • Include the security component in you AppControler.php
  •  Like as below

[sourcecode]class AppController extends Controller {
public $components =array( ‘Acl’,’Session’,’Email’,’Security’,’Cookie’ );

}[/sourcecode]

  • There are 3 configurable variable for which you need to set the values as per the requirement of your application in the beforeFilter functions of AppController.php
  • validatePost:

This variable basically used to validate your post data. Set false if you want skip validating you post data or in case data coming from 3rd party Services. Default its true.

  • csrfCheck :

CSRF(Cross-Site_Request_Forgery)  Used for form protection   . Set to false to skip CSRF protections.

  • CsrfUseOnce :

This is used for CSRF token.If it is set as false then it will user one csrf token through out the application else it will generate new token for each form submissions.

Sample Code :

[sourcecode]function beforeFilter() {
// Codes added for SSL security
$this-&amp;amp;amp;amp;amp;amp;amp;amp;amp;amp;amp;amp;amp;amp;amp;amp;amp;amp;amp;amp;amp;amp;amp;amp;amp;amp;amp;amp;amp;amp;amp;amp;amp;amp;gt;Security-&amp;amp;amp;amp;amp;amp;amp;amp;amp;amp;amp;amp;amp;amp;amp;amp;amp;amp;amp;amp;amp;amp;amp;amp;amp;amp;amp;amp;amp;amp;amp;amp;amp;amp;gt;validatePost=false;
$this-&amp;amp;amp;amp;amp;amp;amp;amp;amp;amp;amp;amp;amp;amp;amp;amp;amp;amp;amp;amp;amp;amp;amp;amp;amp;amp;amp;amp;amp;amp;amp;amp;amp;amp;gt;Security-&amp;amp;amp;amp;amp;amp;amp;amp;amp;amp;amp;amp;amp;amp;amp;amp;amp;amp;amp;amp;amp;amp;amp;amp;amp;amp;amp;amp;amp;amp;amp;amp;amp;amp;gt;csrfCheck=false;
$this-&amp;amp;amp;amp;amp;amp;amp;amp;amp;amp;amp;amp;amp;amp;amp;amp;amp;amp;amp;amp;amp;amp;amp;amp;amp;amp;amp;amp;amp;amp;amp;amp;amp;amp;gt;Security-&amp;amp;amp;amp;amp;amp;amp;amp;amp;amp;amp;amp;amp;amp;amp;amp;amp;amp;amp;amp;amp;amp;amp;amp;amp;amp;amp;amp;amp;amp;amp;amp;amp;amp;gt;csrfUseOnce=false;
}[/sourcecode]

  • In the ‘AppController.php’ you need to define the list of URLs that doesn’t need to be checked for SSL

[sourcecode]$sslnotallowed_url=array(‘beta_user’,’terms’,’privacy’,’security’,’display’,’faq’);[/sourcecode]

  • Code to be written in your ‘beforeFilter()’ of ‘AppController.php’

[sourcecode]function beforeFilter() {
// Codes added for SSL security
$this-&amp;amp;amp;amp;amp;amp;amp;amp;amp;amp;amp;amp;amp;amp;amp;amp;amp;amp;amp;amp;amp;amp;amp;amp;amp;amp;amp;amp;amp;amp;amp;amp;amp;amp;gt;Security-&amp;amp;amp;amp;amp;amp;amp;amp;amp;amp;amp;amp;amp;amp;amp;amp;amp;amp;amp;amp;amp;amp;amp;amp;amp;amp;amp;amp;amp;amp;amp;amp;amp;amp;gt;validatePost=false;
$this-&amp;amp;amp;amp;amp;amp;amp;amp;amp;amp;amp;amp;amp;amp;amp;amp;amp;amp;amp;amp;amp;amp;amp;amp;amp;amp;amp;amp;amp;amp;amp;amp;amp;amp;gt;Security-&amp;amp;amp;amp;amp;amp;amp;amp;amp;amp;amp;amp;amp;amp;amp;amp;amp;amp;amp;amp;amp;amp;amp;amp;amp;amp;amp;amp;amp;amp;amp;amp;amp;amp;gt;csrfCheck=false;
$this-&amp;amp;amp;amp;amp;amp;amp;amp;amp;amp;amp;amp;amp;amp;amp;amp;amp;amp;amp;amp;amp;amp;amp;amp;amp;amp;amp;amp;amp;amp;amp;amp;amp;amp;gt;Security-&amp;amp;amp;amp;amp;amp;amp;amp;amp;amp;amp;amp;amp;amp;amp;amp;amp;amp;amp;amp;amp;amp;amp;amp;amp;amp;amp;amp;amp;amp;amp;amp;amp;amp;gt;csrfUseOnce=false;
$sslnotallowed_url&nbsp; = array(‘beta_user’,’terms’,’privacy’,’security’);
$this-&amp;amp;amp;amp;amp;amp;amp;amp;amp;amp;amp;amp;amp;amp;amp;amp;amp;amp;amp;amp;amp;amp;amp;amp;amp;amp;amp;amp;amp;amp;amp;amp;amp;amp;gt;Security-&amp;amp;amp;amp;amp;amp;amp;amp;amp;amp;amp;amp;amp;amp;amp;amp;amp;amp;amp;amp;amp;amp;amp;amp;amp;amp;amp;amp;amp;amp;amp;amp;amp;amp;gt;blackHoleCallback = ‘forceSSL’;
if(!in_array($this-&amp;amp;amp;amp;amp;amp;amp;amp;amp;amp;amp;amp;amp;amp;amp;amp;amp;amp;amp;amp;amp;amp;amp;amp;amp;amp;amp;amp;amp;amp;amp;amp;amp;amp;gt;params[‘action’],$sslnotallowed_url)){
$this-&amp;amp;amp;amp;amp;amp;amp;amp;amp;amp;amp;amp;amp;amp;amp;amp;amp;amp;amp;amp;amp;amp;amp;amp;amp;amp;amp;amp;amp;amp;amp;amp;amp;amp;gt;Security-&amp;amp;amp;amp;amp;amp;amp;amp;amp;amp;amp;amp;amp;amp;amp;amp;amp;amp;amp;amp;amp;amp;amp;amp;amp;amp;amp;amp;amp;amp;amp;amp;amp;amp;gt;requireSecure(‘*’);
}
}[/sourcecode]

ForceSSL Method

[sourcecode]function forceSSL() {
$this-&amp;amp;amp;amp;amp;amp;amp;amp;amp;amp;amp;amp;amp;amp;amp;amp;amp;amp;amp;amp;amp;amp;amp;amp;amp;amp;amp;amp;amp;amp;amp;amp;amp;amp;gt;redirect(‘https://app.andolacrm.com’ . $this-&amp;amp;amp;amp;amp;amp;amp;amp;amp;amp;amp;amp;amp;amp;amp;amp;amp;amp;amp;amp;amp;amp;amp;amp;amp;amp;amp;amp;amp;amp;amp;amp;amp;amp;gt;here);
}[/sourcecode]

NOTE: Security Component can only be used for the forms create using FormHelper.

Conclusion:

Using the steps as described above would facilitate you to successfully implement the SSL in CakePHP. But you need to be more careful while using security component for your application. It may cause ‘blackhole’ error if there is any kind of security hole in your application. However, you could avoid such errors by setting above described variable to ‘false’.