Created
July 18, 2013 20:09
-
-
Save zoghal/6032614 to your computer and use it in GitHub Desktop.
CakePHP Module Base Exmaple:
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Router::connect('/Module/Posts',array('controller' => 'posts','action' => 'index' ); | |
Router::connect('/Module/Posts/:action/*',array('controller' => 'posts' ); | |
class PostsController extends AppController { | |
public $components = array('Paginator'); | |
public function index(){} | |
public function archive(){ | |
/* | |
* test: $this->request->params['named'] ==> array('page' => 2) | |
*/ | |
$records = $this->Paginator->paginate('Post',array('Post.active' => true)); | |
if (!empty($this->request->params['requested'])) { | |
return $records; | |
} | |
$this->set('Results', $Results); | |
} | |
} | |
### url : domain/officespace/news/ | |
Router::reload(); | |
Router::parse('/'); | |
Router::setRequestInfo(array( | |
array('plugin' => null, 'controller' => 'pages', 'action' => 'view', 'pass' => array('slug => 'news'),'named' => array( 'page' => 2 ), 'form' => array(), 'url' => array('url' => 'news/', 'mod_rewrite' => 'true'), 'bare' => 0), | |
array('base' => '/officespace', 'here' => '/officespace/news/', 'webroot' => '/officespace/') | |
)); | |
// controller::view('news'); | |
// view : pages/view.ctp | |
echo $this->element('post-archive'); | |
// widget element: /Elements/post-archive.ctp | |
### | |
$res = $this->requestAction('/Module/Posts/:archive'); | |
/* $res ===> array( | |
* 'Post' => array( | |
* '0' => array('id' => 1,'title' => 'POst1'), | |
* '1' => array('id' => 2,'title' => 'POst2'), | |
* '2' => array('id' => 3,'title' => 'POst3'), | |
* | |
* ) | |
* ); | |
*/ | |
//test $result = $this->Paginator->next('next'); | |
$expected = array( | |
'span' => array('class' => 'next'), | |
'a' => array('href' => '/officespace/news/page:3', 'rel' => 'next'), | |
'prev', | |
'/a', | |
'/span' | |
); | |
### | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment