CodeIgniter Forums
Call functions in to model.. - Printable Version

+- CodeIgniter Forums (https://forum.codeigniter.com)
+-- Forum: Archived Discussions (https://forum.codeigniter.com/forumdisplay.php?fid=20)
+--- Forum: Archived Development & Programming (https://forum.codeigniter.com/forumdisplay.php?fid=23)
+--- Thread: Call functions in to model.. (/showthread.php?tid=18327)

Pages: 1 2


Call functions in to model.. - El Forum - 05-03-2009

[eluser]Yorick Peterse[/eluser]
[quote author="tnathos" date="1241390895"]same error....

Fatal error: Call to undefined method ClientModel::resta() in[/quote]

Take a look at the error, you probably misspelled the function.


Call functions in to model.. - El Forum - 05-03-2009

[eluser]tnathos[/eluser]
Not the code works fine in the same rotuine but when put in the other function show this error..

in the controller i need load the two functions or only the function what at the second function??


Call functions in to model.. - El Forum - 05-04-2009

[eluser]tnathos[/eluser]
any can help me?


Call functions in to model.. - El Forum - 05-04-2009

[eluser]n0xie[/eluser]
[quote author="tnathos" date="1241381608"]
I THINK WHAT CAN BE....

<?php

MODEL

FUNCTION A {
CALL FUNCTION C
delete * table b
}

FUNCTION B {
CALL FUNCTION C
delete * table a
}

FUNCTION C {
insert into table a field a, b. parametres -> post xxxxx
}

?>[/quote]
I'm guessing that you're trying to polymorphing. I hope this is what you're looking for:

Code:
<?php
/**
* Test Model
*/
class Test_model extends Model {

  function Test_model()
  {
    parent::Model();
  }

  function A($params)
  {
    $table = 'sometable';
    $this->C($params);
    $this->db->delete($table);
  }

  function B($params)
  {
    $table = 'someothertable';
    $this->C($params);
    $this->db->delete($table);
  }

  function C($params)
  {
    $table = 'yetanothertable';
    $this->db->insert($table, $params);
  }
}

/**
* Controller
*/

class Test extends Controller {

function Test(){
  parent::Controller();
  $this->load->model('test_model','test');
}

function doA()
{
  $someparams = array();
  $this->test->A($someparams);
}


function doB()
{
  $someparams = array();
  $this->test->B($someparams);
}
}

This might have typo's in it since I'm writing it from the top of my head.


Call functions in to model.. - El Forum - 05-04-2009

[eluser]tnathos[/eluser]
The problem is the

function B($params)
{
$table = 'someothertable';
$this->C($params);
$this->db->delete($table);
}

generete the error....Fatal error: Call to undefined method testModel:: C() in


Call functions in to model.. - El Forum - 05-04-2009

[eluser]tnathos[/eluser]
this is the funtion.. what do bad?

function resta(){
$restTransa = array ('quota'=> $this->session->userdata('valPlatOr') - $this->input->post('valTrans'),
'dateChange'=>mdate("%Y-%m-%d %h:%i:%a", time()));
$this->db->where('idBalance',$this->session->userdata('idBalance'));
$this->db->update('table',$restTransa);
}