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

Executing a PHP script within the EE/CI framework so as to have the methods/variables available

Development and Programming

Focus Lab Dev Team's avatar
Focus Lab Dev Team
1,129 posts
15 years ago
Focus Lab Dev Team's avatar Focus Lab Dev Team
I had no idea about accessories and process_request. Super awesome. I’m not sure if that’s in the docs anywhere.

Yea that’s a real gem that would have been great to know about.

Can you guys add it to the docs, Pascal?

       
moonbeetle's avatar
moonbeetle
81 posts
15 years ago
moonbeetle's avatar moonbeetle

Thx! Jamie

Removing the _acc suffix on the URL (and some tweaking in my method) did the trick.

       
Darren Miller's avatar
Darren Miller
103 posts
15 years ago
Darren Miller's avatar Darren Miller
I had no idea about accessories and process_request. Super awesome. I’m not sure if that’s in the docs anywhere.

Agreed. I’m gonna remember that one!

       
Leevi Graham's avatar
Leevi Graham
1,143 posts
15 years ago
Leevi Graham's avatar Leevi Graham

It’s worth noting that the method MUST start with “process_”. Here’s the CP code that does the checking:

// only methods beginning with 'process_' are allowed to be called via this method
if (($name = $this->input->get_post('accessory')) === FALSE
OR ($method = $this->input->get_post('method')) === FALSE
OR strncmp($method, 'process_', 8) != 0)
{
    return $this->index();
}

Not sure why “OR strncmp($method, ‘process_’, 8) != 0)” needs to be checked considering a method_exists conditional is further down the routine.

       
Carl W Crawley's avatar
Carl W Crawley
136 posts
15 years ago
Carl W Crawley's avatar Carl W Crawley

Just a quick one that I’d like to follow up regarding the get_safe_refresh()

I’m calling it as part of the process_xxx function to get a URL and then redirect to it - however, I’m noticing on some pages (such as on the ‘snippets’ page), it’s returning a 404 Page error when trying to redirect.

Do I need to pass the output of the $this->EE->cp->get_safe_refresh() into the process_xxx function instead?

Finally, with using the refresh - I don’t seem to be able to get alerts/confirmations using the notify() functionality. How would you recommend executing the process_xx function, redirecting the user back to the page (with the updated information from the process) and display the confirmation message in the header onload.

Hope this makes sense.

Cheers,

C.

       
box-head's avatar
box-head
177 posts
15 years ago
box-head's avatar box-head

Does anybody have any clues to how you would execute a PHP script within the EE/CI framework (so the methods/variables are available) by an action on the front-end such as clicking a link?

I’ve read about doing this if the link is from within the CP (as covered so far in this thread) but I’ve not found anything about executing a module script/method by front-end interaction.

Thanks.

       
Rob Sanchez's avatar
Rob Sanchez
335 posts
15 years ago
Rob Sanchez's avatar Rob Sanchez

Your module actions are executed at http://yoursite.com/index.php?ACT=XX, where XX is the action_id.

You can create a link like so:

$this->EE->functions->fetch_site_index(0, 0).QUERY_MARKER.'ACT='.$this->EE->functions->fetch_action_id('My_module', 'my_action');
       
box-head's avatar
box-head
177 posts
15 years ago
box-head's avatar box-head

Hi Rob,

Thanks for the help. Really appreciate it. Do we have to use the querystring to send over the Action ID? or can we post it and any other variables?

Thanks

       
Rob Sanchez's avatar
Rob Sanchez
335 posts
15 years ago
Rob Sanchez's avatar Rob Sanchez

If you’re POST-ing, no need for the query string, you can POST straight to index.php with your ACT in place.

       
box-head's avatar
box-head
177 posts
15 years ago
box-head's avatar box-head

Great! Life saver. Thank you so much.

       
taktak's avatar
taktak
24 posts
15 years ago
taktak's avatar taktak

I’ve written an accessory that lets you select different entries and ajax-posts the entry_id to a process_ function in my accessory PHP.

It looked to work great at first, I generated a link that looked like this:

<a href="http://.BASE.AMP.C=addons_accessories.AMP.M=process_request.AMP.accessory=cp_mpleads.AMP.method=process_quiz_dataid=base_path">Base Path</a>';

Clicking it brings up my process_quiz_data method, outputting “Entry_ID:” in an empty page. But when I try to reach it using ajax POST(or GET for that matter), it generates the HTML of a normal page. It doesn’t output my method. I’ve no idea really whats the matter. My Javascript looks like this:

$.post($('a#base_path').attr('href'),{
        entry_id: _id
    }, function(data){
        alert(data);
    }, 'html');

I was hoping for an output along the lines of “Entry_ID: 1” or similar… This is what my process_quiz_data method looks like:

[code]function process_quiz_data() {
    exit('ENTRY_ID: '. $this->EE->input->post("entry_id"));

}[/code]

Any ideas of where I’ve gone wrong?

       
1 2

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.