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

Embed Not Working as Advertised

Development and Programming

emorling's avatar
emorling
66 posts
14 years ago
emorling's avatar emorling

I have a template that lists the latest entries in a channel.

I have another template that first inserts a new entry from a form post and then calls the first template. However it does not include the latest inserted entry. It seems that the Embed tag does not work as advertised. It seems the embedded template that lists entries is run before the new entry is inserted.

Any ideas?

       
emorling's avatar
emorling
66 posts
14 years ago
emorling's avatar emorling

Maybe the solution is to call a template from an addon, but how do I do that? The template class documentation seems more concerned with a template calling a module..

       
the3mus1can's avatar
the3mus1can
426 posts
14 years ago
the3mus1can's avatar the3mus1can

Can you post some of the code from the second template that is inserting the entry?

       
Bjørn Børresen's avatar
Bjørn Børresen
629 posts
14 years ago
Bjørn Børresen's avatar Bjørn Børresen

You have access to the template class -> $this->EE->TMPL .. have a look in libraries/Template.php and see what functions you can run. (ie. for instance the run_template_engine(templage_group_name, template_name))

       
emorling's avatar
emorling
66 posts
14 years ago
emorling's avatar emorling
Can you post some of the code from the second template that is inserting the entry?

Sure, this is the function in the addon that takes care of the post and creates a new entry:

function ajax_send(){ $this->EE->load->library(‘api’); $this->EE->api->instantiate(‘channel_entries’); $this->EE->api->instantiate(‘channel_fields’); if(!isset($_POST[‘msg’])){return;} $message = trim($_POST[‘msg’]); $loggedin = false; if ($this->EE->session->userdata(‘member_id’)>0){$loggedin = true;} if(!$loggedin || !strlen($message)){return;} $data = array( ‘title’ => $message,’entry_date’ => time(),); if ($this->EE->api_channel_entries->submit_new_entry(5, $data) === FALSE) { show_error('An Error Occurred Creating the Entry'); } }
       
the3mus1can's avatar
the3mus1can
426 posts
14 years ago
the3mus1can's avatar the3mus1can

I have used code like below to load and parse a template inside of an addon before:

$this->EE->load->library('template', NULL, 'my_template');
                
    $this->EE->my_template->depth = 1;
        
    $this->EE->my_template->fetch_and_parse($template_group, $template_name, FALSE);
        
    $template = $this->EE->my_template->parse_globals($this->EE->my_template->final_template);
       
emorling's avatar
emorling
66 posts
14 years ago
emorling's avatar emorling

Thanks. The template code works, but the entries still will not display the last entry I inserted. Any ideas?

       
emorling's avatar
emorling
66 posts
14 years ago
emorling's avatar emorling

OK Either 1) the “$this->EE->api_channel_entries->submit_new_entry” function does not runat once, but rather later on e.g. when the template has completed processing

OR

2) The “$this->EE->channel_entries_model->get_entries” is cached somehow and therfore not showing the latest insertion

Any ideas ?

       
emorling's avatar
emorling
66 posts
14 years ago
emorling's avatar emorling

By querying the database using the CI Active Record class I can see that the insertion is occuring at once (like it should). The problem is then that the get_entries method is run by a cache or similar?

       
emorling's avatar
emorling
66 posts
14 years ago
emorling's avatar emorling

I am stuck. Any ideas at all?

       
the3mus1can's avatar
the3mus1can
426 posts
14 years ago
the3mus1can's avatar the3mus1can

Do you have to go through the channel_entries_model? If you are able to query and see the record has been created then just create your own model in your add-on and run the query inside there yourself.

       
emorling's avatar
emorling
66 posts
14 years ago
emorling's avatar emorling

Hm. Yes I guess this would be possible, but it will grow cumbersome as I use this approach on many ajax functions on the site. It doesn’t really “feel” right. Should I already be giving up on the channel_entries model? I have a feeling that if I can get to the root of the problem I can use the regular entries tag like I set out to do in the first place. Is there nothing else I can try, do or understand before giving up entirely?

       
emorling's avatar
emorling
66 posts
14 years ago
emorling's avatar emorling

This is just SO strange. If I create a new instance of the channel_entries_model it works. Is this the only way? Is there no reset() function… on models?

$this->EE->load->model(“channel_entries_model”, “my_entries”, TRUE); $this->EE->db->limit(3); $this->EE->db->order_by(“entry_id”, “desc”); $query_result = $this->EE->my_entries->get_entries($channel_id, array(“author_id”,”title”,”entry_date”));
       

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.