所以我正在学习PHP,并从一些非常基础的东西开始。
我正在尝试从我的控制器文件夹中的文件调用一个函数,但它不起作用。
我已成功地将我输入的任何内容回显到URL栏中,但它不会在我的其他index.php文件中打印出作为控制器一部分的消息,但当然会继续回显任何消息输入的URL。我错过了什么吗?
所以这就是我坐在我的MVC文件夹之外的一个index.php文件:
<?php
$url = $_GET['url'];
echo $url;
require 'controllers/' . $url . '.php';
$controller = new $url;
?>
以下是我在我想要调用的controllers文件夹中的index.php文件中的内容:
<?php
class Index {
function __construct(){
echo 'We are in index';
}
}
?>
我的.htaccess文件如下所示:
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-l
RewriteRule ^(.*)$ /index.php?url=$1 [QSA,L]
答案 0 :(得分:0)
如果您使用的是Linux,请将execute()
更改为@interface LinksTableViewController (){
NSArray *data;
}
@property (strong, nonatomic) NSArray *links;
@property (strong, nonatomic) NSArray *tNames;
@property (strong, nonatomic) NSArray *dThor;
@property (strong, nonatomic) NSArray *theLinker;
@property (strong, nonatomic) NSArray *anText;
@property (strong, nonatomic) NSArray *noDo;
@end
@implementation LinksTableViewController
- (void)viewDidLoad {
[super viewDidLoad];
UISegmentedControl *statFilter = [[UISegmentedControl alloc] initWithItems:[NSArray arrayWithObjects:@"STAT1", @"STAT2", @"STAT3", @"STAT4", nil]];
[statFilter sizeToFit];
[statFilter addTarget:self action:@selector(MySegmentControlAction:) forControlEvents: UIControlEventValueChanged];
self.navigationItem.titleView = statFilter;
[NSTimer scheduledTimerWithTimeInterval:0.1 target:self selector:@selector(refreshdelay:) userInfo:nil repeats:NO];
}
- (void)MySegmentControlAction:(UISegmentedControl *)segment
{
NSArray *arrayToSort = data;
if (segment.selectedSegmentIndex == 0)
{
NSSortDescriptor *sortDescriptor = [[NSSortDescriptor alloc] initWithKey:@"pda" ascending:NO];
arrayToSort = [arrayToSort sortedArrayUsingDescriptors:@[sortDescriptor]];
NSLog(@"%@", arrayToSort);
}
else if (segment.selectedSegmentIndex == 1)
{
}
else if (segment.selectedSegmentIndex == 2)
{
}
else if (segment.selectedSegmentIndex == 3)
{
}
[self.tableView reloadData];
}
-(void)refreshdelay:(NSTimer*)timer
{
NSString *myString = [links absoluteString];
NSURL *JSONData = [NSURL URLWithString:myString];
NSData *datas = [NSData dataWithContentsOfURL:JSONData];
NSURLRequest *request = [NSURLRequest requestWithURL:JSONData];
AFHTTPRequestOperation *operation = [[AFHTTPRequestOperation alloc] initWithRequest:request];
operation.responseSerializer = [AFJSONResponseSerializer serializer];
operation.responseSerializer.acceptableContentTypes = [operation.responseSerializer.acceptableContentTypes setByAddingObject:@"text/html"];
[operation setCompletionBlockWithSuccess:^(AFHTTPRequestOperation *operation, id responseObject) {
NSArray *jsonResult = [NSJSONSerialization JSONObjectWithData:datas options:kNilOptions error:nil];
data = jsonResult;
NSMutableArray *names = [NSMutableArray array];
NSMutableArray *bLinks = [NSMutableArray array];
NSMutableArray *daThor = [NSMutableArray array];
NSMutableArray *bsLink = [NSMutableArray array];
NSMutableArray *ancTxt = [NSMutableArray array];
NSMutableArray *folLowd = [NSMutableArray array];
for (id itemfeed in jsonResult){
[names addObject:[NSString stringWithFormat:@"%@", itemfeed[@"ut"]]];
[bsLink addObject:[NSString stringWithFormat:@"%@", itemfeed[@"uu"]]];
[bLinks addObject:[NSString stringWithFormat:@"%@", itemfeed[@"upa"]]];
[daThor addObject:[NSString stringWithFormat:@"%@", itemfeed[@"pda"]]];
[ancTxt addObject:[NSString stringWithFormat:@"%@", itemfeed[@"lt"]]];
[folLowd addObject:[NSString stringWithFormat:@"%@", itemfeed[@"lf"]]];
self.links = names;
self.tNames = bLinks;
self.dThor = daThor;
self.theLinker = bsLink;
self.anText = ancTxt;
self.noDo = folLowd;
}
[self.tableView reloadData];
} failure:^(AFHTTPRequestOperation *operation, NSError *error) {
}];
[operation start];
}
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
// UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"Cell" forIndexPath:indexPath];
static NSString *Cellidentifier = @"DataTableCellId";
LICustomCell *cell = (LICustomCell *) [tableView dequeueReusableCellWithIdentifier:Cellidentifier];
if (cell == nil) {
cell = [[LICustomCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:Cellidentifier];
NSArray *nib = [[NSBundle mainBundle]loadNibNamed:@"LiCellView" owner:self options:nil];
cell = nib[0];
NSString *sLink = self.links[indexPath.row];
NSString *aLink = self.tNames[indexPath.row];
NSString *aDa = self.dThor[indexPath.row];
NSString *theInk = self.theLinker[indexPath.row];
NSString *thAnk = self.anText[indexPath.row];
NSString *fLink = self.noDo[indexPath.row];
cell.ageLable.text = theInk;
}
return cell;
}
,然后尝试使用小写字母访问索引。