2016-01-08 3 views
14

मैं अक्टूबरसीएमएस सीखने की कोशिश कर रहा हूं और मैं प्लगइन को विस्तारित करने की पूरी प्रक्रिया के बारे में उलझन में हूं। मैंने स्क्रीनकास्ट के अनुसार उपयोगकर्ता प्लगइन बढ़ाया है (https://vimeo.com/108040919)। आखिरकार, मैं "श्रेणी" नामक एक नया क्षेत्र बनाना चाहता हूं जो एक उपयोगकर्ता श्रेणी को स्टोर करता है। एक नए पृष्ठ पर, मेरे पास निम्न प्रपत्र है जिसे मैं अपने ई-मेल पते पर आधारित एक नया उपयोगकर्ता पंजीकृत करने के लिए उपयोग करने का प्रयास कर रहा हूं। "श्रेणी" उस पृष्ठ के आधार पर आबादी है जिसे उन्होंने पंजीकृत किया है और पासवर्ड स्वचालित रूप से जेनरेट किया जाना चाहिए ताकि उपयोगकर्ता इसे ई-मेल सक्रियण लिंक से अपने खाते की पुष्टि करने पर सेट कर सके। मेरी प्लगइन को "प्रोफाइल" कहा जाता है।अक्टूबरसीएमएस प्लगइन एक्सटेंशन से फ़ील्ड के साथ कस्टम उपयोगकर्ता पंजीकरण फॉर्म कैसे बनाएं

मेरे plugin.php फ़ाइल लगता है:

<?php namespace Sser\Profile\Models; 

use Model; 
use \October\Rain\Database\Traits\Validation; 

/** 
* Profile Model 
*/ 
class Profile extends Model 
{ 
    public $rules = [ 
     'category' => ['required', 'min:0'] 
    ]; 

    /** 
    * @var string The database table used by the model. 
    */ 
    public $table = 'sser_profile_profiles'; 

    /** 
    * @var array Guarded fields 
    */ 
    protected $guarded = ['*']; 

    /** 
    * @var array Fillable fields 
    */ 
    protected $fillable = []; 

    /** 
    * @var array Relations 
    */ 
    public $hasOne = []; 
    public $hasMany = []; 
    public $belongsTo = [ 
     'user'=> ['RainLab\User\Models\User'] 
    ]; 
    public $belongsToMany = []; 
    public $morphTo = []; 
    public $morphOne = []; 
    public $morphMany = []; 
    public $attachOne = []; 
    public $attachMany = []; 

    public static function getFromUser($user) 
    { 
     if($user->profile) 
     { 
      return $user->profile; 
     } 

     $profile = new static; 
     $profile->user = $user; 
     $profile->save(); 

     $user->profile = $profile; 

     return $profile; 
    } 

} 

मैं एक उपयोगकर्ता पंजीकरण फार्म कि ऐसा दिखाई देता है बनाने के लिए कोशिश कर रहा हूँ:

<?php namespace Sser\Profile; 

use System\Classes\PluginBase; 
use RainLab\User\Models\User as UserModel; 
use RainLab\User\Controllers\Users as UsersController; 
use Sser\Profile\Models\Profile as ProfileModel; 
/** 
* Profile Plugin Information File 
*/ 
class Plugin extends PluginBase 
{ 

    /** 
    * Returns information about this plugin. 
    * 
    * @return array 
    */ 
    public function pluginDetails() 
    { 
     return [ 
      'name'  => 'Profile', 
      'description' => 'Handles user demographic information', 
      'author'  => '', 
      'icon'  => 'icon-leaf' 
     ]; 
    } 

    public function boot() 
    { 
     UserModel::extend(function($model){ 
      $model->hasOne['profile'] = ['Sser\Profile\Models\Profile']; 
     }); 
     // $user->profile->zip 

     UserModel::deleting(function($user) { 
      $user->profile->delete(); 
     }); 

     UsersController::extendFormFields(function($form,$model,$context){ 
      if(!$model instanceof UserModel) 
      { 
       return; 
      } 
      if(!$model->exists) 
      { 
       return; 
      } 
      //Ensures that a profile model always exists... 
      ProfileModel::getFromUser($model); 

      $form->addTabFields([ 
       'profile[age]'=>[ 
        'label'=>'Age', 
        'tab'=>'Profile', 
        'type'=>'number' 
       ], 
       'profile[gender]'=>[ 
        'label'=>'Gender', 
        'tab'=>'Profile', 
        'type'=> 'dropdown', 
        'options'=>array('male'=>'Male', 
            'female'=>'Female') 

       ], 
       'profile[category]'=>[ 
        'label'=>'Category', 
        'tab'=>'Profile', 
        'type'=> 'dropdown', 
        'options'=>array('sink'=>'SINK', 
            'dink'=>'DINK') 
       ], 
       'profile[vag]'=>[ 
        'label'=>'VAG', 
        'tab'=>'Profile', 
        'type'=> 'dropdown', 
        'options'=>array('v'=>'V', 
            'a'=>'A', 
            'g'=>'G') 
       ] 
      ]); 
     }); 
    } 

} 

मेरे profile.php फ़ाइल की तरह लग रहा

<form class="flexiContactForm col s12" role="form" data-request="{{ __SELF__ }}::onSignup" data-request-update="'{{ __SELF__ }}::confirm': '.confirm-container'">; 
    <button id="signup_button" class="waves-effect waves-light btn" style="float:right;" type="submit">Sign Up</button> 
    <div style="overflow: hidden; padding-right:0em;"> 
    <input id="signup_email" type="email" class="validate" name="email">    
    <label id="signup_email_label" for="signup_email" data-error="" data-success="">Email Address</label> 
    <input type="hidden" name="category" value="{{ data.category }}"/> 
    </div> 
</form> 

मुझे इस बारे में उलझन में है कि कैसे "ऑन साइनअप" घटक बनाना है जो मूल रूप से ext उपयोगकर्ता प्लगइन्स "ऑन रजिस्ट्रार" घटक की कार्यक्षमता को समाप्त करें और फिर स्वचालित रूप से एक पासवर्ड उत्पन्न करें और "श्रेणी" फ़ील्ड को भी सहेजें। क्या कोई ऐसे पृष्ठ को उदाहरण या लिंक प्रदान कर सकता है जो इसका एक उदाहरण दिखाता है? धन्यवाद।

उत्तर

1

यह निश्चित रूप से भ्रमित है। देश प्लस प्लगइन को एक गाइड और स्थान प्लगइन (आवश्यक) के रूप में देश/राज्य ड्रॉपडाउन जोड़ने के लिए देखें।

  1. आप एक नया टेबल जोड़ सकते हैं या "अद्यतन/माइग्रेशन" का उपयोग उपयोगकर्ता के लिए "category_id" की तरह कुछ जोड़ने के लिए उपयोगकर्ता की मेज पर एक क्षेत्र को जोड़ने के लिए होगा। यह आपके लिए इसे बचाएगा।

  2. सुनिश्चित करें कि यह भरने योग्य है क्योंकि उपयोगकर्ता निर्माण मॉडल को फ़ॉर्म डेटा के साथ भर देगा अन्यथा यह सहेज नहीं पाएगा। यह बूट पर है, उपयोगकर्ता के प्लस प्लगइन में यह है इसलिए इसे जांचें।

  3. श्रेणियों के लिए एक नई टेबल बनाएं, और एक घटक भाग बनाएं जो सूची ला सकता है। इसके लिए स्थान प्लगइन देखें ... वह हिस्सा जो डेटा/बीजों को सूची में लाता है वह घटक में है।

  4. आपको नए फ़ील्ड को आंशिक रूप से बनाने या सीएमएस आंशिक रूप से नए फ़ील्ड निर्दिष्ट करने की आवश्यकता होगी।

सुदूर पासवर्ड यादृच्छिक, नहीं 100% का सबसे अच्छा तरीका बना रही है, लेकिन आप onInit उपयोग कर सकते हैं के लिए अपने घटक सिर्फ प्रपत्र पोस्ट डेटा में एक बीज के रूप में। पासवर्ड फ़ील्ड को पोस्ट डेटा में जोड़ा जाना चाहिए क्योंकि उपयोगकर्ता की प्लगइन पोस्ट फ़ील्ड्स को मॉडल में पास करती है (यही कारण है कि आपको श्रेणी_आईडी को भरने योग्य के रूप में सेट करना होगा या सुरक्षा कारणों से इसे अवरुद्ध कर दिया जाएगा)।

मैं इस सामान के साथ गड़बड़ कर रहा हूं और उपयोगकर्ता प्लस स्थान प्लगइन के साथ बहुत मदद करता है।

क्षमा करें मैं और अधिक विस्तृत नहीं हो सका।

5

ठीक है, मुझे बस अपनी साइट के लिए ऐसा कुछ करना पड़ा। इसलिए मैं आपके पास 2 विकल्पों का प्रयास और व्याख्या करूंगा।
1: विषय और पृष्ठ PHP का उपयोग कर सामान ओवरराइड करें।

  1. फॉर्म को ओवरराइड करें। ऐसा करने के लिए, प्लगइन/rainlabs/उपयोगकर्ता/घटक/खाता/register.htm से विषयों/साइट-थीम/आंशिक/खाता/register.htm से रजिस्टर.htm कॉपी करें। अब आप फॉर्म को अपडेट कर सकते हैं ताकि आप जो भी फ़ील्ड चाहते हैं।

  2. अपने खाते में प्रवेश/रजिस्टर पेज, php खंड में php डाल डिफ़ॉल्ट ओवरराइड करने के लिए एजेंसियां ​​() फ़ंक्शन पर:

    title = "Account" 
    url = "/account/:code?" 
    layout = "default" 
    description = "The account page" 
    is_hidden = 0 
    
    [account] 
    redirect = "home" 
    paramCode = "code" 
    
    [session] 
    security = "all" 
    == 
    function onRegister() 
    { 
        try { 
         //Do Your Stuff (generate password, category) 
         //Inject the variables 
         return $this->account->onSignin(); 
        } 
        catch (Exception $ex) { 
         Log::error($ex); 
        } 
    } 
    == 
    

2: यह सब करने के लिए एक घटक बनाएँ। इस तरह से मैं समाप्त हो गया जा रहा

  1. php कारीगर बनाने है: घटक Foo.Bar AccountExtend अपने घटक
  2. अब घटक में जाते हैं और कुछ बातें चारों ओर बदल बनाने के लिए। सबसे पहले आपको सभी फाइलों को प्लगइन/rainlabs/उपयोगकर्ता/घटकों/खाते/प्लगइन/फू/बार/घटक/खाताextend/
  3. से कॉपी करने की आवश्यकता होगी अब आपको घटक AccountExtend.php को अद्यतन करने की आवश्यकता है। सबसे पहले, कुछ बदलाव यह सही काम करने के लिए (मैं सभी कोड, बस सामान परिवर्तन की जरूरत है कि शामिल नहीं किया है):

    use RainLab\User\Components\Account as UserAccount; 
    
    class AccountExtend extends UserAccount 
    
  4. और फिर घटक सक्रिय करने के लिए अपने प्लगइन के लिए Plugin.php फ़ाइल का अद्यतन,:

    public function registerComponents() 
        { 
         return [ 
          'Foo\Bar\Components\AccountExtend' => 'account', 
         ]; 
        } 
    
  5. अब आप अपने AccountExtend.php को एजेंसियां ​​() फ़ंक्शन जोड़ सकते हैं:

    public function onRegister() { 
         //Do anything you need to do 
    
         $redirect = parent::onRegister(); 
    
         $user = $this->user(); // This is the user that was just created, here for example, dont need to assign it really 
         // Now you can do stuff with any of the variables that were generated (such as user above) 
    
         // Return the redirect so we redirect like normal 
         return $redirect; 
        } 
    
संबंधित मुद्दे