I am trying to use the Concrete Core Classes to create a user outside of the main folder structure.
For example I had a main folder called
Project One
-- concrete
-- application
-- packages
... etc etc
and another folder called user-upload. In here I have an import-users.php script.
I have a single page which has a form with a file upload element. This takes a CSV and tries to send it to the import-users.php script ready to loop through and create a new user for each row in the CSV. But I keep getting the following error when trying to use the classes:
Fatal error: Class 'Core' not found in path/user_upload/import-users.php on line 6 Call Stack: 0.2009 254592 1. {main}() path/user_upload/import-users.php:0
How can I use the class outside of the concrete5 installation?? Examples would be extremely helpful
Edit 1 Script to upload the CSV
$('#user_upload_submit').click(function () {
var fileInput = document.getElementById('usersfile');
var file = fileInput.files[0];
var formData = new FormData();
formData.append('file', file);
$.ajax({
type: "POST",
url: new_path+"user_upload/import-users.php",
data: formData,
contentType: false,
processData: false,
success: function (msg) {
$('#user_result').html(msg);
},
error: function (jqXHR, exception) {
var msg = '';
if (jqXHR.status === 0) {
msg = 'Not connect.\n Verify Network.';
} else if (jqXHR.status == 404) {
msg = 'Requested page not found. [404]';
} else if (jqXHR.status == 500) {
msg = 'Internal Server Error [500].';
} else if (exception === 'parsererror') {
msg = 'Requested JSON parse failed.';
} else if (exception === 'timeout') {
msg = 'Time out error.';
} else if (exception === 'abort') {
msg = 'Ajax request aborted.';
} else {
msg = 'Uncaught Error.\n' + jqXHR.responseText;
}
alert(msg);
}
});
});
First of all, you should add a validation token to every request you send to the server, and the server-side script should validate the received token.
Then, you should handle the submit in the single page controller.
Let's assume your single page is available at the
/test
path. The View of your single page (where you put the HTML and JavaScript) must be saved as/application/single_pages/test.php
. The controller of the single page (where you put the PHP code that handles the requests) must be saved as/application/controllers/single_page/test.php
.In the
/application/single_pages/test.php
you have to add a validation token to the data to be sent, and you have to call the URL of a controller method (let's call ithandleSubmit
).This can be done with this code:
Then, your controller file (
/application/controllers/single_page/test.php
) can be something like this:The namespace of the controller and its class name must reflect the URL of the single page.
Examples:
Your single page is available as
/test
/application/single_pages/test.php
/application/controllers/single_page/test.php
Application\Controller\SinglePage
Test
Your single page is available as
/foo/bar/baz
/application/single_pages/foo/bar/baz.php
/application/controllers/single_page/foo/bar/baz.php
Application\Controller\SinglePage\Foo\Bar
Baz