Welcome, Guest
Username: Password: Remember me
  • Page:
  • 1

TOPIC:

Retrieve a single item by ID 17 Feb 2016 04:10 #13820

  • vlemos
  • vlemos's Avatar Topic Author
  • Away
  • Elite Member
  • Elite Member
  • Posts: 295
  • Thank you received: 41
Hello Admin

In a legacy Cook component, the code below worked well to retrieve a single item by ID. Now it gives an error. Any ideas why?

Thanks in advance
vlemos

	// load linked model (addresses)
	$model = CkJModel::getInstance('demoitem', 'DemoModel');

	// Define the SQL context
	$model->setState('context', 'demoitem.demoitem');

	// Call the state explicitly
	$model->setState('demoitem.demoitem', true);

	// Complete the object by inserting the addresses into the item
	$item = $model->getItem($id);

Please Log in or Create an account to join the conversation.

Retrieve a single item by ID 17 Feb 2016 12:26 #13821

  • admin
  • admin's Avatar
  • Offline
  • Administrator
  • Administrator
  • Chef
  • Posts: 3711
  • Thank you received: 986
What is the error ?
Coding is now a piece of cake

Please Log in or Create an account to join the conversation.

Retrieve a single item by ID 17 Feb 2016 13:28 #13822

  • vlemos
  • vlemos's Avatar Topic Author
  • Away
  • Elite Member
  • Elite Member
  • Posts: 295
  • Thank you received: 41
Sorry:

Fatal error: Call to a member function getKeyName() on boolean in . . . \demo\libraries\legacy\model\admin.php on line 950

Please Log in or Create an account to join the conversation.

Retrieve a single item by ID 18 Feb 2016 09:29 #13823

Why do you do this?

$model->setState('demoitem.demoitem', true);
You do not even need to set any state

If you have the singular model, the only two line you need are:
$model = CkJModel::getInstance('demoitem', 'DemoModel');
$item = $model->getItem($id);

Assuming you $id has a value

You can use a state if you want:
$model = CkJModel::getInstance('demoitem', 'DemoModel');
$model->setState('demoitem.id', $id);
$item = $model->getItem();
The following user(s) said Thank You: admin, vlemos

Please Log in or Create an account to join the conversation.

Last edit: by Romkabouter.

Retrieve a single item by ID 18 Feb 2016 10:46 #13824

  • admin
  • admin's Avatar
  • Offline
  • Administrator
  • Administrator
  • Chef
  • Posts: 3711
  • Thank you received: 986
Yes, Romkabouter, you are right.
K++

In cook, the way is to set the ID we are searching in the state var. "[itemname].id"
But getItem($id), would be nice also and I try to make it working if possible properly.

I'll check that later. For the moment, just use the state var.

You can make your own fork by yourself if you want to use the model that way.
Fork the model item superclass :
classes/model/item.php
Coding is now a piece of cake
The following user(s) said Thank You: vlemos

Please Log in or Create an account to join the conversation.

Retrieve a single item by ID 18 Feb 2016 11:40 #13825

  • vlemos
  • vlemos's Avatar Topic Author
  • Away
  • Elite Member
  • Elite Member
  • Posts: 295
  • Thank you received: 41
Hello Romkabouter / Admin

If you have the singular model, the only two line you need are:

   $model = CkJModel::getInstance('demoitem', 'DemoModel');
   $item = $model->getItem($id);

Assuming you $id has a value

You can use a state if you want:
   $model = CkJModel::getInstance('demoitem', 'DemoModel');
   $model->setState('demoitem.id', $id);
   $item = $model->getItem();


I tried both of these methods before posting; they do not work anymore in my modules.

Thanks again
vlemos

Fatal error: Call to a member function getKeyName() on boolean in  ....\demo\libraries\legacy\model\admin.php on line 950

Please Log in or Create an account to join the conversation.

Retrieve a single item by ID 18 Feb 2016 11:51 #13826

  • admin
  • admin's Avatar
  • Offline
  • Administrator
  • Administrator
  • Chef
  • Posts: 3711
  • Thank you received: 986
Only in module ?
So it means that a file is missing in the loader.

The last change achieved on the loader is this ticket :
www.j-cook.pro/index.php/forum/18-closed...ing-in-joomla-module
You remember for sure because YOU fixed it. lol.

Guess you don't have problem when the module appears on the page of the component where all dependencies are loaded.

getKeyName()
Is called on a Table object. Search that way.


Try to force loading (include_once) of the concerned missing class in the component loader.
Or at least some explicit XxxLoader::register() furnishing the class name and the full file path.

Hope it helps.

In case... same component than previous ticket ?
Coding is now a piece of cake
The following user(s) said Thank You: vlemos

Please Log in or Create an account to join the conversation.

  • Page:
  • 1
Time to create page: 0.069 seconds

Hi All just wanted to add one more "thank you" voice to all those who discovered the value of this amazing application. The website I was working on went to production few days ago and I do not want to even try to imagine what would it take to build it without j-cook. So - endless thanks keep it running and evolving I believe it deserves to be the core tool for any joomla application! Thanks!
Michael (bmk028 - Forum)  

Get Started