Amazing ERROR - multiple insert on one CALL |
[eluser]Unknown[/eluser]
This thing is amazing... Here we GO! We call APP/client/run/ in client.php are defs for paths, next load model (cart) - it works. next - function run() - include of external file (module_cart.php) and init class - it also works. class Module_Cart calls add() in model... its ok.. and i got informations about added RECORD(one time). then display template (smarty included). What is so strange? "script type="text/javascript" src="{$js}lightbox.js" because of this line placed in td_news.html (template) record is ADDED 3 times!!! NO IDEA WHY. time of loading? loop? recursion? IF I "REM" this line everything is ok! info from mySQL log: 081211 11:46:46 20 Connect root@localhost on 20 Init DB mfcms 20 Query SET NAMES 'utf8' COLLATE 'utf8_general_ci' 20 Query INSERT INTO cart (product,pid) VALUES('cyce',2) 20 Quit 22 Connect root@localhost on 22 Init DB mfcms 21 Connect root@localhost on 22 Query SET NAMES 'utf8' COLLATE 'utf8_general_ci' 21 Init DB mfcms 21 Query SET NAMES 'utf8' COLLATE 'utf8_general_ci' 22 Query INSERT INTO cart (product,pid) VALUES('cyce',2) 21 Query INSERT INTO cart (product,pid) VALUES('cyce',2) 21 Quit 22 Quit CODE: function Client() { parent::Controller(); // $template_path = $this->config->site_url().'/../system/application/client/templates/'. $this->config->item('layout'); // $this->smarty->layout($this->config->item('layout')); $this->smarty->assign('app_url', $this->config->site_url().'/'); $this->smarty->assign('base_url', $this->config->site_url().'/../'); $this->smarty->assign('css', $template_path.'/css/'); $this->smarty->assign('images', $template_path.'/images/'); $this->smarty->assign('files', $template_path.'/files/'); $this->smarty->assign('js', $template_path.'/js/'); //default language $this->load->model('cart'); } function run() { //get arguments from URL via CI URI $this->uri = array_slice($this->uri->segment_array(),2); echo '<b>URI</b><br>'; print_r($this->uri); echo'<br><br>'; include('module_cart.php'); $cart = new Module_Cart($this); $id = isset($this->uri[2]) ? $this->uri[2] : 0; $id_element = isset($this->uri[3]) ? $this->uri[3] : false; $type = isset($this->uri[4]) ? $this->uri[4] : false; $this->display($id, $id_element, $type); } function display($id='', $id_element='', $type='') { echo '<br><b>DISPLAY</b><br>'; echo 'DISPLAY = '.$id.'/'.$id_element.'/'.$type.'<br>'; //$this->smarty->display('td_'.$td_template.'.html'); $this->smarty->display('td_news.html'); } } Class Module_Cart class Module_Cart { var $ci; function Module_Cart($_ci) { $this->ci = $_ci; //parent::Controller(); // echo '<br><b>MODULE CART</b><br>'; $this->add(1); } function add() { echo 'add<br>'; $this->ci->cart->add(1); } } Model is loading properly <?php class Cart extends Model { function Cart() { // Call the Model constructor parent::Model(); echo 'CART MODEL<br>'; //print_r($this); } function add($a) { echo 'cart_add (model)<br>'; //insert article_relations $record = array(); $record['product'] = 'cycki123'; $record['pid'] = $a; echo 'REC='.$record.'<br>'; print_r($record); echo'<br>'; //$this->db->insert('cart', $record); $this->db->query("INSERT INTO cart (product,pid) VALUES('cyce',2)"); } } ?> |
Welcome Guest, Not a member yet? Register Sign In |