SluggableBehavior.php 1.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546
  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 (https://cakephp.org)
  8. * Copyright (c) Cake Software Foundation, Inc. (https://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. (https://cakefoundation.org)
  15. * @link https://cakephp.org CakePHP(tm) Project
  16. * @since 1.2.0
  17. * @license https://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\Utility\Text;
  24. class SluggableBehavior extends Behavior
  25. {
  26. public function beforeFind(Event $event, Query $query, $options = [])
  27. {
  28. $query->where(['slug' => 'test']);
  29. return $query;
  30. }
  31. public function findNoSlug(Query $query, $options = [])
  32. {
  33. $query->where(['slug' => null]);
  34. return $query;
  35. }
  36. public function slugify($value)
  37. {
  38. return Text::slug($value);
  39. }
  40. }