How to create a snapin

aarondwyer

New Member
Hi

Is there any documentation on how to go about making a snapin?

I've modeled off the existing ones in the snapin folder. But I'm not sure how to do it properly.

I would like to have it show up in the menu under "Accounts" / "Packages"

Aaron
 

CE-Matt

Administrator
Staff member
We don't really have any docs for this yet.

You should be able to call:

Code:
$this->addMappingForTopMenu('admin', 'clients', 'templateName', 'title', 'desc');
Then make sure you have a function called templateName() in your Snapin, as well as a templateName.phtml in the snapin directory, and that will be the view that is used.

Once you activate the snapin and enable the permissions, log out of CE and back in to force it to re-load the menu.
 

aarondwyer

New Member
Ok I now have a link in the menu. Thank you for that.

I have generated the content that I want to show in the view() function.

How do I get content from the view function to show inside CE?

Code:
function view()
{
    $output = '<h3>Snapin Output</h3>';

    return $this->view->render('snapinname.phtml');
}
In the snapinname.phtml file do I just put this to show the content?

Code:
<?php echo $output; ?>
Aaron
 

CE-Matt

Administrator
Staff member
You don't need to do any HTML in the function. Just have a view.phtml in the directory and it'll render that HTML. If you need to pass any variables, just set them in $this->view->varName in that function.
 

aarondwyer

New Member
Hi Matt

Sorry but I don't seem to be able to work it out. I can't get the output from the script into the view.phtml file and onto the screen.

I have attached a basic snapin example where I'm looking to get a link in the menu (which works) and then get some content to get to the screen in CE.

I'm probably missing something very basic. Any ideas?

I can reach the snapin page from a linked menu item like this...

CEinstall/admin/index.php?fuse=admin&view=viewsnapin&controller=snapins&plugin=snapinexample&h=dG9wbWVudTow

Aaron
 

Attachments

Last edited:

CE-Matt

Administrator
Staff member
Since you're calling snapinexample in the addMappingForTopMenu, that is the function and view name that'll be returned.

Just add any PHP code to the snapinexample function, and any HTML to snapinexample.phtml and you should be good
 

aarondwyer

New Member
Ok thanks, I've tried that, and still not getting the PHP parsed into the CE view. Sorry but I must be missing something simple here. Seems fairly straight forward a concept. Any ideas?

I only have 2 files in my snapinexample now.

This is my snapinexample.phtml

Code:
Snapin Example on snapinexample.phtml
<br>
<?php echo $output; ?>
<br>
{END}
This is my PluginSnapinexample.php

Code:
<?php
require_once 'modules/admin/models/SnapinPlugin.php';

class PluginSnapinexample extends SnapinPlugin
{
    public function getVariables()
    {
        $variables = [
            lang('Plugin Name')       => [
                'type'        => 'hidden',
                'description' => 'Snapin Example Description',
                'value'       => 'Snapin Example',
            ]
        ];
        
        return $variables;
    }

    function init()
    {
        $this->setDescription("This is a snapin example description.");
        $this->setPermissionLocation("clients");
        $this->addMappingForTopMenu("admin","clients","snapinexample","Snapin Example Menu","Snapin Example Description Menu");
    }

    function snapinexample()
    {
        $output = '<h3>Snapin Example from snapinexample PHP</h3>';
    
        return $output;
    }
        
}
?>
 

CE-Matt

Administrator
Staff member
Ah, sorry!

Code:
Snapin Example on snapinexample.phtml
<br>
<?php echo $this->output; ?>
<br>
Code:
function snapinexample()
{
    $this->view->output = '<h3>Snapin Example from snapinexample PHP</h3>';    
}
That should work for you now.
 

hadi

Member
Hello
Ah, sorry!

Code:
Snapin Example on snapinexample.phtml
<br>
<?php echo $this->output; ?>
<br>
Code:
function snapinexample()
{
    $this->view->output = '<h3>Snapin Example from snapinexample PHP</h3>';   
}
That should work for you now.
Could you tell me how can I include a HTML file here ?
Thanks
 

CE-Matt

Administrator
Staff member
The function name that is called for the view (snapinexample) will look for snapinexample.phtml.
 

hadi

Member
Consider we submit form in view.phtml
so we can now$_GET['v']==process in view.phtml function.
How can I render a new page, for example, secondpage.phtml ?
 
Top