2

我一直在 PyroCMS 中构建一个模块并制作了它的结构。我正在使用 Streams API 来构建表单并执行我的操作,还执行了一个虚拟安装以检查一切是否正常。然后我继续修改假人的内容并完成我的结构。但是,在details.php文件中,我进行了更改,创建了一个外键(字段的关系类型,如果您知道 API 术语)以从另一个流(在我当前流之后定义的另一个流)中检索一个字段,现在何时我安装了模块,它显示“无法安装模块”错误,但我可以看到模块已安装。我试图注释掉外键引用,但问题仍然存在。

这是我的 details.php 文件:

类 Module_Employer 扩展模块 {

public $version = '1.0';

public function info()
{
    return array(
        'name' => array(
            'en' => 'Employer'
        ),
        'description' => array(
            'en' => 'Module for Employer'
        ),
        'frontend' => true,
        'backend' => true,
        'menu' => 'content',
        'shortcuts' => array(
            'create' => array(
                'name' => 'Employer:new',
                'uri' => 'admin/employer/create',
                'class' => 'add'
            )
        )
    );
}



public function install()
{
    // We're using the streams API to
    // do data setup.
    $this->load->driver('Streams');

    $this->load->language('employer/emp');


    // Add streams
    if ( ! $this->streams->streams->add_stream(lang('Employer:employers'), 'employers', 'employer', null, 'This is the Employer Stream')) return false;
    if ( ! $this->streams->streams->add_stream(lang('Employer:company'), 'company', 'company', null, 'This is the Company Stream')) return false;
    if ( ! $this->streams->streams->add_stream(lang('Employer:job'), 'jobs', 'job', null, 'This is the Job Stream')) return false;

    // Fields for employers table
    $employer_fields = array(
        array(
            'name' => 'Name',
            'slug' => 'name',
            'namespace' => 'employer',
            'type' => 'text',
            'extra' => array('max_length' => 100),
            'assign' => 'employers',
            'title_column' => true,
            'required' => true,
            'unique' => true
        ),
        array(
            'name' => 'Username',
            'slug' => 'username',
            'namespace' => 'employer',
            'type' => 'text',
            'extra' => array('max_length' => 100),
            'assign' => 'employers',
            'title_column' => true,
            'required' => true,
            'unique' => true
        ),
        array(
            'name' => 'Password',
            'slug' => 'password',
            'namespace' => 'employer',
            'type' => 'encrypt',
            'extra' => array('hide_typing' => 'yes'),
            'assign' => 'employers',
            'title_column' => true,
            'required' => true,
            'unique' => true
        ),
        array(
            'name' => 'Credits',
            'slug' => 'credits',
            'namespace' => 'employer',
            'type' => 'integer',
            'extra' => array('max_length' => 10),
            'assign' => 'employers',
            'title_column' => true,
            'required' => true,
            'unique' => true
        ),  
        array(
            'name' => 'Company name',
            'slug' => 'company_name',
            'namespace' => 'employer',
            'type' => 'relationship',
            'extra' => array('choose_stream' => 'company'),
            'assign' => 'employers',
            'title_column' => true,
            'required' => false,
            'unique' => false
        )
    );
    $this->streams->fields->add_fields($employer_fields);

    //Fields for company stream
    $company_fields = array(
        array(
            'name' => 'Username',
            'slug' => 'username',
            'namespace' => 'company',
            'type' => 'relationship',
            'extra' => array('choose_stream' => 'employers'),
            'assign' => 'company',
            'title_column' => true,
            'required' => false,
            'unique' => false
        ),
        array(
            'name' => 'E-mail',
            'slug' => 'email',
            'namespace' => 'company',
            'type' => 'email',
            'assign' => 'company',
            'title_column' => true,
            'required' => true,
            'unique' => false
        ),
        array(
            'name' => 'Company Name',
            'slug' => 'company_name',
            'namespace' => 'company',
            'type' => 'text',
            'extra' => array('max_length' => 100),
            'assign' => 'company',
            'title_column' => true,
            'required' => true,
            'unique' => true
        ),
        array(
            'name' => 'Logo',
            'slug' => 'logo',
            'namespace' => 'company',
            'type' => 'image',
            'extra' => array('folder' => 'upload'),
            'assign' => 'company',
            'title_column' => true,
            'required' => false,
            'unique' => false
        ),
        array(
        'name' => 'Designation',
        'slug' => 'designation',
        'namespace' => 'company',
        'type' => 'text',
        'extra' => array('max_length' => 100),
        'assign' => 'company',
        'title_column' => true,
        'required' => false,
        'unique' => false
        ),
        array(
        'name' => 'Contact No.1',
        'slug' => 'contact1',
        'namespace' => 'company',
        'type' => 'integer',
        'extra' => array('max_length' => 10),
        'assign' => 'company',
        'title_column' => true,
        'required' => true,
        'unique' => false
        ),
        array(
        'name' => 'Contact No.2',
        'slug' => 'contact2',
        'namespace' => 'company',
        'type' => 'integer',
        'extra' => array('max_length' => 10),
        'assign' => 'company',
        'title_column' => true,
        'required' => false,
        'unique' => false
        ),
        array(
        'name' => 'Contact No.3',
        'slug' => 'contact3',
        'namespace' => 'company',
        'type' => 'integer',
        'extra' => array('max_length' => 10),
        'assign' => 'company',
        'title_column' => true,
        'required' => false,
        'unique' => false
        ),
        array(
        'name' => 'Address',
        'slug' => 'address',
        'namespace' => 'company',
        'type' => 'textarea',
        'assign' => 'company',
        'title_column' => true,
        'required' => true,
        'unique' => false
        ),
        array(
        'name' => 'Billing ddress',
        'slug' => 'billing_address',
        'namespace' => 'company',
        'type' => 'textarea',
        'assign' => 'company',
        'title_column' => true,
        'required' => true,
        'unique' => false
        ),
    );
    $this->streams->fields->add_fields($company_fields);

    //Fields for company stream
    $job_desc_fields = array(
        array(
            'name' => 'Username',
            'slug' => 'username',
            'namespace' => 'company',
            'type' => 'relationship',
            'extra' => array('choose_stream' => 'employers'),
            'assign' => 'jobs',
            'title_column' => true,
            'required' => false,
            'unique' => false
        ),
        array(
            'name' => 'Key Skills',
            'slug' => 'keyskills',
            'namespace' => 'company',
            'type' => 'textarea',
            'assign' => 'jobs',
            'title_column' => true,
            'required' => true,
            'unique' => false
        ),
        array(
            'name' => 'Position Summary',
            'slug' => 'position_summary',
            'namespace' => 'company',
            'type' => 'textarea',
            'assign' => 'jobs',
            'title_column' => true,
            'required' => false,
            'unique' => false
        ),
        array(
            'name' => 'Experience',
            'slug' => 'experience',
            'namespace' => 'company',
            'type' => 'text',
            'assign' => 'jobs',
            'title_column' => true,
            'required' => true,
            'unique' => false
        ),
        array(
            'name' => 'Industry',
            'slug' => 'industry',
            'namespace' => 'company',
            'type' => 'text',
            'assign' => 'jobs',
            'title_column' => true,
            'required' => false,
            'unique' => false
        ),
        array(
            'name' => 'Functional Area',
            'slug' => 'functional_area',
            'namespace' => 'company',
            'type' => 'text',
            'assign' => 'jobs',
            'title_column' => true,
            'required' => false,
            'unique' => false
        ),
        array(
            'name' => 'Salary',
            'slug' => 'salary',
            'namespace' => 'company',
            'type' => 'text',
            'assign' => 'jobs',
            'title_column' => true,
            'required' => false,
            'unique' => false
        ),
        array(
            'name' => 'Start Date',
            'slug' => 'start_date',
            'namespace' => 'company',
            'type' => 'datetime',
            'assign' => 'jobs',
            'extra' => array('input_type' => 'datepicker'),
            'title_column' => true,
            'required' => false,
            'unique' => false
        ),
        array(
            'name' => 'Job Type',
            'slug' => 'job_type',
            'namespace' => 'company',
            'type' => 'choice',
            'assign' => 'jobs',
            'extra' => array('input_type' => 'datepicker'),
            'title_column' => true,
            'required' => false,
            'unique' => false
        ),
    );
    return true;
}

public function uninstall()
{
    $this->load->driver('Streams');

    $this->streams->utilities->remove_namespace('employer');

    return true;
}

public function upgrade($old_version)
{
    // Your Upgrade Logic
    return true;
}

public function help()
{
    // Return a string containing help info
    // You could include a file and return it here.
    return "No documentation has been added for this module.<br />Contact the module developer for assistance.";
}

}

4

1 回答 1

1

我之前已经“安装”了该模块,但是在 uninstall() 函数下,我忘记添加删除所有流的代码(PS:我有 3 个流,在 install() 函数中定义了单独的命名空间)。我只有以下内容:

$this->streams->utilities->remove_namespace('employer');

因此,其他流在系统中“存在”,尽管从表面上看,模块已被卸载,每当我尝试重新安装模块时,我都会收到错误Could not install module,因为在创建表/流时在数据库中,查询返回FALSE,因为表已经存在。

但是,我随后添加了代码以删除所有其他流,只需在调用中包含它们的命名空间,例如:

$this->streams->utilities->remove_namespace('employer');
$this->streams->utilities->remove_namespace('job');
$this->streams->utilities->remove_namespace('company');

..问题已解决!

于 2012-07-12T06:31:32.773 回答