ArticlesTable.php 1.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273
  1. <?php
  2. /**
  3. * CakePHP(tm) : Rapid Development Framework (https://cakephp.org)
  4. * Copyright (c) Cake Software Foundation, Inc. (https://cakefoundation.org)
  5. *
  6. * Licensed under The MIT License
  7. * Redistributions of files must retain the above copyright notice
  8. *
  9. * @copyright Copyright (c) Cake Software Foundation, Inc. (https://cakefoundation.org)
  10. * @since 3.0.0
  11. * @license https://opensource.org/licenses/mit-license.php MIT License
  12. */
  13. namespace TestApp\Model\Table;
  14. use Cake\ORM\Table;
  15. /**
  16. * Article table class
  17. */
  18. class ArticlesTable extends Table
  19. {
  20. public function initialize(array $config)
  21. {
  22. $this->belongsTo('Authors');
  23. $this->belongsToMany('Tags');
  24. $this->hasMany('ArticlesTags');
  25. }
  26. /**
  27. * Find published
  28. *
  29. * @param \Cake\ORM\Query $query The query
  30. * @param array $options The options
  31. * @return \Cake\ORM\Query
  32. */
  33. public function findPublished($query, array $options = [])
  34. {
  35. $query = $query->where(['published' => 'Y']);
  36. if (isset($options['title'])) {
  37. $query->andWhere(['title' => $options['title']]);
  38. }
  39. return $query;
  40. }
  41. /**
  42. * Example public method
  43. *
  44. * @return void
  45. */
  46. public function doSomething()
  47. {
  48. }
  49. /**
  50. * Example Secondary public method
  51. *
  52. * @return void
  53. */
  54. public function doSomethingElse()
  55. {
  56. }
  57. /**
  58. * Example protected method
  59. *
  60. * @return void
  61. */
  62. protected function _innerMethod()
  63. {
  64. }
  65. }