unexpected '-' (T_OBJECT_OPERATOR) when inserting

2

I use php and codeigniter, I try to enter data and I get this:

An uncaught Exception was encountered
Type: ParseError

Message: syntax error, unexpected '->' (T_OBJECT_OPERATOR)

Filename: C:\xampp3\htdocs\CesdeCodeIgniter\application\models\main_model.php

Line Number: 29

Backtrace:

File: C:\xampp3\htdocs\CesdeCodeIgniter\application\controllers\cliente.php
Line: 11
Function: model

File: C:\xampp3\htdocs\CesdeCodeIgniter\index.php
Line: 315
Function: require_once

main_model

 class Main_model extends CI_Model  
 {  
    public function __construct() {
        //llamamos al constructor de la clase padre
        parent::__construct();

        //cargamos la base de datos
        $this->load->database();
    }       

    public function insertar($datos){
      this->db->insert('tbl_cliente', array('DocIdent'=>$datos['documentoDeIdentidad'], 
        'Nombre'=>$datos['nombre'],
        'Apellido'=>$datos['apellido'],
        'Direccion'=>$datos['direccion'],
        'Telefono'=>$datos['telefono'],
        'Estado'=>$datos['estado'],
        'FechaIngreso'=>$datos['fechaIngreso'],
        'Password'=>$datos['password']
      ));
     }

This is line 29:

this->db->insert('tbl_cliente', array('DocIdent'=>$datos['documentoDeIdentidad'], 

client (the controller)

defined('BASEPATH') OR exit('No direct script access allowed');

    class cliente extends CI_Controller{
        function __construct(){
            parent::__construct();
            $this->load->helper(array('form', 'url'));
            $this->load->library('form_validation');
            $this->load->database();
            //llamo o incluyo el modelo
            $this->load->model('main_model');

        }

        function mostrarInicio(){
            $this->load->view("inicio");
            $query = $this->db->get('tbl_cliente');
            var_dump($query->result());
        }

        function mostrarDatos(){
            $this->form_validation->set_rules('texDocumentoDeIdentidad', 'Documento de identidad', 'trim|required|max_length[12]');
            $this->form_validation->set_rules('texPassword', 'Password', 'trim|required|min_length[3]');
            $this->form_validation->set_rules('texNombre', 'Nombre', 'trim|required|min_length[3]|max_length[30]');
            $this->form_validation->set_rules('texApellido', 'Apellido', 'trim|required|min_length[3]|max_length[30]');
            $this->form_validation->set_rules('texDireccion', 'Dirección', 'trim|min_length[10]|max_length[30]');
            $this->form_validation->set_rules('texTelefono', 'Teléfono', 'trim|min_length[7]|max_length[12]');
            $this->form_validation->set_rules('texFechaIngreso', 'Fecha de ingreso', 'trim|required|min_length[8]|max_length[12]');
            $this->form_validation->set_rules('texEstado', 'Estado', 'trim|required|min_length[5]|max_length[16]');

            if($this->form_validation->run()==FALSE){
                $this->load->view('formulario_cliente');
            }
            else{

                $datos=array(
                    'documentoDeIdentidad' => $this->input->post('texDocumentoDeIdentidad'),
                    'password' => $this->input->post('texPassword'),
                    'nombre' => $this->input->post('texNombre'),
                    'apellido' => $this->input->post('texApellido'),
                    'direccion' => $this->input->post('texDireccion'),
                    'telefono' => $this->input->post('texTelefono'),
                    'fechaIngreso' => $this->input->post('texFechaIngreso'),
                    'estado' => $this->input->post('texEstado')                 
                );
                $this->main_model->insertar($datos);
                $this->load->view('formulario_cliente');
            }
        } //mostrarDatos

Customer Line 11:

$this->load->model('main_model');
    
asked by Jhon Hernández 05.10.2018 в 06:29
source

1 answer

1

The error that I can observe in this line:

this->db->insert('tbl_cliente', array('DocIdent'=>$datos['documentoDeIdentidad'], 

Is that you are using this without the dollar sign $ should be like this

$this->db->insert('tbl_cliente', array('DocIdent'=>$datos['documentoDeIdentidad'], 

why?

  • if you leave this that's like if you were declaring a constant but in an incorrect way
  • must be $this because it is the reserved word that is used to indicate the current object, with this we also indicate that we are within the scope of a class
  • answered by 05.10.2018 / 06:40
    source