neilcrookes / cakephp-habtm-counter-cache-plugin Goto Github PK
View Code? Open in Web Editor NEWCakePHP Behavior in a plugin to handle counter caching for HABTM associations
Home Page: http://www.neilcrookes.com
CakePHP Behavior in a plugin to handle counter caching for HABTM associations
Home Page: http://www.neilcrookes.com
i don't know why but my model doesn't recognize that this behavior is part of a plugin.
i have it listed as described in the readme:
var $actsAs = array('HabtmCounterCache.HabtmCounterCache');
but it will only work if i list it as:
var $actsAs = array('HabtmCounterCache');
and put a behavior in my app/model/behavior director called:
habtm_counter_cache.php
as was demanded by me of my error report.
am i missing something very simple in this?
2014-07-12 19:23:55 Error: [MissingPluginException] Plugin HabtmCounterCache could not be found.
Exception Attributes: array (
'plugin' => 'HabtmCounterCache',
)
Request URL: /professors
Stack Trace:
#0 /usr/home/vhost/cake.d-zone/lib/Cake/Core/App.php(365): CakePlugin::path('HabtmCounterCac...')
#1 /usr/home/vhost/cake.d-zone/lib/Cake/Core/App.php(226): App::pluginPath('HabtmCounterCac...')
#2 /usr/home/vhost/cake.d-zone/lib/Cake/Core/App.php(547): App::path('Model/Behavior', 'HabtmCounterCac...')
#3 [internal function]: App::load('HabtmCounterCac...')
#4 [internal function]: spl_autoload_call('HabtmCounterCac...')
#5 /usr/home/vhost/cake.d-zone/lib/Cake/Model/BehaviorCollection.php(120): class_exists('HabtmCounterCac...')
#6 /usr/home/vhost/cake.d-zone/lib/Cake/Model/BehaviorCollection.php(66): BehaviorCollection->load('HabtmCounterCac...',
#7 /usr/home/vhost/cake.d-zone/lib/Cake/Model/Model.php(747): BehaviorCollection->init('Professor', Array)
#8 [internal function]: Model->__construct(Array)
#9 /usr/home/vhost/cake.d-zone/lib/Cake/Utility/ClassRegistry.php(169): ReflectionClass->newInstance(Array)
#10 /usr/home/vhost/cake.d-zone/lib/Cake/Controller/Controller.php(738): ClassRegistry::init(Array)
#11 /usr/home/vhost/cake.d-zone/lib/Cake/Controller/Controller.php(367): Controller->loadModel('Professor')
#12 /usr/home/vhost/cake.d-zone/lib/Cake/Controller/Controller.php(405): Controller->__isset('Professor')
#13 /usr/home/vhost/cake.d-zone/app/Controller/ProfessorsController.php(24): Controller->__get('Professor')
#14 [internal function]: ProfessorsController->index()
#15 /usr/home/vhost/cake.d-zone/lib/Cake/Controller/Controller.php(490): ReflectionMethod->invokeArgs(Object(ProfessorsCo
#16 /usr/home/vhost/cake.d-zone/lib/Cake/Routing/Dispatcher.php(191): Controller->invokeAction(Object(CakeRequest))
#17 /usr/home/vhost/cake.d-zone/lib/Cake/Routing/Dispatcher.php(165): Dispatcher->_invoke(Object(ProfessorsController), O
#18 /usr/home/vhost/cake.d-zone/app/webroot/index.php(108): Dispatcher->dispatch(Object(CakeRequest), Object(CakeResponse
#19 {main}
I got this errors when I enable the plugin:
Strict (2048): Declaration of BlogSetting::afterSave() should be compatible with Model::afterSave($created) [APP\Plugin\Blog\Model\BlogSetting.php, line 10]
Strict (2048): Declaration of BlogPost::afterSave() should be compatible with Model::afterSave($created) [APP\Plugin\Blog\Model\BlogPost.php, line 435]
Strict (2048): Declaration of HabtmCounterCacheBehavior::setup() should be compatible with ModelBehavior::setup(Model $model, $config = Array) [APP\Plugin\habtm_counter_cache\Model\Behavior\HabtmCounterCacheBehavior.php, line 27]
Strict (2048): Declaration of HabtmCounterCacheBehavior::beforeSave() should be compatible with ModelBehavior::beforeSave(Model $model) [APP\Plugin\habtm_counter_cache\Model\Behavior\HabtmCounterCacheBehavior.php, line 27]
Strict (2048): Declaration of HabtmCounterCacheBehavior::afterSave() should be compatible with ModelBehavior::afterSave(Model $model, $created) [APP\Plugin\habtm_counter_cache\Model\Behavior\HabtmCounterCacheBehavior.php, line 27]
Strict (2048): Declaration of HabtmCounterCacheBehavior::beforeDelete() should be compatible with ModelBehavior::beforeDelete(Model $model, $cascade = true) [APP\Plugin\habtm_counter_cache\Model\Behavior\HabtmCounterCacheBehavior.php, line 27]
Strict (2048): Declaration of HabtmCounterCacheBehavior::afterDelete() should be compatible with ModelBehavior::afterDelete(Model $model) [APP\Plugin\habtm_counter_cache\Model\Behavior\HabtmCounterCacheBehavior.php, line 27]
am i correct in seein gthat it goies through every row of the habtm table updaitng the count, instead of just the one being updated?
my db at ~25,000 rows and it takes a very long time to edit just one field..
i don't mean to making so many issues, but it would be great to have this feature working well.
My User model is like this:
class User extends AppModel {
public $actsAs = array('Containable', 'HabtmCounterCache');
public $hasAndBelongsToMany = array(
'Follower' => array(
'className' => 'User',
'joinTable' => 'relationships',
'foreignKey' => 'followed_id',
'associationForeignKey' => 'follower_id',
'unique' => 'true' // If you do not want records to be deleted
),
'Following' => array(
'className' => 'User',
'joinTable' => 'relationships',
'foreignKey' => 'follower_id',
'associationForeignKey' => 'followed_id',
'unique' => 'true' // If you do not want records to be deleted
)
);
I have added two columns namely follwer_count and following_count at user model. But its not updating the counter.
when use use whit prefix table not worked.
This error occurs every time i save model using the plugin.
it stil seems to work but i don't understand why implode gets invalid arguments.
full error report:
$query = array(
"offset" => null,
"joins" => null,
"fields" => array(
"COUNT(*)"
),
"table" => "contacts_events",
"alias" => "ContactsEvent",
"conditions" => array(
"ContactsEvent.event_id = Event.id"
),
"order" => null,
"limit" => null,
"group" => null
)
$model = AppModel
AppModel::$useDbConfig = "default"
AppModel::$useTable = "contacts_events"
AppModel::$displayField = "id"
AppModel::$id = false
AppModel::$data = array
AppModel::$table = "contacts_events"
AppModel::$primaryKey = "id"
AppModel::$_schema = array
AppModel::$validate = array
AppModel::$validationErrors = array
AppModel::$tablePrefix = ""
AppModel::$name = "ContactsEvent"
AppModel::$alias = "ContactsEvent"
AppModel::$tableToModel = array
AppModel::$logTransactions = false
AppModel::$cacheQueries = false
AppModel::$belongsTo = array
AppModel::$hasOne = array
AppModel::$hasMany = array
AppModel::$hasAndBelongsToMany = array
AppModel::$actsAs = NULL
AppModel::$Behaviors = BehaviorCollection object
AppModel::$whitelist = array
AppModel::$cacheSources = true
AppModel::$findQueryType = NULL
AppModel::$recursive = 1
AppModel::$order = NULL
AppModel::$virtualFields = array
AppModel::$__associationKeys = array
AppModel::$__associations = array
AppModel::$__backAssociation = array
AppModel::$__insertID = NULL
AppModel::$__numRows = NULL
AppModel::$__affectedRows = NULL
AppModel::$_findMethods = array
implode - [internal], line ??
DboSource::buildStatement() - CORE/cake/libs/model/datasources/dbo_source.php, line 1468
HabtmCounterCacheBehavior::_updateCounterCache() - APP/models/behaviors/habtm_counter_cache.php, line 402
HabtmCounterCacheBehavior::afterSave() - APP/models/behaviors/habtm_counter_cache.php, line 258
ModelBehavior::dispatchMethod() - CORE/cake/libs/model/model_behavior.php, line 171
BehaviorCollection::trigger() - CORE/cake/libs/model/model_behavior.php, line 494
Model::save() - CORE/cake/libs/model/model.php, line 1363
ContactsController::transformTags() - APP/controllers/contacts_controller.php, line 200
Dispatcher::_invoke() - CORE/cake/dispatcher.php, line 204
Dispatcher::dispatch() - CORE/cake/dispatcher.php, line 171
[main] - APP/webroot/index.php, line 83
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.