⚠ In case you've missed it we are migrating to our new website, with a brand new forum. For more details about the migration you can read our blog post for website migration. Very soon this forum will be read-only and archived. ⚠


Try to "CRUD" from a view

views tables

  • Please log in to reply
8 replies to this topic

#1 JPintor

JPintor

    Newbie

  • Members
  • Pip
  • 5 posts

Posted 24 August 2012 - 11:31 AM

Hello again friends!!!

I have a new question, sorry for my english but I try to explain me:


I have 2 tables:

clients(id,name, distributor)

Distributors(id,name)



and 1 view:

dist_cli(id,name, number_of_clients)


I can work with the view????
Because the normal way use (the table way use) not work

someone idea??
thanks for you time!!

#2 web-johnny

web-johnny

    grocery CRUD Author

  • Administrators
  • 1,166 posts

Posted 24 August 2012 - 01:25 PM

You have to add the primary_key if you want to add a view. For example:

$crud->set_table('dist_cli');
$crud->set_primary_key('id');


#3 saulimus

saulimus

    Advanced Member

  • Members
  • PipPipPip
  • 40 posts

Posted 24 August 2012 - 01:25 PM

Set the primary key for the view and it will work:
http://www.grocerycr...set_primary_key

set_primary_key('ID', 'dist_cli')

You might have a problem because both your tables have the primary key as 'ID' so it can't guess which one you're referring to.
You'd have to try and see what happens... but I guess it would be ok if you only use the view for reading data.

#4 JPintor

JPintor

    Newbie

  • Members
  • Pip
  • 5 posts

Posted 27 August 2012 - 08:11 AM

thank you very much for the two!!

I continue work with Grocery CRUD!! I'ts fantastic

#5 RazorLegacy

RazorLegacy

    Newbie

  • Members
  • Pip
  • 1 posts

Posted 16 October 2013 - 06:39 PM

CREATE TABLE IF NOT EXISTS `videos` (
  `id` int(11) NOT NULL AUTO_INCREMENT,
  `active` enum('0','1') NOT NULL DEFAULT '1',
  `title` varchar(255) NOT NULL,
  `deck` mediumtext NOT NULL,
  `thumb` enum('0','1','2') NOT NULL DEFAULT '0',
  PRIMARY KEY (`id`),
  KEY `thumb` (`thumb`),
  KEY `active` (`active`)
) ENGINE=MyISAM  DEFAULT CHARSET=utf8 AUTO_INCREMENT=4337 ;

I apologize for bringing up a old post but I am having the same issue and my table does have the primary key all set up properly. No code changes were made but now I get "Fatal error: Cannot access empty property in app/libraries/Grocery_CRUD.php on line 1556"

 

Using PHP 5.5.4 and PDO, GroceryCRUD 1.4.1

 

Everything was working perfectly but then just stopped all of a sudden this morning.

 

var_dump($data->list) displays all table data to screen with no issues but the following is where the issue is. app/libraries/Grocery_CRUD.php

		foreach($data->list as $num_row => $row)
		{
			$data->list[$num_row]->edit_url = $data->edit_url.'/'.$row->{$data->primary_key};
			$data->list[$num_row]->delete_url = $data->delete_url.'/'.$row->{$data->primary_key};
			$data->list[$num_row]->read_url = $data->read_url.'/'.$row->{$data->primary_key};
		}

What is wrong here? Any suggestions are welcome.



#6 majd94

majd94

    Newbie

  • Members
  • Pip
  • 5 posts

Posted 09 April 2021 - 06:22 PM

You have to add the primary_key if you want to add a view. For example:
 

$crud->set_table('dist_cli');
$crud->set_primary_key('id');

 

I am using GC Enterprise und want to crud from a view. I did put the primary key and the table has correctly loaded. But when I click on read a row, it appears this error We can't process the response of the server. This is all we know about it:

Summary: 500 - Internal Server Error

Error: error

Response:



#7 web-johnny

web-johnny

    grocery CRUD Author

  • Administrators
  • 1,166 posts

Posted 10 April 2021 - 07:48 AM

I am using GC Enterprise und want to crud from a view. I did put the primary key and the table has correctly loaded. But when I click on read a row, it appears this error We can't process the response of the server. This is all we know about it:

Summary: 500 - Internal Server Error

Error: error

Response:

 

Hello @majd94,

 

This is a very generic error and it can be anything really  :)

I have created a YouTube video for that to see how to debug it https://youtu.be/X0gnDD0qTS8 Although this is for Grocery CRUD community edition you can follow the same steps for Grocery CRUD Enterprise as well.

 

Let me know if that helped.

 

Regards

Johnny



#8 majd94

majd94

    Newbie

  • Members
  • Pip
  • 5 posts

Posted 10 April 2021 - 09:57 AM

Hello John, thanks for your reply. I really have checked every thing, seemed to be a connection database error only when click on read, edit (by using view as a table). Do you have a solution?
This is the response that I get when calling a specific row:

An uncaught Exception was encountered

Type: Zend\Db\Adapter\Exception\InvalidQueryException

Message: You have an error in your SQL syntax; check the manual that corresponds to your MariaDB server version for the right syntax to use near '= '1'' at line 1

Filename: C:\xampp\htdocs\plesung\application\libraries\GroceryCrudEnterprise\zendframework\zend-db\src\Adapter\Driver\Mysqli\Connection.php

Line Number: 240

 

 

 



#9 majd94

majd94

    Newbie

  • Members
  • Pip
  • 5 posts

Posted 13 April 2021 - 12:14 PM

Any idea?







Also tagged with one or more of these keywords: views, tables

0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users