WebView - Why does it have this behavior

Hello…

I’m trying to view a local PHP file in my WebView, but when doing so it only returns the actual source of my PHP file
if I load the PHP file from my webserver I have no problem in getting the correct output…

This script is something I found on this forum.


property URL_Home_Page : "file:///Users/mkh/Desktop/test.php"

on awake from nib theObject
	--Display_URL(URL_Home_Page) -- This will NOT work
	--Display_URL("http://domain.com/test.php") -- This works
end awake from nib

to Display_URL(theURL)
	try
		set URLWithString to call method "URLWithString:" of class "NSURL" with parameter theURL
		set requestWithURL to call method "requestWithURL:" of class "NSURLRequest" with parameter URLWithString
		set mainframe to call method "mainFrame" of object (view "mywebview" of window 1)
		call method "loadRequest:" of mainframe with parameter requestWithURL
	on error the_error
		log the_error
	end try
end Display_URL

If I try to load the local file as an HTML file it works, but I sure would like to use PHP, reason for this is CSS & SQLite3…

Any help would be great…

mkh

Hi mkh,

This will be because you are not involving the web-server which is needed to parse the PHP file.

Have you tried putting it in your user’s sites folder and trying ‘http://127.0.0.1/~mkh/test.php’ to access it? (you’d need to have ‘web sharing’ enabled). I’m not 100% sure this would work, but it’s worth a try.

Also, (just to check) do you have Apache set up to run with PHP on you machine?

John M
www.nhoj.co.uk

Hi John…

Ofc, you are right, the server has to return the actual output parsed from the PHP source, my bad…

And no, at this point I don’t have Apache setup to use .php extension, I was kinda trying to avoid this, if the application has
to run on more than my machine every user has to put the files in the ~/Sites/ which I think is overkill, using it from within the
app itself would keep it more dynamic, but I’m not sure my idea is the best solution either… But maby it is the only way to go.

mkh

Hi mkh,

Without knowing more about what you are trying to achieve, it’s had to say what the best options would be.

John M

John, so true, well, the point of all this is to see if I can use a tabview and a few webview’s to create an application
driven by PHP, as I described in my first post, the main reason for this is the use of CSS styling, I’m pretty sure I
can comeup with something nice using some fancy javascrpt libs, such as http://developer.yahoo.com/yui/examples/,
PHP comes standard with all Mac’s so I see it as another way to do things :slight_smile: with the use of sqlite3 there it’s no task in handling data…

Thinking a bit, I might just setup a default httpd.conf and php.ini to include in my app and then “install” the new
files first time app is opend… Then i can move the PHP files to users ~/Sites/, but :confused: as I said I would like to avoid this…

I just tested it on my machine and that worked fine, but I don’t know how to set the websharing from within applescript

moving files and folder is not a problem, but to enable to websharing I don’t have a clue :slight_smile:

Besides, this could be used in alot of ways, atm I’m working freelance for a small sales company, and all the people are Mac users.
So this could be used to create and application to hookup with the MySQL databse inhouse and show most recent data, there are a TON
of opportunitys in something like this, but that is just my way of thinking :slight_smile:
mkh