The Joomla! Forum ™



Forum rules


Please use the mailing list here: http://groups.google.com/group/joomla-dev-general rather than this forum.



Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 9 posts ] 
Author Message
PostPosted: Sun Aug 10, 2008 8:58 pm 
Joomla! Fledgling
Joomla! Fledgling

Joined: Wed Jun 28, 2006 10:43 pm
Posts: 3
I wrote an application that I want to interface with Joomla. Everything works fine, but the final piece is that when a member views the page, I want them to see only their own information. This means that I have to know which user is viewing the page.

I'm trying to use this code to do this:
Code:
require('../libraries/joomla/factory.php');
$user =& JFactory::getUser();
$user_id = $user->id;


Once I know the user id I can do my own processing. However, the result of this code is:

Fatal error: Call to undefined function jimport() in /home/(username)/public_html/libraries/joomla/factory.php on line 159

How do I make it so that I can grab the userid of the viewing user in my application? Please help!

Thank you


Top
 Profile  
 
PostPosted: Sun Aug 10, 2008 9:01 pm 
User avatar
Joomla! Exemplar
Joomla! Exemplar

Joined: Fri Sep 09, 2005 2:13 pm
Posts: 7962
Location: The Netherlands
Mod Note: Topic moved to Joomla! 1.5 Development Forum

_________________
Robert Dam - Joomla Forum Moderator
Dutch Boards | Joomla Coding Boards | English Support Boards


Top
 Profile  
 
PostPosted: Mon Aug 11, 2008 7:51 pm 
Joomla! Enthusiast
Joomla! Enthusiast

Joined: Thu Aug 24, 2006 3:59 pm
Posts: 103
mhamberg wrote:
I wrote an application that I want to interface with Joomla. Everything works fine, but the final piece is that when a member views the page, I want them to see only their own information. This means that I have to know which user is viewing the page.

I'm trying to use this code to do this:
Code:
require('../libraries/joomla/factory.php');
$user =& JFactory::getUser();
$user_id = $user->id;


Once I know the user id I can do my own processing. However, the result of this code is:

Fatal error: Call to undefined function jimport() in /home/(username)/public_html/libraries/joomla/factory.php on line 159

How do I make it so that I can grab the userid of the viewing user in my application? Please help!

Thank you


If you look in index.php you'll see the following

Code:
define('JPATH_BASE', dirname(__FILE__) );

define( 'DS', DIRECTORY_SEPARATOR );

require_once ( JPATH_BASE .DS.'includes'.DS.'defines.php' );
require_once ( JPATH_BASE .DS.'includes'.DS.'framework.php' );


Those two includes import the framework, including JFactory, into the execution path. Be aware that you may run into other issues related to including the Joomla! framework in your application. Several are technical, such as how Joomla! handles sessions, the possibility of function/class collision, etc. Another one is legal in nature. Joomla! is licensed under the GNU Public License (GPL) and the license requires any derived work that is distributed to be licensed under a compatible license.


Top
 Profile  
 
PostPosted: Tue Aug 12, 2008 11:40 pm 
Joomla! Fledgling
Joomla! Fledgling

Joined: Wed Jun 28, 2006 10:43 pm
Posts: 3
Thanks, I had to fix a couple of other things like you mentioned. I ended up having to move the code into the root directory because putting it in a subdirectory was giving me 'restricted access.' I also had to initialize the application.

Here's the code that I needed in total:
Code:
// Set flag that this is a parent file
define( '_JEXEC', 1 );

define('JPATH_BASE', dirname(__FILE__) );

define( 'DS', DIRECTORY_SEPARATOR );

require_once ( JPATH_BASE .DS.'includes'.DS.'defines.php' );
require_once ( JPATH_BASE .DS.'includes'.DS.'framework.php' );

require('libraries/joomla/factory.php');

// initialize the application
$mainframe =& JFactory::getApplication('site');
$mainframe->initialise();

....

// Take in user id parameter to only show for a specific user
$user =& JFactory::getUser();
$user_id = $user->get('id');


Top
 Profile  
 
PostPosted: Mon May 11, 2009 12:23 am 
Joomla! Intern
Joomla! Intern

Joined: Fri Feb 20, 2009 12:30 am
Posts: 81
mhamberg wrote:
Thanks, I had to fix a couple of other things like you mentioned. I ended up having to move the code into the root directory because putting it in a subdirectory was giving me 'restricted access.' I also had to initialize the application.

Here's the code that I needed in total:
Code:
// Set flag that this is a parent file
define( '_JEXEC', 1 );

define('JPATH_BASE', dirname(__FILE__) );

define( 'DS', DIRECTORY_SEPARATOR );

require_once ( JPATH_BASE .DS.'includes'.DS.'defines.php' );
require_once ( JPATH_BASE .DS.'includes'.DS.'framework.php' );

require('libraries/joomla/factory.php');

// initialize the application
$mainframe =& JFactory::getApplication('site');
$mainframe->initialise();

....

// Take in user id parameter to only show for a specific user
$user =& JFactory::getUser();
$user_id = $user->get('id');


Hi!!

I've been using this same code to integrate tinybrowser with tinyMCE editor with user folders function. The folders are created correctly by userid, the upload procees is working fine....but finally the click to insert function from tinybrowser is broken, if I deleted the code to get joomla userid, the "click to insert" works again.

Any idea how can I solve this?? Maybe deinit framework after I get userid?? If so, how can I deinit framework??


Top
 Profile  
 
PostPosted: Wed May 20, 2009 10:54 am 
User avatar
Joomla! Apprentice
Joomla! Apprentice

Joined: Sun Apr 06, 2008 11:29 pm
Posts: 17
Location: Italy
your code gives me a :

"No configuration file found and no installation code available. Exiting.."

any idea?? what's missing?


Top
 Profile  
 
PostPosted: Wed May 20, 2009 12:22 pm 
Joomla! Intern
Joomla! Intern

Joined: Fri Feb 20, 2009 12:30 am
Posts: 81
autodafe wrote:
your code gives me a :

"No configuration file found and no installation code available. Exiting.."

any idea?? what's missing?


Try the next, it's working very nice for me: (notice that you must change the number for $currentfolderlevel

Code:
define( 'DS', DIRECTORY_SEPARATOR );
$rootFolder = explode(DS,dirname(__FILE__));
   
//current level in diretoty structure
$currentfolderlevel = 9;

array_splice($rootFolder,-$currentfolderlevel);

$base_folder = implode(DS,$rootFolder);


if(is_dir($base_folder.DS.'libraries'.DS.'joomla'))   
{
   
   define( '_JEXEC', 1 );
   
   define('JPATH_BASE',implode(DS,$rootFolder));
   
   require_once ( JPATH_BASE .DS.'includes'.DS.'defines.php' );
        require_once ( JPATH_BASE .DS.'includes'.DS.'framework.php' );
        $userid='';
        $usertype='';
$mainframe =& JFactory::getApplication('site');
$mainframe->initialise();
$user =& JFactory::getUser();
$userid = $user->get('id');
$usertype = $user->get('usertype');
}


Top
 Profile  
 
PostPosted: Wed May 20, 2009 1:24 pm 
User avatar
Joomla! Apprentice
Joomla! Apprentice

Joined: Sun Apr 06, 2008 11:29 pm
Posts: 17
Location: Italy
I solved it by putting my php file inthe root directory...Which looks more ore less the direction you ponted me to with your code...
ut then I realized that this was not what I needed and had to wor out something else.
Thanks a lot anyway


Top
 Profile  
 
PostPosted: Thu Sep 08, 2011 11:54 pm 
Joomla! Apprentice
Joomla! Apprentice

Joined: Thu Aug 11, 2011 8:20 am
Posts: 12
so thankful for your work. solved my issue i just tried a couple hours on. Thank You!

_________________
Barter Exchange Management (http://www.barter-sites.com) for Joomla!


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 9 posts ] 



Who is online

Users browsing this forum: No registered users and 9 guests


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Jump to:  
Powered by phpBB® Forum Software © phpBB Group