TalkPHP
 
 
Account Login
Latest Articles
» The basic usage of PHPTAL, a XML/XHTML template library for PHP
» Vulnerable methods and the areas they are commonly trusted in.
» Simple way to protect a form from bot
» The Basics On: How Session Stealing Works
» How to keep your forms from double posting data
IRC Channel
IRC Speech Bubble Join the friendly bunch on IRC...
(#TalkPHP on Freenode)

...Also available via a web interface.

See this thread for information on the TalkPHP Free Hugs Initiative™. Subject to availability.
Associates
Associates
CSS Tutorials
Reply
 
LinkBack Thread Tools Search this Thread Display Modes
Old 10-05-2007, 09:35 PM   #1 (permalink)
The Acquainted
Upcoming Programmer 
 
CMellor's Avatar
 
Join Date: Sep 2007
Location: Leeds, UK
Posts: 141
Thanks: 6
CMellor is on a distinguished road
Default Function Calling

Hey,

Here's a folder structure I have:

configs
- functions.php
- ajax_functions.php

In functions.php I have a function called getUser. I want to use that function in ajax_functions.php, but when I call it, I get the "Function does not exist" message. I used include to include the functions.php file into ajax_functions.php but that gave errors saying it couldn't open such folders as libs/Smarty.class.php.

How can I call getUser in the ajax_functions.php when the function is wrote in functions.php I hope I don't have to have the function in both pages, I was hoping to just have it in the one.

Hope you understand... thanks for the help if any.

- Chris
__________________
Not quite a n00b...
CMellor is offline  
Reply With Quote
Old 10-06-2007, 02:12 PM   #2 (permalink)
The Reckoner
Advanced Programmer Top Contributor 
 
Karl's Avatar
 
Join Date: Sep 2007
Posts: 437
Thanks: 22
Karl is on a distinguished road
Default

It all depends on the project structure. Where are you including functions.php and ajax_functions.php from? For example, consider your full setup was:

my_project
> config
> index.php

If we wanted to include both files inside index.php, we could simply use the following statements:

PHP Code:
require_once('./config/functions.php');
require_once(
'./config/ajax_functions.php'); 
That's all there really is to it. You just need to remember how PHP works, we're including the files in the index.php file, therefor, in reality we're actually pulling the data out of those files and essentially "pasting" it into the index.php file.
Karl is offline  
Reply With Quote
Old 10-06-2007, 06:31 PM   #3 (permalink)
The Acquainted
Upcoming Programmer 
 
CMellor's Avatar
 
Join Date: Sep 2007
Location: Leeds, UK
Posts: 141
Thanks: 6
CMellor is on a distinguished road
Default

configs
-- functions.php
-- ajax_functions.php
ucpanel.php

In ucpanel.php I include the functions.php file. I use the request method in PrototypeJS to call AJAX, and it grabs the ajax_functions.php from the form action.
__________________
Not quite a n00b...
CMellor is offline  
Reply With Quote
Old 10-07-2007, 01:30 PM   #4 (permalink)
The Reckoner
Advanced Programmer Top Contributor 
 
Karl's Avatar
 
Join Date: Sep 2007
Posts: 437
Thanks: 22
Karl is on a distinguished road
Default

Ah right, I see. In that situation you will need to include functions.php inside the ajax_functions.php file. Don't specify any path, just the filename, such as:

require_once('functions.php');
Karl is offline  
Reply With Quote
Old 10-07-2007, 04:49 PM   #5 (permalink)
The Acquainted
Upcoming Programmer 
 
CMellor's Avatar
 
Join Date: Sep 2007
Location: Leeds, UK
Posts: 141
Thanks: 6
CMellor is on a distinguished road
Default

The problem I get when doing that is, in functions.php, I have another include:

Code:
include('libs/Smarty.class.php');
$smarty = new Smarty;
I've had it where it doesn't include the class file, and also had it say "Smarty class does not exist" which it clearly does...

Meh, I just gave in and copy/pasted the function into the ajax_functions.php file as well as in the functions.php file.
__________________
Not quite a n00b...
CMellor is offline  
Reply With Quote
Reply



Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


All times are GMT. The time now is 09:18 AM.

 
     

Powered by vBulletin® Version 3.6.8
Copyright ©2000 - 2013, Jelsoft Enterprises Ltd.
Search Engine Optimization by vBSEO 3.1.0
Inactive Reminders By Icora Web Design