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

TOPIC:

Load data attached to user ID? URGENT 12 Jul 2016 17:01 #14211

Is there any way I can load data attached to a users ID dynamically? Basically I have a user data page overview and want to load the data attached to the logged in user. I'm Guessing in the model somwhere? any guidance would be greatly appreciated.

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

Last edit: by bennett.d.design. Reason: Need help quickly

Load data attached to user ID? URGENT 12 Jul 2016 22:25 #14214

Any one got any ideas? Im currently looking into the com_users component but it seems it loads data diffrently... All I need to know is how to set the active CID from the model...

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

Last edit: by bennett.d.design.

Load data attached to user ID? URGENT 12 Jul 2016 23:47 #14216

Not sure I am totally clear on what you want to achieve but:
$user_id	 = JFactory::getUser()->id;
If ($user_id. . . . .

Will get you the current user id and Ajax could be used to load the data you need.
The following user(s) said Thank You: admin

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

Last edit: by vlemos.

Load data attached to user ID? URGENT 12 Jul 2016 23:50 #14217

yea ive got that but i need to set the cid[] from the model. I have managed to populate the fields in a form using
protected function loadFormData() {
	$user = JFactory::getUser();
	if($user->id != 0) {
		$this->setState('userdetails.id', 3);
		$this->setState('userdetails.first_name','test');
		$data = $this->getItem(3);
	}
}
this is just using hardcoded variables I will do a SQL search to get the one I need
however this does not show any data in the fly views...

but if i can set the cid[] var thats passed in the url then this would be unneeded...

Thanks for the help anyway

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

Last edit: by bennett.d.design.

Load data attached to user ID? URGENT 13 Jul 2016 00:22 #14218

Which file are you working in, . . . \views\useritem\ view.html.php?

Are you looking for something like:
if($user->id != 0) {
header( 'Location: ' . JURI::base() . 'index.php/. . . .cid[0]=' . $user->id
:(

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

Last edit: by vlemos.

Load data attached to user ID? URGENT 13 Jul 2016 01:44 #14220

Thanks but Id like to do it from the model to avoid having to reload the page... I'm using a jquery hack to add the cid to the url at the mo

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

Load data attached to user ID? URGENT 13 Jul 2016 03:32 #14221

Still not totally sure what you require but good luck.

if you need an Ajax solution then it can be done with a bit of JavaScript and a call to the "view.html.php" like this:
JS:
var url = "index.php?option=com_demo&view=users&layout=ajax&render=userinfo";

PHP:
protected function displayAjax($tpl = null)
	{
		$jinput = JFactory::getApplication()->input;
		$render = $jinput->get('render', null, 'CMD');
		$token = $jinput->get('token', null, 'BASE64');
		$values = $jinput->get('values', null, 'ARRAY');

		switch($render)
		{
			case 'userinfo':
	
				$user = JFactory::getUser();
				$model = $this->getModel();
				$model->setState('filter.user_id', $user->id);
				$item = $model->getItems()[0];

				echo json_encode($item);
				.
				.
				.



Or the loadFormData Method should allow you to pass the user id in a filter like "&filter_user_id=1" as part of the url
/**
* Method to get the data that should be injected in the form.
*
* @access	protected
*
* @return	mixed	The data for the form.
*/
protected function loadFormData()
{
	// Check the session for previously entered form data.
	$data = JFactory::getApplication()->getUserState('com_demo.edit.useritem.data', array());

	if (empty($data)) {
		//Default values shown in the form for new item creation
		$data = $this->getItem();

		// Prime some default values.
		if ($this->getState('useritem.id') == 0)
		{
			$jinput = JFactory::getApplication()->input;

			$data->id = 0;
			.
			.
			.
			$data->user_id = $jinput->get('filter_user_id', $this->getState('filter.user_id'), 'INT');
The following user(s) said Thank You: bennett.d.design

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

Last edit: by vlemos.

Load data attached to user ID? URGENT 13 Jul 2016 14:40 #14229

This is the hack I've ended up using...
<?php
	if($user->id) {
		$db = JFactory::getDbo();
		$query = $db->getQuery(true);

		$query->select($db->quoteName('id'));
		$query->from($db->quoteName('#__bartschoir_userinformation'));
		$query->where($db->quoteName('user_id') . ' LIKE '. $db->quote($user->id));
 
		$db->setQuery($query);
		$db->execute();

		$account_id = $db->loadResult();
?>
	jQuery(document).ready(function() {
		jQuery(".item-159").html( '<a href="index.php/members/my-account?cid='+<?php echo $account_id; ?>+'">My Account</a>' );
		jQuery(".item-161").html( '<a href="index.php/members/edit-account?cid='+<?php echo $account_id; ?>+'">Edit Account</a>' );
	});
<?php
	}
?>

Thanks though, I still would have prefered to do it through the model... but ah well ay.

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

Load data attached to user ID? URGENT 13 Jul 2016 15:32 #14230

This wouldn't really be my first approach but for the model add it like this; it needs a filter in the model though.

jQuery(".item-159").html( '<a href="index.php/members/my-account?cid='
	+ <?php if($user->id) {
			$model = CkJModel::getInstance('Userinformation', 'BartschoirModel');
			$model->setState('filter.user_id', $user->id);
			$account = $model->getItems()[0];

			echo $account->id; 
		?>
	+ '">My Account</a>
The following user(s) said Thank You: bennett.d.design

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

Last edit: by vlemos.
  • Page:
  • 1
Time to create page: 0.131 seconds

Awards for the best Joomla app. This product is gonna win an award for this amazing job. Cook Self Service is the the best application from all over the Joomla universe ! It brings Joomla to a professional level really advanced for developers. It is a real fun to develop with it. The ACL part and security checks implementation are just... so much hours saved. I can now concentrate myself more on the design part and the creative works. Thank you so much. Guys I offer you all my congratulation ! Keep up the works because Joomla is needing it to increase the quality of extensions availables on the JED. I also learned a lot because I can see how to code at the proper place and I found all my answers reading the forum.
lack_hanson (JED)
          

Get Started