我正在尝试使用Codeigniter分页,我收到以下错误"致命错误:调用未定义的方法Pagination :: initialize()"。
我发现了一些有相同问题的帖子,但他们都表示解决方案是自动加载我已经在做的Pagination类。我能想到的唯一问题是我的班级使用自定义控制器" MY_Controller"它扩展了CI控制器。以下是我的代码,请帮忙。提前谢谢。
MY_Controller.php
<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');
class MY_Controller extends CI_Controller {
public function __construct()
{
parent::__construct();
$this->init();
}
}
主控制器
<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');
class Main extends MY_Controller {
function index()
{
$this->display();
}
function display()
{
//pagination settings
$config['base_url'] = base_url();
$config['total_rows'] = 200;
$config['per_page'] = 50;
$this->pagination->initialize($config);
}
}
答案 0 :(得分:1)
如果你创建了一个自定义控制器并使用核心@interface DownloadManager ()
@property (nonatomic, strong) NSProgress *progress;
@property (nonatomic, strong) Settings *settings;
@property (nonatomic, strong) DocumentDirectory *documentDirectory;
@end
@implementation DownloadManager
- (instancetype)init
{
self = [super init];
if (self) {
self.progress = [NSProgress new];
[self.progress addObserver:self forKeyPath:@"fractionCompleted" options:NSKeyValueObservingOptionNew context:NULL];
self.settings = [Settings new];
self.documentDirectory = [DocumentDirectory new];
}
return self;
}
- (void) dealloc {
[self.progress removeObserver:self forKeyPath:@"fractionCompleted"];
}
//Download the file from remote server in the document directory as Zip format
- (void) downloadCarContents:(NSArray *)urlArray forContent:(NSArray *)contentArray {
AFHTTPSessionManager *manager = [AFHTTPSessionManager manager];
self.progress.totalUnitCount = urlArray.count;
self.progress.completedUnitCount = 0;
for (NSInteger i = 0; i < urlArray.count; i++) {
NSString *destinationPath = [self.documentDirectory getDownloadContentPath:contentArray[i]];
NSURLRequest *request = [NSURLRequest requestWithURL:[NSURL URLWithString:urlArray[i]]];
NSURLSessionTask *task = [manager downloadTaskWithRequest:request progress:nil destination:^NSURL *(NSURL *targetPath, NSURLResponse *response) {
return [NSURL fileURLWithPath:destinationPath];
} completionHandler:^(NSURLResponse *response, NSURL *filePath, NSError *error) {
}];
NSProgress *childProgress = [manager downloadProgressForTask:task];
[self.progress addChild:childProgress withPendingUnitCount:1];
NSLog(@"Total downloaded : %f", self.progress.fractionCompleted * 100.0);
[task resume];
}
}
@end
扩展它而不是My_Controller
函数中的加载分页库:
display()