p0lym0rphik/cakephp-metabehavior

CakePHP MetaBehavior Plugin, dealing with additional datas

dev-master 2015-04-22 07:28 UTC

This package is not auto-updated.

Last update: 2024-06-04 00:53:11 UTC


README

Coverage Status Build Status

CakePHP MetaBehavior

Join the chat at https://gitter.im/p0lym0rphik/cakephp-metabehavior

Introduction

CakePHP Metabehavior is a meta data Behavior for CakePHP 2. This behavior allows you to store, retrieve and search for metadata about any record for any model within your database.

Installation

  1. Add the folder on your app/Plugin directory.

  2. Make sure that the Plugin is loaded (check your bootstrap configuration).

  3. Run the following commands:

cd /path/to/installation/
app/Console/cake schema create MetaBehavior.metas
  1. Add the behavior to the model you want to use.
class MyModel extends Model {
	public $actsAs = array('Meta');
}

How to

  1. Add datas to an object.
// Just set meta key on the primary request model
	$savedDatas = $this->request->data;
	$savedDatas['MyModel']['foo'] = 'bar';
	
	$this->MyModel->save($savedDatas);
  1. Retrieve datas.
	// Just launch a find and datas are in the primary model.

	$model = $this->MyModel->findByid(1);
	
	return array(
		'MyModel' => array(
			'id' => 1,
			'foo' => 'bar'
		)
	)	
  1. You can directly search on meta values.
	$this->MyModel->find('all',array(
		'conditions' => array(
			'MyModel.foo =' => 'bar'
		)
	));

Licence GPL2

CakePHP MetaBehavior plugin Copyright (C) 2014 Fabien Moreau

This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version.

This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.

You should have received a copy of the GNU General Public License along with this program; if not, write to the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.