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?
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'); } }
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);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 ?
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?
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”));
Packet Tide owns and develops ExpressionEngine. © Packet Tide, All Rights Reserved.