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

TOPIC:

Connecting to J-Cook from external Scripts / Crons 30 Jan 2013 18:49 #6575

  • vlemos
  • vlemos's Avatar Topic Author
  • Offline
  • Elite Member
  • Elite Member
  • Posts: 295
  • Thank you received: 41
Hello admin / fellow cooks

I have been trying to write a cron for a site on which my jcook component is installed and working well. I wanted to reuse the tables/models of the component to carry out all db tasks but with zero luck.

I am unsure that my approach is the correct one for the component framework. The getInstance method fails on cimport('classes.jtable'); Part of my code is shown below:
// retrieve the contact who's ID is $id
JTable::addIncludePath(JPATH_ADMINISTRATOR.DS.'components'.DS.'com_erm'.DS.'tables');
$row = JTable::getInstance('contacts', 'EmrlTable', $options=array());
$row->load($id);
I have looked throughout the forum for external scripts/cron examples but nothing like my scenario has been published yet. If the above code is pointed to a Joomla core table it works well but not so on the j-cook framework. Maybe I don't know how to ask it politely...

Any pointers/examples/urls on how to accomplish connecting from an external script would be a great help.

Thanks & regards
vlemos

JS Framework JQuery
Embed Framework Yes
Form style Exploded
Features Maximum
TODO No

DB automatisms Model
Timeout loading 30s

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

Last edit: by vlemos.

Re: Connecting to J-Cook from external Scripts / Crons 31 Jan 2013 21:52 #6603

  • JoomGuy
  • JoomGuy's Avatar
  • Offline
  • Moderator
  • Moderator
  • Joomla Enthusiast, Lover of Cooking
  • Posts: 1115
  • Thank you received: 195
Hi @vlemos

Have you seen this post - j-cook.pro/forum/19-new-tickets/5628-err...ction--solution#5754 ?

I think that this approach using JLoader will suit your needs.

Hope it helps,

Gez
Need help with your Cook/Joomla Project? . PM me to find out what I can help with. NO time wasters please!!!
The following user(s) said Thank You: vlemos

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

Re: Connecting to J-Cook from external Scripts / Crons 01 Feb 2013 13:09 #6605

  • vlemos
  • vlemos's Avatar Topic Author
  • Offline
  • Elite Member
  • Elite Member
  • Posts: 295
  • Thank you received: 41
Hello Gez, thanks a lot. I will review... V

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

Re: Connecting to J-Cook from external Scripts / Crons 01 Feb 2013 15:05 #6608

  • JoomGuy
  • JoomGuy's Avatar
  • Offline
  • Moderator
  • Moderator
  • Joomla Enthusiast, Lover of Cooking
  • Posts: 1115
  • Thank you received: 195
No probs, hope it gets you where you need to be ;)
Need help with your Cook/Joomla Project? . PM me to find out what I can help with. NO time wasters please!!!

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

Re: Connecting to J-Cook from external Scripts / Crons 03 Feb 2013 17:47 #6620

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

Thanks for the link. I was able to use some of its info to connect to my J-Cook component. As you are aware, J-Cook uses a number of unique definitions which need to be declared in the external script before connection is seamless. I will share what I have found here to help others who may be looking for this type of info:
	@define('COM_DEMO', 'com_demo');
	@define('JPATH_ADMIN_DEMO', JPATH_ADMINISTRATOR . DS . 'components' . DS . COM_DEMO);
	@define('JPATH_SITE_DEMO', JPATH_SITE . DS . 'components' . DS . COM_DEMO);

	//Shortcut to include component libraries
	if (!function_exists('cimport')){
		function cimport($namespace, $option = 'com_demo', $className = null){
			//Check if class already exists
			if (($className) && class_exists($className))
				return;
			@require_once JPATH_ADMINISTRATOR .DS. 'components' .DS. $option . DS . str_replace(".", DS, $namespace) . '.php';
		}
	}

	require_once(JPATH_ADMIN_DEMO .DS.'helpers'.DS.'helper.php');
	JHTML::_("behavior.framework");

	// Set the table directory
	JTable::addIncludePath(JPATH_ADMIN_DEMO . DS . 'tables');

This allows the retrieval of data via:
	JLoader::import( 'news', JPATH_ADMINISTRATOR . DS . 'components' . DS . 'com_demo' . DS . 'models' );
	$news = JModel::getInstance( 'news', 'DemoModel' );
	$news->setState( 'title', $title );
	$row = $news->getItems();


Save is also possible via
	JLoader::import( 'newsitem', JPATH_COMPONENT_ADMINISTRATOR . DS . 'com_demo' . DS . 'models' );
	$news = JModel::getInstance( 'newsitem', 'DemoModel' );
	$news->save( $item );


My last issue is getting j-cook to return the ID of the newly inserted record.

I have tried insertid() without any success...
$model->_db->insertid();

If you can shed any light on how to return the ID after insert it would be greatly appreciated. However, I will continue looking as well.

Thanks & regards
vlemos
The following user(s) said Thank You: JoomGuy

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

Re: Connecting to J-Cook from external Scripts / Crons 03 Feb 2013 17:58 #6621

  • JoomGuy
  • JoomGuy's Avatar
  • Offline
  • Moderator
  • Moderator
  • Joomla Enthusiast, Lover of Cooking
  • Posts: 1115
  • Thank you received: 195
Hi @Vlemos,

Thanks for sharing! K+1!!!

Regarding your insertid() question, have you tried to get that from the table store method?

Gez
Need help with your Cook/Joomla Project? . PM me to find out what I can help with. NO time wasters please!!!

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

Re: Connecting to J-Cook from external Scripts / Crons 03 Feb 2013 18:37 #6622

  • vlemos
  • vlemos's Avatar Topic Author
  • Offline
  • Elite Member
  • Elite Member
  • Posts: 295
  • Thank you received: 41
I will research it but I don't know if store is a method which is available on the model.

thx
v

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

Re: Connecting to J-Cook from external Scripts / Crons 04 Feb 2013 01:48 #6625

  • vlemos
  • vlemos's Avatar Topic Author
  • Offline
  • Elite Member
  • Elite Member
  • Posts: 295
  • Thank you received: 41
My final code looks more like this:
// where $item is an array with elements corresponding to the field-names of the 'newsitem' table
JTable::addIncludePath( JPATH_ADMINISTRATOR.DS.'components'.DS.'com_demo'.DS.'tables' );
$row =& JTable::getInstance('newsitem', 'DemoTable', $options=array());
if( $row->bind($item) ) {
	$row->store();
	return $row->id;
}
return false;
Thanks again for all your feedback.
vlemos
The following user(s) said Thank You: JoomGuy

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

Last edit: by vlemos.

Re: Connecting to J-Cook from external Scripts / Crons 04 Feb 2013 08:21 #6626

  • JoomGuy
  • JoomGuy's Avatar
  • Offline
  • Moderator
  • Moderator
  • Joomla Enthusiast, Lover of Cooking
  • Posts: 1115
  • Thank you received: 195
Thanks for sharing again @vlemos!

Gez
Need help with your Cook/Joomla Project? . PM me to find out what I can help with. NO time wasters please!!!

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

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

  I am so so so looking forward to see how far this can go. Seems like the skies the limit at the moment.
Kevin (Forum) 

Get Started