本文整理汇总了PHP中Controller::constructClasses方法的典型用法代码示例。如果您正苦于以下问题:PHP Controller::constructClasses方法的具体用法?PHP Controller::constructClasses怎么用?PHP Controller::constructClasses使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Controller
的用法示例。
在下文中一共展示了Controller::constructClasses方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: setUp
/**
* setUp method
*
* @access public
* @return void
*/
public function setUp()
{
$this->Controller = new ArticlesTestController();
$this->Controller->constructClasses();
$this->Controller->params = array('named' => array(), 'pass' => array(), 'url' => array());
$this->Controller->modelClass = 'Article';
$this->Controller->Archive = new ArchiveComponent($this->Controller->Components);
$this->Controller->Archive->startup($this->Controller);
}
示例2: __construct
/**
* Initialize
*
* @param type $stdout
* @param type $stderr
* @param type $stdin
*/
public function __construct($stdout = null, $stderr = null, $stdin = null)
{
parent::__construct($stdout, $stderr, $stdin);
$this->_CroogoPlugin = new CroogoPlugin();
$this->_CroogoTheme = new CroogoTheme();
$CakeRequest = new CakeRequest();
$CakeResponse = new CakeResponse();
$this->_Controller = new AppController($CakeRequest, $CakeResponse);
$this->_Controller->constructClasses();
$this->_Controller->startupProcess();
$this->_CroogoPlugin->setController($this->_Controller);
$this->initialize();
}
示例3: constructClasses
/**
* Override this method to ensure that some components get loaded
* conditionally.
*
* @access public
*/
public function constructClasses()
{
if (Configure::read('debug') > 0) {
$this->components[] = 'DebugKit.Toolbar';
}
parent::constructClasses();
}
示例4: _createController
protected function _createController($data)
{
$request = new CakeRequest();
$request->data = $data;
$controller = new Controller($request);
$controller->components = array('Croogo.BulkProcess');
$controller->constructClasses();
$controller->startupProcess();
return $controller;
}
示例5: constructClasses
public function constructClasses()
{
if (Configure::read('debug')) {
$className = get_class($this);
if (substr($className, 0, 5) != 'Mock_') {
//inside PHPUnit mocks, do not use DebugKit Toolbar
$this->components[] = 'DebugKit.Toolbar';
}
}
parent::constructClasses();
}
示例6: switch
/**
* When methods are now present in a controller
* scaffoldView is used to call default Scaffold methods if:
* <code>
* var $scaffold;
* </code>
* is placed in the controller's class definition.
*
* @param string $url
* @param string $controller_class
* @param array $params
* @since Cake v 0.10.0.172
* @access private
*/
function __scaffold($params)
{
if (!in_array('Form', $this->controllerClass->helpers)) {
$this->controllerClass->helpers[] = 'Form';
}
if ($this->controllerClass->constructClasses()) {
$db =& ConnectionManager::getDataSource($this->controllerClass->{$this->modelKey}->useDbConfig);
if (isset($db)) {
if ($params['action'] === 'index' || $params['action'] === 'list' || $params['action'] === 'view' || $params['action'] === 'add' || $params['action'] === 'create' || $params['action'] === 'edit' || $params['action'] === 'update' || $params['action'] === 'delete') {
switch ($params['action']) {
case 'index':
$this->__scaffoldIndex($params);
break;
case 'view':
$this->__scaffoldView($params);
break;
case 'list':
$this->__scaffoldIndex($params);
break;
case 'add':
$this->__scaffoldForm($params, 'add');
break;
case 'edit':
$this->__scaffoldForm($params, 'edit');
break;
case 'create':
$this->__scaffoldSave($params, 'create');
break;
case 'update':
$this->__scaffoldSave($params, 'update');
break;
case 'delete':
$this->__scaffoldDelete($params);
break;
}
} else {
return $this->cakeError('missingAction', array(array('className' => Inflector::camelize($params['controller'] . "Controller"), 'base' => $this->controllerClass->base, 'action' => $params['action'], 'webroot' => $this->controllerClass->webroot)));
}
} else {
return $this->cakeError('missingDatabase', array(array('webroot' => $this->controllerClass->webroot)));
}
} else {
return $this->cakeError('missingModel', array(array('className' => $this->modelKey, 'webroot' => '', 'base' => $this->base)));
}
}
示例7: testPagination
public function testPagination()
{
$this->markTestSkipped('Needs revision');
$objController = new Controller(new CakeRequest('/'), new CakeResponse());
$objController->layout = 'ajax';
$objController->uses = array('User');
$objController->constructClasses();
$objController->request->url = '/';
$objController->paginate = array('fields' => array('username'), 'contain' => false, 'link' => array('Profile' => array('fields' => array('biography'))), 'limit' => 2);
$arrayResult = $objController->paginate('User');
$this->assertEquals($objController->params['paging']['User']['count'], 4, 'Paging: total records count: %s');
// Pagination with order on a row from table joined with Linkable
$objController->paginate = array('fields' => array('id'), 'contain' => false, 'link' => array('Profile' => array('fields' => array('user_id'))), 'limit' => 2, 'order' => 'Profile.user_id DESC');
$arrayResult = $objController->paginate('User');
$arrayExpected = array(0 => array('User' => array('id' => 4), 'Profile' => array('user_id' => 4)), 1 => array('User' => array('id' => 3), 'Profile' => array('user_id' => 3)));
$this->assertEquals($arrayResult, $arrayExpected, 'Paging with order on join table row: %s');
// Pagination without specifying any fields
$objController->paginate = array('contain' => false, 'link' => array('Profile'), 'limit' => 2, 'order' => 'Profile.user_id DESC');
$arrayResult = $objController->paginate('User');
$this->assertEquals($objController->params['paging']['User']['count'], 4, 'Paging without any field lists: total records count: %s');
}
示例8: _invoke
/**
* Initializes the components and models a controller will be using.
* Triggers the controller action, and invokes the rendering if Controller::$autoRender is true and echo's the output.
* Otherwise the return value of the controller action are returned.
*
* Works like {@see Dispatcher::_invoke()} but returns the full response instead the body only.
*
* Bancha needs to overwrite this method because we need the full response object not only the body of the response
* object on return.
*
* @param Controller $controller Controller to invoke
* @param CakeRequest $request The request object to invoke the controller for.
* @param CakeResponse $response The response object to receive the output
* @return CakeResponse te resulting response object
*/
protected function _invoke(Controller $controller, CakeRequest $request, CakeResponse $response)
{
$controller->constructClasses();
$controller->startupProcess();
$render = true;
$result = $controller->invokeAction($request);
if ($result instanceof CakeResponse) {
$render = false;
$response = $result;
}
if ($render && $controller->autoRender) {
$response = $controller->render();
} elseif ($response->body() === null) {
$response->body($result);
}
$controller->shutdownProcess();
if (isset($request->params['return'])) {
return $response;
// <-------------- only this line is changed, original: return $response->body();
}
$response->send();
}
示例9: testPaginateMaxLimit
/**
* testPaginateMaxLimit
*
* @return void
*/
public function testPaginateMaxLimit()
{
$Controller = new Controller($this->request);
$Controller->uses = array('PaginatorControllerPost', 'ControllerComment');
$Controller->passedArgs[] = '1';
$Controller->constructClasses();
$Controller->request->params['named'] = array('contain' => array('ControllerComment'), 'limit' => '1000');
$result = $Controller->paginate('PaginatorControllerPost');
$this->assertEquals($Controller->params['paging']['PaginatorControllerPost']['options']['limit'], 100);
$Controller->request->params['named'] = array('contain' => array('ControllerComment'), 'limit' => '1000', 'maxLimit' => 1000);
$result = $Controller->paginate('PaginatorControllerPost');
$this->assertEquals($Controller->params['paging']['PaginatorControllerPost']['options']['limit'], 100);
$Controller->request->params['named'] = array('contain' => array('ControllerComment'), 'limit' => '10');
$result = $Controller->paginate('PaginatorControllerPost');
$this->assertEquals($Controller->params['paging']['PaginatorControllerPost']['options']['limit'], 10);
$Controller->request->params['named'] = array('contain' => array('ControllerComment'), 'limit' => '1000');
$Controller->paginate = array('maxLimit' => 2000, 'paramType' => 'named');
$result = $Controller->paginate('PaginatorControllerPost');
$this->assertEquals($Controller->params['paging']['PaginatorControllerPost']['options']['limit'], 1000);
$Controller->request->params['named'] = array('contain' => array('ControllerComment'), 'limit' => '5000');
$result = $Controller->paginate('PaginatorControllerPost');
$this->assertEquals($Controller->params['paging']['PaginatorControllerPost']['options']['limit'], 2000);
}
示例10: testPaginateBackwardsCompatibility
/**
* test that using Controller::paginate() falls back to PaginatorComponent
*
* @return void
*/
function testPaginateBackwardsCompatibility()
{
$request = new CakeRequest('controller_posts/index');
$request->params['pass'] = $request->params['named'] = array();
$Controller = new Controller($request);
$Controller->uses = array('ControllerPost', 'ControllerComment');
$Controller->passedArgs[] = '1';
$Controller->params['url'] = array();
$Controller->constructClasses();
$expected = array('page' => 1, 'limit' => 20, 'maxLimit' => 100, 'paramType' => 'named');
$this->assertEqual($Controller->paginate, $expected);
$results = Set::extract($Controller->paginate('ControllerPost'), '{n}.ControllerPost.id');
$this->assertEqual($results, array(1, 2, 3));
$Controller->passedArgs = array();
$Controller->paginate = array('limit' => '-1');
$this->assertEqual($Controller->paginate, array('limit' => '-1'));
$Controller->paginate('ControllerPost');
$this->assertIdentical($Controller->params['paging']['ControllerPost']['page'], 1);
$this->assertIdentical($Controller->params['paging']['ControllerPost']['pageCount'], 3);
$this->assertIdentical($Controller->params['paging']['ControllerPost']['prevPage'], false);
$this->assertIdentical($Controller->params['paging']['ControllerPost']['nextPage'], true);
}
示例11: constructClasses
public function constructClasses()
{
parent::constructClasses();
$this->Auth = $this->CustomAuth;
}
示例12: testPaginate
/**
* testPaginate method
*
* @access public
* @return void
*/
function testPaginate()
{
$Controller = new Controller();
$Controller->uses = array('Article');
$Controller->passedArgs[] = '1';
$Controller->params['url'] = array();
$Controller->constructClasses();
$Controller->paginate = array('Article' => array('fields' => array('title'), 'contain' => array('User(user)')));
$result = $Controller->paginate('Article');
$expected = array(array('Article' => array('title' => 'First Article'), 'User' => array('user' => 'mariano', 'id' => 1)), array('Article' => array('title' => 'Second Article'), 'User' => array('user' => 'larry', 'id' => 3)), array('Article' => array('title' => 'Third Article'), 'User' => array('user' => 'mariano', 'id' => 1)));
$this->assertEqual($result, $expected);
$r = $Controller->Article->find('all');
$this->assertTrue(Set::matches('/Article[id=1]', $r));
$this->assertTrue(Set::matches('/User[id=1]', $r));
$this->assertTrue(Set::matches('/Tag[id=1]', $r));
$Controller->paginate = array('Article' => array('contain' => array('Comment(comment)' => 'User(user)'), 'fields' => array('title')));
$result = $Controller->paginate('Article');
$expected = array(array('Article' => array('title' => 'First Article', 'id' => 1), 'Comment' => array(array('comment' => 'First Comment for First Article', 'user_id' => 2, 'article_id' => 1, 'User' => array('user' => 'nate')), array('comment' => 'Second Comment for First Article', 'user_id' => 4, 'article_id' => 1, 'User' => array('user' => 'garrett')), array('comment' => 'Third Comment for First Article', 'user_id' => 1, 'article_id' => 1, 'User' => array('user' => 'mariano')), array('comment' => 'Fourth Comment for First Article', 'user_id' => 1, 'article_id' => 1, 'User' => array('user' => 'mariano')))), array('Article' => array('title' => 'Second Article', 'id' => 2), 'Comment' => array(array('comment' => 'First Comment for Second Article', 'user_id' => 1, 'article_id' => 2, 'User' => array('user' => 'mariano')), array('comment' => 'Second Comment for Second Article', 'user_id' => 2, 'article_id' => 2, 'User' => array('user' => 'nate')))), array('Article' => array('title' => 'Third Article', 'id' => 3), 'Comment' => array()));
$this->assertEqual($result, $expected);
$r = $Controller->Article->find('all');
$this->assertTrue(Set::matches('/Article[id=1]', $r));
$this->assertTrue(Set::matches('/User[id=1]', $r));
$this->assertTrue(Set::matches('/Tag[id=1]', $r));
$Controller->Article->unbindModel(array('hasMany' => array('Comment'), 'belongsTo' => array('User'), 'hasAndBelongsToMany' => array('Tag')), false);
$Controller->Article->bindModel(array('hasMany' => array('Comment'), 'belongsTo' => array('User')), false);
$Controller->paginate = array('Article' => array('contain' => array('Comment(comment)', 'User(user)'), 'fields' => array('title')));
$r = $Controller->paginate('Article');
$this->assertTrue(Set::matches('/Article[id=1]', $r));
$this->assertTrue(Set::matches('/User[id=1]', $r));
$this->assertTrue(Set::matches('/Comment[article_id=1]', $r));
$this->assertFalse(Set::matches('/Comment[id=1]', $r));
$r = $this->Article->find('all');
$this->assertTrue(Set::matches('/Article[id=1]', $r));
$this->assertTrue(Set::matches('/User[id=1]', $r));
$this->assertTrue(Set::matches('/Comment[article_id=1]', $r));
$this->assertTrue(Set::matches('/Comment[id=1]', $r));
}
示例13: testPaginateOrderVirtualFieldSharedWithRealField
/**
* test paginate() and virtualField overlapping with real fields.
*
* @return void
*/
public function testPaginateOrderVirtualFieldSharedWithRealField()
{
$Controller = new Controller($this->request);
$Controller->uses = array('PaginatorControllerPost', 'PaginatorControllerComment');
$Controller->constructClasses();
$Controller->PaginatorControllerComment->virtualFields = array('title' => 'PaginatorControllerComment.comment');
$Controller->PaginatorControllerComment->bindModel(array('belongsTo' => array('PaginatorControllerPost' => array('className' => 'PaginatorControllerPost', 'foreignKey' => 'article_id'))), false);
$Controller->paginate = array('fields' => array('PaginatorControllerComment.id', 'title', 'PaginatorControllerPost.title'));
$Controller->passedArgs = array('sort' => 'PaginatorControllerPost.title', 'dir' => 'asc');
$result = $Controller->paginate('PaginatorControllerComment');
$this->assertEquals(Set::extract($result, '{n}.PaginatorControllerComment.id'), array(1, 2, 3, 4, 5, 6));
}
示例14: testRequestHandlerPrefers
/**
* testRequestHandlerPrefers method
*
* @access public
* @return void
*/
function testRequestHandlerPrefers()
{
Configure::write('debug', 2);
$Controller = new Controller();
$Controller->components = array("RequestHandler");
$Controller->modelClass = 'ControllerPost';
$Controller->params['url']['ext'] = 'rss';
$Controller->constructClasses();
$Controller->Component->initialize($Controller);
$Controller->beforeFilter();
$Controller->Component->startup($Controller);
$this->assertEqual($Controller->RequestHandler->prefers(), 'rss');
unset($Controller);
}
示例15: _invoke
/**
* Initializes the components and models a controller will be using.
* Triggers the controller action, and invokes the rendering if Controller::$autoRender is true and echo's the output.
* Otherwise the return value of the controller action are returned.
*
* @param Controller $controller Controller to invoke
* @param CakeRequest $request The request object to invoke the controller for.
* @param CakeResponse $response The response object to receive the output
* @return CakeResponse the resulting response object
*/
protected function _invoke(Controller $controller, CakeRequest $request, CakeResponse $response)
{
$controller->constructClasses();
$controller->startupProcess();
$render = true;
$result = $controller->invokeAction($request);
if ($result instanceof CakeResponse) {
$render = false;
$response = $result;
}
if ($render && $controller->autoRender) {
$response = $controller->render();
} elseif (!$result instanceof CakeResponse && $response->body() === null) {
$response->body($result);
}
$controller->shutdownProcess();
return $response;
}