SluggableBehavior.php 1.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748
  1. <?php
  2. /**
  3. * Behavior for binding management.
  4. *
  5. * Behavior to simplify manipulating a model's bindings when doing a find operation
  6. *
  7. * CakePHP(tm) : Rapid Development Framework (http://cakephp.org)
  8. * Copyright (c) Cake Software Foundation, Inc. (http://cakefoundation.org)
  9. *
  10. * Licensed under The MIT License
  11. * For full copyright and license information, please see the LICENSE.txt
  12. * Redistributions of files must retain the above copyright notice.
  13. *
  14. * @copyright Copyright (c) Cake Software Foundation, Inc. (http://cakefoundation.org)
  15. * @link http://cakephp.org CakePHP(tm) Project
  16. * @since 1.2.0
  17. * @license http://www.opensource.org/licenses/mit-license.php MIT License
  18. */
  19. namespace TestApp\Model\Behavior;
  20. use Cake\Event\Event;
  21. use Cake\ORM\Behavior;
  22. use Cake\ORM\Query;
  23. use Cake\ORM\Table;
  24. use Cake\Utility\Inflector;
  25. class SluggableBehavior extends Behavior
  26. {
  27. public function beforeFind(Event $event, Query $query, $options = [])
  28. {
  29. $query->where(['slug' => 'test']);
  30. return $query;
  31. }
  32. public function findNoSlug(Query $query, $options = [])
  33. {
  34. $query->where(['slug' => null]);
  35. return $query;
  36. }
  37. public function slugify($value)
  38. {
  39. return Inflector::slug($value);
  40. }
  41. }