⚠ In case you've missed it, we have migrated to our new website, with a brand new forum. For more details about the migration you can read our blog post for website migration. This is an archived forum. ⚠

  •     

profile picture

Mysql view error



kolo78

kolo78
  • profile picture
  • Member

Posted 08 November 2016 - 01:05 AM

Hello I'm facing a problem with a Mysql view.

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

class Lstmatfinal extends CI_Controller
{

    function __construct()
    {
        parent::__construct();
        $this->load->helper('url');
        $this->load->library('grocery_CRUD');
    }

    public function index()
    {
        $crud = new grocery_CRUD();
        $crud->set_table('Inscriptos');
        $crud-> $this->set_primary_key('inscfinal_id','Inscriptos');

        $output = $crud->render();
        $this->_example_output($output);
    }


    function _example_output($output = null)

    {
        $this->load->view('Principal.php', $output);
    }
}

and the error is the following

A PHP Error was encountered

Severity: 4096

Message: Object of class Lstmatfinal could not be converted to string

Filename: controllers/Lstmatfinal.php

Line Number: 19

Backtrace:

File: /var/www/html/CodeIgniter/application/controllers/Lstmatfinal.php
Line: 19
Function: _error_handler

File: /var/www/html/CodeIgniter/index.php
Line: 292
Function: require_once

A PHP Error was encountered

Severity: Notice

Message: Object of class Lstmatfinal to string conversion

Filename: controllers/Lstmatfinal.php

Line Number: 19

Backtrace:

File: /var/www/html/CodeIgniter/application/controllers/Lstmatfinal.php
Line: 19
Function: _error_handler

File: /var/www/html/CodeIgniter/index.php
Line: 292
Function: require_once

A PHP Error was encountered

Severity: Notice

Message: Undefined property: Grocery_CRUD::$Object

Filename: controllers/Lstmatfinal.php

Line Number: 19

Backtrace:

File: /var/www/html/CodeIgniter/application/controllers/Lstmatfinal.php
Line: 19
Function: _error_handler

File: /var/www/html/CodeIgniter/index.php
Line: 292
Function: require_once


( ! ) Fatal error: Call to a member function set_primary_key() on a non-object in /var/www/html/CodeIgniter/application/controllers/Lstmatfinal.php on line 19
Call Stack
#	Time	Memory	Function	Location
1	0.0001	231320	{main}( )	../index.php:0
2	0.0003	234632	require_once( '/var/www/html/CodeIgniter/system/core/CodeIgniter.php' )	../index.php:292
3	0.0068	1041944	call_user_func_array ( )	../CodeIgniter.php:514
4	0.0068	1042248	Lstmatfinal->index( )	../CodeIgniter.php:514
A PHP Error was encountered

Severity: Error

Message: Call to a member function set_primary_key() on a non-object

Filename: controllers/Lstmatfinal.php

Line Number: 19

Backtrace:

Any help will be highly appreciated!! :)

 

--- More information added to the question ---

 

Table "Inscriptos" is the Mysql view, it's somethins like this 

CREATE VIEW Inscriptos AS SELECT inscfinal_id, materia.materia_nombre AS Materia,
            fechafinales.final_fecha as Fecha, alumno_nombre AS Alumno, alumno_dni AS DNI ,
            insfinal_datetime_stamp as Timestamp
                FROM inscripcionfinales INNER JOIN alumno ON insfinal_alumno_id = alumno_id
                INNER JOIN fechafinales ON inscfinal_final_id = fechafinales.final_id
                INNER JOIN materia ON fechafinales.final_mat_id = materia.materia_id

Regards,

Pablo


semsik

semsik
  • profile picture
  • Member

Posted 08 November 2016 - 22:44 PM

Check your controller line 19!
I'm pretty sure that its

$crud->set_primary_key('inscfinal_id','Inscriptos');

Instead of

$crud-> $this->set_primary_key('inscfinal_id','Inscriptos');

See API

http://www.grocerycrud.com/documentation/options_functions/set_primary_key

Greetz

kolo78

kolo78
  • profile picture
  • Member

Posted 09 November 2016 - 00:48 AM

@semsik thank you very much for your help. It work like a charm ... A very simple question when one has the answer :)