Jump to content
  • 0

Plugin Development Problem,how To Use Record In Plugin's Controller?


ty0716

Question

1: Can i user Record->select()  method in plugin's controller?

 

if use $this->Record->select()->from("clients");  then this page return 500.

 

 

or this need to add some use("") ?

Or can only be used in the plugin's model to database query?

 

2:How can i use API to achieve some plugin's method or model function?

 

3:I want to custom plugin's page title.

 

THS!

Link to comment
Share on other sites

4 answers to this question

Recommended Posts

  • 0

The API makes public model methods available, but it sounds like you're looking for language that represents the plugin name. In this case you don't want to fetch information from the plugin directly, but instead want to fetch the plugin details from the PluginManager.

 

e.g.

$response = $api->get("plugin_manager", "get", array('plugin_id' => 1, 'detailed' => true));

To open a ticket from the API, you can use the Support Manager plugin included with Blesta and make two calls to 1) create the ticket and 2) add the ticket reply to the ticket. e.g.

$ticket_data = array(
    'ticket_id' => 1, // the ID of the ticket that was just created
    'vars' => array(
        'department_id' => 1, // ticket belongs to this department
        'staff_id' => 1, // ticket assigned this staff user
        'service_id' => null, // ticket is in relation to this service
        'client_id' => 1, // ticket belongs to this client
        'email' => null, // ticket was emailed into the system from this address
        'summary' => "I have an issue", // summary line of the ticket
        'priority' => "critical", // priority of the ticket
        'status' => "open", // status of the ticket
    )
);
$response = $api->get("support_manager.support_manager_tickets", "add", $ticket_data);

# TODO: make sure the ticket is actually created, then add a reply to it
$reply_data = array(
    'vars' => array(
        'staff_id' => null, // the reply is from this staff user
        'client_id' => 1, // the reply is from this client user
        'contact_id' => null, // the reply is from this client contact user
        'type' => "reply", // this is a ticket reply
        'details' => "My issue is that...", // the ticket reply description
        'department_id' => 1, // the ticket's assigned department
        'summary' => "I have an issue", // summary line of the ticket
        'priority' => "critical", // priority of the ticket
        'status' => "open", // status of the ticket
        'ticket_staff_id' => null, // the staff user the ticket is assigned to
    ),
    'files' => null,
    'new_ticket' => true // this reply is for a newly created ticket
);
$response = $api->post("support_manager.support_manager_tickets", "addReply", $reply_data);
Link to comment
Share on other sites

  • 0

1: Can i user Record->select()  method in plugin's controller?

 

if use $this->Record->select()->from("clients");  then this page return 500.

 

 

or this need to add some use("") ?

Or can only be used in the plugin's model to database query?

 

2:How can i use API to achieve some plugin's method or model function?

 

3:I want to custom plugin's page title.

 

THS!

 

1- Yes you can but you must call the Record component first, however, since the plugins design follows the MVC pattern, you better create a model for the database interaction.

Link to comment
Share on other sites

  • 0

1: Can i user Record->select()  method in plugin's controller?

 

It's possible, but not recommended for the aforementioned reason of breaking the MVC design pattern. It is simpler for the controller to just call a plugin's model that creates the query and returns the results.

 

 

2:How can i use API to achieve some plugin's method or model function?

 

Take a look here. Call the API using the plugin's name and model, e.g. consider fetching a support department from the support manager plugin:

$response = $api->get("support_manager.support_manager_departments", "get", array('department_id' => 1));

3:I want to custom plugin's page title.

 

Could you clarify?

Link to comment
Share on other sites

  • 0

It's possible, but not recommended for the aforementioned reason of breaking the MVC design pattern. It is simpler for the controller to just call a plugin's model that creates the query and returns the results.

 

 

 

Take a look here. Call the API using the plugin's name and model, e.g. consider fetching a support department from the support manager plugin:

$response = $api->get("support_manager.support_manager_departments", "get", array('department_id' => 1));

Could you clarify?

 

 

I need to change the title of the plugin to display in the client page.

$response = $api->get("support_manager.support_manager_departments", "get", array('department_id' => 1));

Is this method also can be used for open ticket?

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Answer this question...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...
×
×
  • Create New...