phalcon动态类创建失败并出现错误?

时间:2015-11-06 06:27:35

标签: php phalcon

我正在尝试使用用户模型中的模型函数创建dynimic模型类,但由于某种原因,它无法识别类位置。它给了我一个错误

NSArray *members = [NSArray arrayWithObjects:@"Keith", nil];

以下是功能

member

有什么原因造成的?

视图服务提供的数据如下

-(NSArray *) makeArray {
    NSArray *members = [NSArray arrayWithObjects:@"Keith", nil];
    return *members;
}

2 个答案:

答案 0 :(得分:1)

即使类名是变量,Phalcon也应该正确加载类。尝试将问题分解为:

$myClass='VarEducation';
$partner_obj = new $myClass();

同时尝试从您的模型列表中注释掉该特定模型,看看您的其他模型是否有效,或许找到该特定模型时出错,但其他模型却没有。检查您的/app/config/loader.php文件,确保您已注册模型目录。然后确保模型目录中存在文件VarEducation.php以及其他模型。还要确保文件中的类名与文件名匹配,并且您已将类VarEducation命名为。还要确保它没有命名空间。另外,请确保您没有忘记前导<?php并且该文件没有任何错误。如果所有其他方法都失败了,您只需从loader.php文件中加载类,如下所示:

$loader->registerClasses(array(
    'VarEducation' => $config->application->modelsDir.'/VarEducation.php'
));

确保模型的简单测试有效:$x=new VarEducation();我建议您在test操作下从索引控制器执行此操作。如果这些都不起作用,请在尝试我的建议时对结果发表评论,然后我会更新我的答案。

答案 1 :(得分:1)

无论你做什么,如果你的模型隐藏在任何命名空间中,你必须使用你的映射数组提供完整的命名空间。可以说,你的所有模型都在Application\Models的命名空间中,你必须这样使用它:

public function getUserVarPartnerModelCheckMappingArray() { 

    return array( 
        'p_education' => '\Application\Models\VarEducation', 
        'p_body' => '\Application\Models\VarBody', 
        'p_ethnicity' => '\Application\Models\VarEthnicity', 
        'p_religion' => '\Application\Models\VarReligion', 
        'p_family' => '\Application\Models\VarFamily', 
    ); 
}

并不是说我宁愿在这么少的选项上切换/大小写,而是直接使用模型,而不是手工构建SQL。

相关问题