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

Calling the Channel Entries API: Exactly how?

Development and Programming

ffurger's avatar
ffurger
220 posts
15 years ago
ffurger's avatar ffurger

I need to add some code to a template in order to submit a new entry under certain conditions. I thought I would use this function:

$this->EE->api_channel_entries->submit_new_entry((int) $channel_id, (mixed) $data);

The User Guide says that in order to call the class I need to instantiate it first:

$this->EE->load->library('api');
$this->EE->api->instantiate('channel_entries');

That’s fine, but how do I embed this code in a template?

I am not developing a plugin, an extension or a module, I am simply relying on this class to get some work done in a template.

Thank you for your help! Franco

       
Chuck Liddell's avatar
Chuck Liddell
57 posts
15 years ago
Chuck Liddell's avatar Chuck Liddell

You can use PHP within your template, so something like this would do the trick:

$EE =& get_instance();
$EE->load->library('api');
$EE->api->instantiate('channel_entries');
$EE->api_channel_entries->submit_new_entry( $id, $data );
       
ffurger's avatar
ffurger
220 posts
15 years ago
ffurger's avatar ffurger

Thanks Chuck, I really appreciate it.

Just a quick follow-up question: what if I’d like to use Codeigniter classes in a EE2 template - any suggestions?

-Franco

       
Jamie Rumbelow's avatar
Jamie Rumbelow
546 posts
15 years ago
Jamie Rumbelow's avatar Jamie Rumbelow

You can use PHP in templates. Because you can use PHP, you can call get_instance(), and because you can call get_instance(), you can access anything inside your CodeIgniter system. ExpressionEngine is, after all, a CodeIgniter app.

$EE =& get_instance();
$EE->load->library('form_validation');
$EE->load->library('xmlrpc');
$EE->load->helper('url');
// ...
       
ffurger's avatar
ffurger
220 posts
15 years ago
ffurger's avatar ffurger

Perfect - that’s precisely want I wanted to know - thank you very much!

-Franco

       

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.