General Joomla php include question

Discussion and education for beginner / novice programmers interested in embarking on the development process to take advantage of the extensible nature of the Joomla! CMS.

Moderators: tjay, seadap, Rogue4ngel, matthewhayashida

Forum rules
Post Reply
durino13
Joomla! Fledgling
Joomla! Fledgling
Posts: 4
Joined: Fri Dec 21, 2007 2:19 pm
Contact:

General Joomla php include question

Post by durino13 » Sat Jan 26, 2008 9:57 am

I am already frustrated, as I can't find a solution to my question  :-\

I need to include a php file into my 'module project'. But because this file is somehow outside the joomla framework, I can't call the Joomla methods in this file.

Is there an easy way, how can I do this?

--

This is the usuall structure of a module in J!1.5

/mod_customname
|
|--tmpl
|  |
|  |--default.php
|
|--problem_directory
|  |
|  |--problem_file.php

|
|--helper.php
|--mod_customname.php


The problem_file.php is called from default.php. I generate an AJAX request and the problem_file.php should generate a response, which will be included in my
tag in default.php again.

The problem_file.php contains something like this:
$db = JFactory::getDBO();
....
?>

But I get the error, that the JFactory is not known. How can I properly use Joomla framework methods in this file? Btw. everything works fine, if the problem_file.php is a pure php file, e.g:

echo "works ..";
....
?>

Thx a lot in advance !! I am really stuck here.
Last edited by durino13 on Tue Feb 05, 2008 7:28 am, edited 1 time in total.

ewel
Joomla! Apprentice
Joomla! Apprentice
Posts: 37
Joined: Mon Oct 01, 2007 11:35 am

Re: General Joomla php include question

Post by ewel » Sat Jan 26, 2008 10:58 am

I would also like to know that the best way is to include or require files. So far I have always had trouble trying it.

biohazard
Joomla! Fledgling
Joomla! Fledgling
Posts: 4
Joined: Sat Jan 26, 2008 4:13 am

Re: General Joomla php include question

Post by biohazard » Sun Jan 27, 2008 1:18 am

I want to keep the article index there i just wanna know how
to RENAME it...not the ARTICLE

I WANNA RENAME THAT LIST OR TEXT IN THE ARTICLE INDEX  BOX THINGY!!!!

NightAvatar
Joomla! Fledgling
Joomla! Fledgling
Posts: 1
Joined: Mon Jan 21, 2008 9:09 pm

Re: General Joomla php include question

Post by NightAvatar » Wed Jan 30, 2008 10:42 pm

Ditto. I have the same problem.

Looks like this is a much needed feature - being able to include php files from outside the Joomla framework.

In my case, it's to included a Simple Pie coded rss parser because there isn't a good one yet for Joomla 1.5 and I need to show multiple news feeds on my front page (in one area, not only one per module like is default in Joomla).

Thanks.

User avatar
ianmac
Joomla! Enthusiast
Joomla! Enthusiast
Posts: 237
Joined: Sat Sep 24, 2005 11:01 pm
Location: Toronto, Canada

Re: General Joomla php include question

Post by ianmac » Thu Jan 31, 2008 4:43 am

Create a simple component to support your module that will handle the ajax request.

Ian
Help test my Component XML Generator Tool!
http://extensions.joomla.org/component/option,com_mtree/task,viewlink/link_id,1997/Itemid,35/
All feedback appreciated!

durino13
Joomla! Fledgling
Joomla! Fledgling
Posts: 4
Joined: Fri Dec 21, 2007 2:19 pm
Contact:

Re: General Joomla php include question

Post by durino13 » Sun Feb 03, 2008 8:50 am

ianmac wrote:Create a simple component to support your module that will handle the ajax request.

Ian


Hi Ian,

could you be pls more specific, what do you mean? It's not clear, why should I mix here with component ..

Thx

Skippdog
Joomla! Apprentice
Joomla! Apprentice
Posts: 7
Joined: Fri Jan 11, 2008 4:49 pm

Re: General Joomla php include question

Post by Skippdog » Sun Feb 03, 2008 11:56 pm

durino13 wrote:
ianmac wrote:Create a simple component to support your module that will handle the ajax request.

Ian


Hi Ian,

could you be pls more specific, what do you mean? It's not clear, why should I mix here with component ..

Thx


Components can be called "raw" from the query string to render without any of the site template or modules. This makes them good for producing data to be retrieved from AJAX. Go to any component in your joomla site and try adding &tmpl=component  to the query string to see what I mean.

I started a module which I intended to be AJAX enabled, and ended up making a component that would deliver this data to the module. The problem is that modules cannot be called to the browser directly, but components can.

It's not the "cleanest" solution in the world, but it works fine and lets you stay within the Joomla framework. A better solution should certainly be developed in the future for people who want to develop AJAX data providers from within the framework.

durino13
Joomla! Fledgling
Joomla! Fledgling
Posts: 4
Joined: Fri Dec 21, 2007 2:19 pm
Contact:

Re: General Joomla php include question

Post by durino13 » Mon Feb 04, 2008 9:38 pm

Hi Skipdog ..

Thank you for your answer .. I understand what you want to say with the tmpl=component parameter .. I've tested it and I see, that only the component is returned instead of everything (template, modules .. ). Now, I am thinking, how this could help me with my issue.

Am I correct, if I say following?

1. I send an AJAX request from my module (the requested file will be a 'php' file of my component) ..
2. I will be able to use all methods in the php file, as it will be a standart component (withing Joomla framework)
3. As a response, I'll receive an HTML file from the server, which i can include back into my module ..

Do I understand it correctly?  :-[

Skippdog
Joomla! Apprentice
Joomla! Apprentice
Posts: 7
Joined: Fri Jan 11, 2008 4:49 pm

Re: General Joomla php include question

Post by Skippdog » Mon Feb 04, 2008 9:43 pm

You can't call the php file of the component directly. Your AJAX call will be to index.php?option=com_[yourcomponent]&tmpl=component

This calls the component properly through the framework, and returns just the data you need to update your module.

durino13
Joomla! Fledgling
Joomla! Fledgling
Posts: 4
Joined: Fri Dec 21, 2007 2:19 pm
Contact:

Re: General Joomla php include question

Post by durino13 » Tue Feb 05, 2008 7:26 am

Now I think I know everything I needed to know !!

Thank you guys for your time !

8)
Last edited by durino13 on Tue Feb 05, 2008 7:27 am, edited 1 time in total.

User avatar
ianmac
Joomla! Enthusiast
Joomla! Enthusiast
Posts: 237
Joined: Sat Sep 24, 2005 11:01 pm
Location: Toronto, Canada

Re: General Joomla php include question

Post by ianmac » Tue Feb 05, 2008 4:21 pm

You might also use format=raw so that you don't get any extra HTML around your component.

Ian
Help test my Component XML Generator Tool!
http://extensions.joomla.org/component/option,com_mtree/task,viewlink/link_id,1997/Itemid,35/
All feedback appreciated!

Skippdog
Joomla! Apprentice
Joomla! Apprentice
Posts: 7
Joined: Fri Jan 11, 2008 4:49 pm

Re: General Joomla php include question

Post by Skippdog » Tue Feb 05, 2008 4:43 pm

ianmac wrote:You might also use format=raw so that you don't get any extra HTML around your component.

Ian
The only problem with that is that you need to develop a raw view for the component and most (or all the ones I've seen at least) of the core or community components don't have a raw view implemented. If he's developing the component specifically as a data provider for his module, his template can ensure it doesn't include anything more than the module needs in terms of HTML.

User avatar
ianmac
Joomla! Enthusiast
Joomla! Enthusiast
Posts: 237
Joined: Sat Sep 24, 2005 11:01 pm
Location: Toronto, Canada

Re: General Joomla php include question

Post by ianmac » Tue Feb 05, 2008 5:03 pm

I think you only need to implement a raw view if you are using MVC...  if you are not using MVC, then you should be okay I think.

Ian
Help test my Component XML Generator Tool!
http://extensions.joomla.org/component/option,com_mtree/task,viewlink/link_id,1997/Itemid,35/
All feedback appreciated!


Post Reply