I'm new to PHP and am trying to use the SNMP class in a controller. I can use it just fine in the view index.phtml, but when I move it to the controller I'm getting the following error:
Fatal error: Class 'Project\Controller\SNMP' not found in /Project/module/Project/src/Project/Controller/ProjectController.php on line 113
It seems like it's looking for the class within the controller, but I'm not sure why. Any ideas?
All I had to do was add use SNMP to the top of the controller. Turns out it worked in the view because the view is not namespaced, while the controller is.
Related
PHP Application running as docker container throws below error under increased load. Unable to figure out the root cause. Any advice would help?
PHP Fatal error: Uncaught Error: Class 'Page' not found in /var/www/html/vendor/silverstripe/errorpage/src/ErrorPage.php
This is the code of ErrorPage.php:
<?php
namespace SilverStripe\ErrorPage;
use Page;
use SilverStripe\Assets\File;
use SilverStripe\Assets\Storage\GeneratedAssetHandler;
use SilverStripe\CMS\Controllers\ModelAsController;
use SilverStripe\CMS\Model\SiteTree;
use SilverStripe\Control\Controller;
use SilverStripe\Control\Director;
use SilverStripe\Control\HTTPRequest;
use SilverStripe\Control\HTTPResponse;
use SilverStripe\Control\HTTPResponse_Exception;
use SilverStripe\Core\Injector\Injector;
use SilverStripe\Dev\Debug;
class ErrorPage extends Page
{
.....
}
The Page class is imported with use Page;.
Is there a file named Page.php in the same folder as SilverStripe/ErrorPage.php?
If not then that's the problem and use Page; is not correct and should be changed to the correct path or the file should be created with correct code.
I am using Lithium Framework. I am trying to call class into a controller, that class is placed inside libraries folder.... But it is showing this error
Fatal error: Class 'app\libraries\Test' not found in /home/ali.mehdi/AvonTPH/app/controllers/SessionsagentController.php on line 34
In libraries folder I created Test.php having following code.
<?php
namespace app\libraries;
class Test{
public static function getTest(){
return "Hi";
}
}
Also Inside my controller.. I used following using statements:
use app\libraries\Test;
But Why Test Class not found... Am I missing something? Any Help would be appreciated.
As #Matei Mihai has commented, in your app\config\bootstrap\libraries.php add the line Libraries::add('.'), though I'd advise against this (see below).
Be aware that the best practice is to put your classes into a package and not drop them in the libraries folder.
I am trying to upload files following Zend's tutorial, but keep getting this error:
[10-Apr-2015 05:14:41 Europe/Berlin] PHP Fatal error: Class 'Album\Controller\UploadForm' not found in /Applications/MAMP/htdocs/zf2-tutorial/module/Album/src/Album/Controller/AlbumController.php on line 120
Look like you forgot to use Your UploadForm class on top of controller class. So in that case when you call directly call Form class from controller it searched into current namespace which is Album\Controller so error coming.
Change it to (Assuming your form class at Album/Form/).
namespace Album\Controller;
use Album\Form\UploadForm;
I am using a Facedtector class for my work. I added the class in my Codeigniter libraries folder and just called from my controller class. In my controller I also loaded the class but run time it is showing following error:
An Error Was Encountered
Non-existent class: FaceDetector
Please anyone can help me about this.
Thanks
Add your class file inside you library folder of your main application folder.
And then you can use the auto load function of codeigniter
application/config/autoload.php
at the above location and then you can access the class directly or other way of using this use
$this->load->library('Your_Class_Name', 'Path\to\your\class');
This way you can access your class in codeigniter
You can follow below link for autoload of a class library.
https://ellislab.com/codeigniter/user-guide/general/autoloader.html
I'm working with a Zend Framework project and using the ZF tool from the command line. After setting up some initial structure, I extended the Zend_Controller_Action class with something like MySite_Controller_Action and made the existing controllers point to that. So now I have something like:
class IndexController extends MySite_Controller_Action
{ ... }
and
abstract class MySite_Controller_Action extends Zend_Controller_Action
{ ... }
The problem is that now when I attempt to run a command like
Bash$ zf create action edit Index
I get an error like this:
Creating an action named edit inside controller at /Library/WebServer/Documents/MySite/application/controllers/IndexController.php
PHP Fatal error: Class 'MySite_Controller_Action' not found in /Library/WebServer/Documents/MySite/application/controllers/IndexController.php on line 3
Fatal error: Class 'MySite_Controller_Action' not found in /Library/WebServer/Documents/OurMods/application/controllers/IndexController.php on line 3
Can anyone offer up any ideas? I've done a little searching, but I don't even know where to start on this one.
NOTE: I HAVE loaded a 'MySite' namespace via the application.ini file as follows:
autoloadernamespaces.MySite = "MySite_"