Hello,
I am trying to access the (DataObject) class Offerer.php in my controller TestController.php .
The controller works fine.
<?php
use SilverStripe\Control\Controller;
use SilverStripe\Control\HTTPRequest;
use SilverStripe\ORM\DataObject;
class TestController extends PageController {
private static $allowed_actions = [
'light',
// ...
];
public function light() {
$offerer = new Offerer();
// ...
}
}
The location for both TestController.php and Offerer.php are located in
I actually posted the question three times and specifically stated the various ways I tried to instantiate the DataObject class Offerer:
public function light() {
$offerer = new Offerer();
/* $offerer = Offerer::create(); */
}
The exact error message: âError message: [Alert] Class âOffererâ not found GET /silver/test/light Line 22 in C:\xampp\htdocs\silver\mysite\code\TestController.phpâ
No worries, I really appreciate your help. (I apologize but I am a newbie)
I think you nailed it because even though I have run http://localhost/silver/dev/build and http://localhost/silver/dev/build?flush numerous times, I do not see the table structure being created. Am I missing something ?
Can you just confirm the location of the file containing the Offerer() class. Is it in /mysite/code?
One thing I noticed is that the class is using a short opening tag <? instead of the full <?php tag. Might be worth changing that in case your system doesnât have short tags enabled.
Hello,
I seem to be getting a problem somewhat related.
When I try to instantiate other DataObject classes (all located in /mysite/code) in the same function light() { }, I always keep getting the same fatal error (see screenshot below) which always refers to the same DataObject class Apartment.php (dev/build regularly used). Thanks.
I am bit lost when it comes to figuring out the error message because regardless which one of my four DataObject PHP Objects I instantiate in the light() {} method , the error message above in red always refers to Apartment.php (which is one of the DataObject PHP Objects). Here is the file: https://paste.ofcode.org/mw6x6Mjmrgv4xQTJ6a75rb
What notation worked for the other dataobject? Was it with the leading slash ie. \Offerer::create();
If so, then youâll probably need that here as well. Youâre creating all your code in the global namespace by the look of things, so you may need the leading backslashes to be able to reference the class.