We use cookies to improve your experience. No personal information is gathered and we don't serve ads. Cookies Policy.

ExpressionEngine Logo ExpressionEngine
Features Pricing Support Find A Developer
Partners Upgrades
Blog Add-Ons Learn
Docs Forums University
Log In or Sign Up
Log In Sign Up
ExpressionEngine Logo
Features Pro new Support Find A Developer
Partners Upgrades
Blog Add-Ons Learn
Docs Forums University Blog
  • Home
  • Forums

Creating Module Links - Disallowed Characters

Development and Programming

Codehack's avatar
Codehack
2 posts
15 years ago
Codehack's avatar Codehack

I’m trying to create a module that uses Ajax on the backend. Since this has a Control Panel backend, I need to do ajax calls to the module. I’ve tried unsuccessfully to generate calls to the module using EE links and constants, but I keep running against roadblocks. The generated links have semicolons, which in turn generate ‘Disallowed Character’ errors.

Ex: In my javascript code

var link = <?= BASE. AMP .'C=addons_modules'.AMP.'M=show_module_cp'.AMP.'module=featured'.AMP.'method=find_franchise'; ?>

No matter how I code it, even when I specifically use the ‘&’ character, EE strips it out and replaces it with &

Suggestions?

       
Victor Michnowicz's avatar
Victor Michnowicz
95 posts
about 15 years ago
Victor Michnowicz's avatar Victor Michnowicz

This prolly is not best way to do this, but I added another action in the exp_actions table. In the upd.my_module.php file I have the following:

$data = array(
    'module_name' => 'My_module' ,
    'module_version' => $this->version,
    'has_cp_backend' => 'y',
    'has_publish_fields' => 'n'
);

$this->EE->db->insert('modules', $data);

// For exp_actions
$data = array('class' => 'My_module', 'method' => 'i_love_ajax');

$this->EE->db->insert('actions', $data);

This allows you to use then use some JS like this:

$.post(BASE_URL, {
        ACT: $(new_option).find('input[name="ee_polls_ajax_add_option_action_id"]').val(), // Action ID
        my_module: 'is cool',
        i_am: 'also cool'
    }, function(data) {
        console.log〈data〉;
}, 'json');

(“BASE_URL” is a JS variable with the base URL of the site)

However, by doing this, you let anyone access this i_love_ajax method. Inside this method you must make sure that the current user is allowed to access. You can do this by checking the current member group ID.

this->session->userdata('group_id')

If the group ID is 1, then you got a super admin and they can access it for sure. If its not 1 you should check the module_member_groups table.

There is probably a way better way of doing this… but its the only thing I could come up with.

       
Codehack's avatar
Codehack
2 posts
about 15 years ago
Codehack's avatar Codehack

Thanks, it seems like after lots of searching and the discussion on this thread:

http://ellislab.com/forums/viewthread/175788/

the actions table method is the generally accepted way to do it.

       
Parse19's avatar
Parse19
44 posts
about 15 years ago
Parse19's avatar Parse19

I’m not sure if this applies or not, but here is an overview of making AJAX calls within the CP. You can solve your original problem with using some JS variables EE generates.

http://forrst.com/posts/ExpressionEngine_Control_Panel_AJAX-OZJ

       
Victor Michnowicz's avatar
Victor Michnowicz
95 posts
about 15 years ago
Victor Michnowicz's avatar Victor Michnowicz

^ Sweet, thanks dude.

       

Reply

Sign In To Reply

ExpressionEngine Home Features Pro Contact Version Support
Learn Docs University Forums
Resources Support Add-Ons Partners Blog
Privacy Terms Trademark Use License

Packet Tide owns and develops ExpressionEngine. © Packet Tide, All Rights Reserved.