Welcome Guest, Not a member yet? Register   Sign In
Hi, custom class as library (under singleton) not insert from array
#1

Hi for all, i have this situation.. 

i has created a custom class and i use like :

in my model 

PHP Code:
<?php
error_reporting
(E_ALL);
require_once(
APPPATH.'libraries/Sercon.php');
require_once(
APPPATH.'libraries/Serbus.php');
require_once(
APPPATH.'libraries/Noveltie.php');

class 
Model_admin extends CI_Model {

}
//end of model 


in method of model

PHP Code:
public function createNoveltie$data ){

 
   
    $this
->NoveltieNoveltie::getInstance();
    
$this->Noveltie->initialize(array('date'='2019-05-26''IdCompany'=>8));
    
    
$data["some"] = $data_new;
    
    
$this->Noveltie->createFromArray$data );



in my controller 


PHP Code:
public function setdispatch(){
    
$data=$_POST;
    
$user=$this->home->createNoveltie($data);
    echo 
$user;




PHP Code:
<?php defined('BASEPATH') OR exit('No direct script access allowed');

//include APPPATH.'third_party/Braintree.php';
class Noveltie {
 
 
  
// private const ASIGNADO=22;
 
 // private const NOASIGNADO=21;
 
 
  public $CI
 
  public $user
="";
 
 public $started=false;
 
 public $services = array();
 
 //....

 
 private function __construct(){

 
   $this->CI =& get_instance();
 
   $this->CI->load->helper('url');
 
   $this->CI->load->library('session');
 
   $this->CI->config->item('base_url');
 
   $this->CI->load->database();
 
  
    $this
->user=$this->CI->session->userdata('username-admin');
 
   array_push($this->log,"Class noveltie has been instantiated \n");
 
   
  
}

 
 public function initialize($data){
 
   $this->IdEmpresa $data["IdCompany"];
 
   $this->fecha $data["date"];
 
   $this->started true;
 
   array_push($this->log,"Se inicializo clase Noveltie \n");
 
   array_push($this->log,"No hay una novedad \n");
 
 }
 
 
 

  public 
function getlog$lines,&$place ){

 
 }
 
 
  public 
function createFromArray($datos){
    
    
this NOT work.. 
    
$this->CI->db->insert("my_table",$datos);
    
    
//this work
 
   foreach $datos as $llave => $valor ){
 
     $this->CI->db->set($llave,$valor);
 
   }
 
   $this->CI->db->insert("my_table");
 
 }

 
 public function test(){
 
   // var_dump($this->collection);return;
 
   array_push($this->log,"En test \n");
 
   
    $this
->CI->db->set('campo',"phphp");
 
   $this->CI->db->insert("test");

 
   array_push($this->log,$this->CI->db->_error_message()." \n");
 
   array_push($this->log,"En test salida \n");
 
   
  
}

 
 public static function getInstance() {
 
     if (self::$_instance === null) {
 
         self::$_instance = new self();
 
     }
 
     return self::$_instance;
 
   }
    
}
//end of class 



why not insert from arra in custom class...?

Version : 2.1.3 php 5.6
Reply




Theme © iAndrew 2016 - Forum software by © MyBB