I’m trying to create MODx documents from my own PHP code, but I’m not very successful.
The pages are created, but viewing doesn’t work (500 error) - and the context doesn’t seem to really be set (at least retrieving modContext is not successful).
At first I though that it probably was an authorisation problem, but after loging in with a manager-account at the front end the results are the same.
I’m obviously doing something wrong, but what?
Thanks for the corrections; now I can indeed get the resource object - and you’re completely right: get(’context_key’) would have been better.
The prepare() was copied from the create resource processor in the MODx core (the example I worked from). Good to here that it’s not useful; I will remove it from my code.
About the use of echo statements:
this was just a simple test-case - and the real code is part of a large class, that returns the results to the main-program (no echo-statements in that part of the code).
But I must admit that for my main PHP code I still need to make the switch to a better MODx/Snippet/placeholder -based way of working (yes currently it still contains lots of echo-statements - and I also do not know yet what would be the right solution for debugging and error-reporting - so much to learn...).
You also asked whether it is a snippet; Currently my code is just included in a snippet - and is stored as a seperate PHP file.
But for the main problem:
the code now reports that everything goes well and the page does indeed show up in the menu (as it did earlier) and it is shown in the manager in the ’web’ context (also as it did earlier) - but when I try to open the page I get "500 Error" "A fatal application error has been encountered".
Do you have any idea about what could cause this?
See attachment for the now somewhat shorter version of the code.
-
MODX Staff
- 10,725 Posts
Anything in your error log? See Reports --> Error Log
Quote from: Black at Feb 18, 2010, 03:52 PM
(by the way: what would be a valid content type?)
$resource->set('content_type',1)
(but it’s the default anyway).
Quote from: OpenGeek at Feb 19, 2010, 08:54 AM
Quote from: Black at Feb 19, 2010, 02:24 AM
Thanks Bob!
A very short name, but that has the advantage of very little chance of typing errors

That is not the name of a content type, it is the primary key representing the row in the content_type table (represented by the modContentType class).
It might be worth defining some constants for that.