Please upgrade here. These earlier versions are no longer being updated and have security issues.
HackerOne users: Testing against this community violates our program's Terms of Service and will result in your bounty being denied.

Writing a config for a plugin

edited November 2010 in Vanilla 2.0 - 2.8
How do i go about writing a config page for the dashboard.
The page needs to read a table and add/update records to that table.


  • Options
    LincLinc Detroit Admin
    Config options are generally stored in the config.php file rather than the database. This plugin isn't terribly useful, but it has a simple Dashboard config page you could reverse-engineer pretty easily:
  • Options
    Thnx ill have a look.
  • Options
    Cant get the view to show. The code ive adapted form teh plugin is:
    EventArguments['SideMenu']; $Menu->AddItem('GoogleCalendar', 'GoogleCalendar'); $Menu->AddLink('GoogleCalendar', 'Settings', 'plugin/GoogleCalendar','Plugins.GoogleCalendar.Edit'); } public function Controller_Index(&$Sender) { $Sender->AddCssFile('admin.css'); // $SQL = Gdn::Structure(); // $this->$feeds= $SQL // ->Select("url,days,name,feedid") // ->From('Cals') // ->Get(); $Sender->Render($this->GetView('settings.php')); }

    and added permission
    'RegisterPermissions' => array( 'Plugins.GoogleCalendar.Edit'),
  • Options
    The menu items are added to the dashboard but i cant understand why it is not showing the view. all i see is a page not found error. Any ideas?
  • Options
    LincLinc Detroit Admin
    You're using Controller_Index without creating the controller. :)

    You need a PluginController_GoogleCalendar_Create($Sender) method with this in it:
    $this->Dispatch($Sender, $Sender->RequestArgs);
  • Options
  • Options
    HOw do you make a form in a view load data from the model or database
    so far ive got:
    public function Controller_Edit(&$Sender,$id) { $Sender->AddCssFile('admin.css'); $Sender->AddSideMenu('plugin/googlecalendar'); $validation = new Gdn_Validation(); $calModel = new Gdn_Model('Cals',$validation); $calData = $calModel->GetWhere(array('feedID' => $id))->FirstRow(); $Sender->Form->SetModel($calModel); $Sender->Form->SetData($calData); $Sender->Render($this->GetView('edit.php')); }
    and in the view
    if (!defined('APPLICATION')) exit(); echo $this->Form->Open(); echo $this->Form->Errors(); echo $this->Form->Label('Feed ID','feedid'); echo $this->Form->Input('feedid'); echo $this->Form->Label('Title','name'); echo $this->Form->Input('name'); echo $this->Form->Label('Days','days'); echo $this->Form->Input('days'); echo $this->Form->Label('Calendar URL','url'); echo $this->Form->Input('url'); echo $this->Form->Close('Save');

    Sorry about so many questions but first time ive done this and its simple things i seem to miss.
  • Options
    LincLinc Detroit Admin
    Are the form field names identical to the database field names? I see 'feedid' on the form and 'feedID' for the database.
  • Options
    the feedID was a type the lowercase version is correct.
    apart from that the field names are correct.
    Do i have to implement a model class?
  • Options
    LincLinc Detroit Admin
    Have a look at Vanilla's PostController::Discussion method from the beginning down to where it says // Save as a draft?

    It's easier to start with too much functionality and whittle down to the part you need than to try and build it from scratch the first time.
  • Options
    Ive followed that method through and i cant see anything ive forgotten.
    My form displays from the view but the content from the model does not.
    am i right in using the $id parameter like that?
    where the url is domain/plugin/GoogleCalendar/edit/7
    where $id = 7.
  • Options
    Answer no i wasnt.
    $id =$Sender->RequestArgs[1];
  • Options
    Finished thanks for all the help.
Sign In or Register to comment.