DataProviderInterface.php 2.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273
  1. <?php
  2. /**
  3. * @link http://www.yiiframework.com/
  4. * @copyright Copyright (c) 2008 Yii Software LLC
  5. * @license http://www.yiiframework.com/license/
  6. */
  7. namespace yii\data;
  8. /**
  9. * DataProviderInterface is the interface that must be implemented by data provider classes.
  10. *
  11. * Data providers are components that sort and paginate data, and provide them to widgets
  12. * such as [[\yii\grid\GridView]], [[\yii\widgets\ListView]].
  13. *
  14. * For more details and usage information on DataProviderInterface, see the [guide article on data providers](guide:output-data-providers).
  15. *
  16. * @author Qiang Xue <qiang.xue@gmail.com>
  17. * @since 2.0
  18. */
  19. interface DataProviderInterface
  20. {
  21. /**
  22. * Prepares the data models and keys.
  23. *
  24. * This method will prepare the data models and keys that can be retrieved via
  25. * [[getModels()]] and [[getKeys()]].
  26. *
  27. * This method will be implicitly called by [[getModels()]] and [[getKeys()]] if it has not been called before.
  28. *
  29. * @param bool $forcePrepare whether to force data preparation even if it has been done before.
  30. */
  31. public function prepare($forcePrepare = false);
  32. /**
  33. * Returns the number of data models in the current page.
  34. * This is equivalent to `count($provider->getModels())`.
  35. * When [[getPagination|pagination]] is false, this is the same as [[getTotalCount|totalCount]].
  36. * @return int the number of data models in the current page.
  37. */
  38. public function getCount();
  39. /**
  40. * Returns the total number of data models.
  41. * When [[getPagination|pagination]] is false, this is the same as [[getCount|count]].
  42. * @return int total number of possible data models.
  43. */
  44. public function getTotalCount();
  45. /**
  46. * Returns the data models in the current page.
  47. * @return array the list of data models in the current page.
  48. */
  49. public function getModels();
  50. /**
  51. * Returns the key values associated with the data models.
  52. * @return array the list of key values corresponding to [[getModels|models]]. Each data model in [[getModels|models]]
  53. * is uniquely identified by the corresponding key value in this array.
  54. */
  55. public function getKeys();
  56. /**
  57. * @return Sort the sorting object. If this is false, it means the sorting is disabled.
  58. */
  59. public function getSort();
  60. /**
  61. * @return Pagination|false the pagination object. If this is false, it means the pagination is disabled.
  62. */
  63. public function getPagination();
  64. }