PageRenderTime 47ms CodeModel.GetById 19ms RepoModel.GetById 1ms app.codeStats 0ms

/protected/controllers/BlogController.php

https://github.com/paranoidxc/iwebhost
PHP | 154 lines | 121 code | 12 blank | 21 comment | 4 complexity | 546c54e205e15aae3bdf9a6e7d7ff4c7 MD5 | raw file
  1. <?php
  2. class BlogController extends Controller
  3. {
  4. public function actionApi(){
  5. echo '<pre>';
  6. echo '117 Category API::node( array(\'ident_label\' => \'blog\') 下的属性<br/>';
  7. $blog = API::node( array('ident_label' => 'blog') );
  8. $blog->iprint();
  9. echo '<br>';
  10. echo '只提取blog下的文章 $articles = $blog->essays(); <br>';
  11. $articles = $blog->essays();
  12. foreach($articles as $a ){
  13. print_r($a->title);
  14. echo "<br/>";
  15. }
  16. echo '<br>';
  17. echo '提取blog下的文章 包括blog类别下的类别的文章 $articles = $blog->essays(array($include=>true));<Br>';
  18. $articles = $blog->essays(array('include'=>true));
  19. foreach($articles as $a ){
  20. print_r($a->title);
  21. echo "<br/>";
  22. }
  23. echo '<br>';
  24. echo '提取blog下的文章 包括blog类别下的类别的文章 list($articles ,$pagination)= $blog->essays(array(\'include\'=>true,\'split\' => true ));<Br>';
  25. list( $x , $pagination )= $blog->essays(array('include'=>true, 'split' => true ));
  26. foreach($x as $a ){
  27. print_r($a->title);
  28. echo "<br/>";
  29. }
  30. print_r($pagination->run());
  31. echo '<br>';
  32. echo '<br>';
  33. echo '提取一篇指定文章';
  34. echo "\$eassy = API::essay( array( 'id' => 482 ) ); \$eassy->iprint(); <br/>";
  35. $eassy = API::essay( array('id'=>482) );
  36. $eassy->iprint();
  37. echo '<br>';
  38. echo '以该文章为基准提取下一篇,默认提取属于同一 Category 下的文章; $eassy->getNext()->iprint(); <br/>';
  39. if( $eassy->getNext() ){
  40. $eassy->getNext()->iprint();
  41. }
  42. echo '<br>';
  43. echo '以该文章为基准提取上一篇,默认提取属于同一 Category 下的文章; $eassy->getPrev()->iprint();<br/>';
  44. if( $eassy->getPrev() ){
  45. $eassy->getPrev()->iprint();
  46. }
  47. echo '<br>';
  48. echo '以该文章为基准提取下一篇,指定提取属于117 Category 下的文章<br/>';
  49. if( $eassy->getNext(117) ){
  50. $eassy->getNext(117)->iprint();
  51. }
  52. echo '<br>';
  53. echo '以该文章为基准提取上一篇,指定提取属于117 Category 下的文章<br/>';
  54. if( $eassy->getPrev(117) ){
  55. $eassy->getPrev(117)->iprint();
  56. }
  57. /*
  58. list($list,$p) = API::essay(array(
  59. 'id' => '1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19'
  60. ));
  61. foreach($list as $e) {
  62. _debug( $e->title );
  63. }
  64. echo $p->run();
  65. */
  66. echo '</pre>';
  67. }
  68. public function actionAPIx(){
  69. $item_count =32;
  70. $page_size =2;
  71. $pages =new CPagination($item_count);
  72. //$pages->pageVar = 'iook=8&ok';
  73. //$pages->createPageUrl(CController::createUrl('blog/index',$pages) );
  74. $pages->setPageSize($page_size);
  75. // simulate the effect of LIMIT in a sql query
  76. //$end =($pages->offset+$pages->limit <= $item_count ? $pages->offset+$pages->limit : $item_count);
  77. //$sample =range($pages->offset+1, $end);
  78. $pagination = new CLinkPager();
  79. //print_r("<pre>");
  80. //print_r($pagination);
  81. //print_r("</pre>");
  82. //$pages->pageVar='stat='.$_GET[stat]."&page";
  83. $pagination->setPages($pages);
  84. $pagination->init();
  85. $pagination->run();
  86. print_r("--");
  87. print_r($pages->offset);
  88. print_r("--");
  89. $pagination = new CListPager();
  90. $pages->pageVar = 'ioof';
  91. $pagination->setPages($pages);
  92. $pagination->init();
  93. $pagination->run();
  94. exit;
  95. echo 'find id=2 essay <br>';
  96. echo '<pre>';
  97. $a = API::essay(array(
  98. 'id' => '2'
  99. ));
  100. $a->print;
  101. echo 'find id=2,3,4 essay <br>';
  102. $a = API::essay(array(
  103. 'id' => ',1,2,3,4,5,6,7,,8,,9,0,0,-,-,,,,r,r,r,w,,3,2,3'
  104. ));
  105. foreach( $a as $t ){
  106. print_r("<hr>");
  107. $t->print;
  108. }
  109. echo '</pre>';
  110. exit;
  111. }
  112. public function actionIndex(){
  113. Yii::app()->name = 'xiaochuan.log';
  114. Yii::app()->theme='blog';
  115. //$blog = API::INODE( array('ident_label' => 'blog','include' => true) );
  116. $blog = API::node( array('ident_label' => 'blog') );
  117. $article = $blog->first( array('include'=> true) );
  118. $this->render('index', array(
  119. 'article' => $article,
  120. 'blog' => $blog
  121. ) );
  122. }
  123. public function actionMap(){
  124. Yii::app()->name = 'xiaochuan.log';
  125. Yii::app()->theme='blog';
  126. $blog = API::node( array('ident_label' => 'blog' ) );
  127. $this->renderPartial('_map', array(
  128. 'blog' => $blog
  129. ) );
  130. }
  131. public function actionArticle() {
  132. Yii::app()->name = 'xiaochuan.log';
  133. Yii::app()->theme='blog';
  134. $id = $_GET['id'];
  135. $article = Article::model()->findbyPk($_GET['id']);
  136. $blog = API::node( array('ident_label' => 'blog') );
  137. $this->render( 'index', array( 'article' => $article , 'blog' => $blog ) );
  138. }
  139. }
  140. ?>