2

私は PyroCMS でモジュールを構築しており、その構造を作成しています。Streams API を使用してフォームを作成し、アクションを実行しています。また、ダミーのインストールを実行して、すべてが正常に見えるかどうかを確認しています。その後、ダミーの内容を変更し、構造を完成させました。ただし、details.phpファイルでは、別のストリーム (現在のストリームの後に定義されている他のストリーム) からフィールドを取得するために、外部キー (API 用語を知っている場合はフィールドの関係タイプ) を作成する場所を変更しました。モジュールをインストールすると、「モジュールをインストールできませんでした」というエラーが表示されますが、モジュールがインストールされていることがわかります。外部キー参照をコメントアウトしようとしましたが、問題は解決しません。

ここに私の details.php ファイルがあります:

class Module_Employer extends Module {

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:install()関数で個別の名前空間が定義された3つのストリームがありました)。私は次のものしか持っていませんでした:

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

このため、他のストリームはシステムに「存在」していましたが、表面的にはモジュールがアンインストールされ、モジュールを再インストールしようとすると、テーブル/ストリームの作成中にモジュールをインストールできませんでしたというエラーが発生しましたデータベースでは、テーブルがすでに存在しているため、クエリは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 に答える