我是OctoberCMS的新手,我喜欢它的工作方式。目前我已经创建了两个插件,分别叫做产品和产品分类。我使用Builder Plugin创建了这些插件,这也是一个很好的插件,可以轻松创建另一个插件。OctoberCMS在当前插件的下拉列表中调用另一个插件的数据
现在的问题是,在我的产品类别插件,我只是有称为产品类别和用户为他/她想要将添加许多种类单一领域,这个插件正常工作。
在我产品插件,我有一个称为产品类别领域这是一个下拉领域,我希望所有那些我已经在产品类别分别插件创建的类别,但不知何故,我不能实现此功能。这是我到目前为止所尝试过的。
Plugin.php(插件\ technobrave \产品)
<?php namespace Technobrave\Products;
use System\Classes\PluginBase;
use technobrave\productcategory\Models\ProductCategory as ProductCategory;
use technobrave\products\Models\Product as ProductModel;
class Plugin extends PluginBase
{
public function registerComponents()
{
}
public function registerSettings()
{
}
public function boot()
{
ProductModel::extend(function($model){
$model->hasOne['ProductCategory'] = ['technobrave\productcategory\Models\ProductCategory'];
});
}
}
Product.php(插件\ technobrave \产品\型号)
<?php namespace Technobrave\Products\Models;
use Model;
/**
* Model
*/
class Product extends Model
{
use \October\Rain\Database\Traits\Validation;
/*
* Validation
*/
public $rules = [
'category' => 'required',
'product_brand' => 'required',
'product_channel' => 'required',
'product_type' => 'required',
'client_name' => 'required',
'project_name' => 'required',
'product_description' => 'required',
'banner_image' => 'required',
'product_images' => 'required',
];
public $customMessages = [
'category.required' => 'Please Select Product Category',
'product_brand.required' => 'Please Select Product Brand',
'product_channel.required' => 'Please Select Product Channel',
'product_type.required' => 'Please Select Product Type',
'client_name.required' => 'Please Enter Client Name',
'project_name.required' => 'Please Enter Project Name',
'product_short_description.required' => 'Please Enter Product Short Description',
'product_description.required' => 'Please Enter Product Description',
'banner_image.required' => 'Please select Product Banner Image',
'product_images.required' => 'Please select Product Image(s)',
];
/*
* Disable timestamps by default.
* Remove this line if timestamps are defined in the database table.
*/
//public $timestamps = false;
/**
* @var string The database table used by the model.
*/
public $table = 'technobrave_products_';
public $settingsFields = 'fields.yaml';
public $attachOne = [
'banner_image' => 'System\Models\File'
];
public $attachMany = [
'product_images' => 'System\Models\File'
];
public $belongsTo = [
'ProductCategory'=> ['technobrave\productcategory\Models\ProductCategory']
];
// Here i want my product dropdown categories to be dynamic
public function getCategoryOptions()
{
echo '<pre>';
print_r($ProductCategory);
exit;
//return array();
}
}
但我不断收到死亡错误消息说:
Undefin ED变量:产品分类
为此我投入Product.php
echo '<pre>';
print_r($ProductCategory);
exit;
在上述Plugin.php文件此特定代码我有以下代码
use technobrave\productcategory\Models\ProductCategory as ProductCategory;
所以通过这样做,我试图获得我已经创建的所有类别,并以某种方式试图在我的下拉列表中显示它。
我知道OctoberCMS而创建的插件,我们可以处理关系逻辑(即的hasMany,hasOne等),但现在我想以这种方式与外部插件来实现。我想在方法getCategoryOptions()
中添加要填写的类别,我将在下拉列表中返回这些类别。
有人能指导我,如果它的可能在我想要的方式吗?
谢谢