Is this the correct way to create an application?
It seems to work for me. But I'd love to have suggestions on how to do it better, or if there is a better way.
I wanted to have a side panel with some modules from vanilla (e.g. categories and bookmarks) in a custom application.
Actually, it would be great if @Todd or x00 or someone else explained how to retrieve the modules that are displayed in the discussions panel in a custom app. It would be handy to know, if there is a better way than the following.
But here's how I did it - it may not be the best way....
assuming your new application is called myapp. pay close attention to folder names and where you copy things from...
**you have the following folders created** applications/myapp/controllers/class.myappcontroller.php applications/myapp/js applications/myapp/locale applications/myapp/models applications/myapp/modules/ (copy the modules from /applications/vanilla/modules into applications/myapp/modules) applications/myapp/settings applications/myapp/views/modules (copy the modules from /applications/vanilla/views/modules into applications/myapp/views/modules) applications/myapp/views/myapp/index.php
in /applications/myapp/views/myapp/index.php <?php if (!defined('APPLICATION')) exit(); echo " <h1> My MyApp Application </h1>"; // your own custom module $this->AddModule('MyAppModule', 'Panel'); // some pre-existing vanilla modules $this->AddModule('BookMarkedModule','Panel'); $this->AddModule('CategoriesModule','Panel');
in /applications/myapp/modules/class.myappmodule.php <?php if (!defined('APPLICATION')) exit(); class MyAppModule extends Gdn_Module { public function AssetTarget() { return 'Panel'; } public function ToString() { echo " <div id=\"MyApp\" class=\"Box MyAppBox\">"; echo " <ul class=\"PanelInfo PanelMyApp\">"; echo " <h4>"; echo T('This is my app module'); echo " </h4>"; echo " </ul> </div>"; } }
in /applications/myapp/controllers/class.myappcontroller.php <?php if (!defined('APPLICATION')) exit(); class MyAppController extends Gdn_Controller { /** @var array List of objects to prep. They will be available as $this->$Name. */ // $this->Uses = array('Form'); public $Uses = array('Database', 'DiscussionModel', 'Form'); /** * If you use a constructor, always call parent. * Delete this if you don't need it. * * @access public */ public function __construct() { parent::__construct(); } /** * This is a good place to include JS, CSS, and modules used by all methods of this controller. * * Always called by dispatcher before controller's requested method. * * @since 1.0 * @access public */ // public function Initialize() { // There are 4 delivery types used by Render(). // DELIVERY_TYPE_ALL is the default and indicates an entire page view. // if ($this->DeliveryType() == DELIVERY_TYPE_ALL) // $this->Head = new HeadModule($this); // Call Gdn_Controller's Initialize() as well. public function Initialize() { $this->Permission('Garden.SignIn.Allow'); if ($this->DeliveryType() == DELIVERY_TYPE_ALL) { $this->Head = new HeadModule($this); $this->AddJsFile('jquery.js'); $this->AddJsFile('jquery.livequery.js'); $this->AddJsFile('jquery.form.js'); $this->AddJsFile('jquery.popup.js'); $this->AddJsFile('jquery.gardenhandleajaxform.js'); $this->AddJsFile('jquery.gardenmorepager.js'); $this->AddJsFile('jquery.autogrow.js'); $this->AddJsFile('jquery.autocomplete.js'); $this->AddJsFile('global.js'); } $this->AddCssFile('style.css'); parent::Initialize(); } public function index() { $this->Render(); } }
I may not provide the completed solution you might desire, but I do try to provide honest suggestions to help you solve your issue.
Comments
This place was going to the dogs without you ... where do I send you the money?
❌ ✊ ♥. ¸. ••. ¸♥¸. ••. ¸♥ ✊ ❌
You should be able to just use vanilla and dashboard modules, by using AddModule, shouldn't have to copy them to your app.
grep is your friend.
@peregrine please can you change your sig to NO.... from N0
There was an error rendering this rich post.
thanks x00 - I tried your suggestion - but it doesn't seem to work for me. If you have more insights...
@x00 said:
using the same exact code as posted in my first comment above but NOT copying over the
results in bookmarks and categories not showing up within my app sidepanel.
However, after copying the two modules into applications/myapp/modules the bookmarks and categories show up in side panel.
It's a bit puzzling to me. It looks like they have to be copied, unless there is a way around it.
edit: I just saw this in the module documentation:
http://vanillaforums.org/docs/modules
"Modules are application-specific, and are located in the application's "modules" folder."
thanks for the sig fix @422
I may not provide the completed solution you might desire, but I do try to provide honest suggestions to help you solve your issue.
Yes you are absolutely right, though dashborad modules like UserInfoModule, SignedInModule, and GuestModule do not have to be copied. They can be called in vanilla app, but only reside in dashboard.
grep is your friend.