Cannot use a custom PHP plugin in Laravel - php

I have installed a plug-in called tet. I copied tet.so in the plug in folder and included it in php.ini
I have checked phpinfo and says that the plugin is enabled and running.
I have created a php page to test it.
<?php
new tet();
?>
And works perfectly.
However when I try this on my laravel it gives me this error:
FatalThrowableError in mycontroller.php line 16: Class
'App\Http\Controllers\tet' not found
tet is not a controller. Tet is a class created by the php plugin. How do I include this in laravel?

You should try
new \tet();
because you are using it inside a namespace. Inside a namespace any reference to a class is considered as relative to the namespace you are in. With the "\" you can "escape" the namespace and so you can access classes outside.

Related

Fatal error: Class __ not found

Last spring I was working on a project using PHP, and it was working well. I had no time to work on it later, but now after I changed hosting I want to work on it again. I send files in working directory, but the error appears. It says that can't find Class TemplateLogin in class Login
Login.php:
class Login extends TemplateLogin
TemplateLogin.php:
abstract class TemplateLogin extends Core
Login.php and TemplateLogin.php are in the same folder
Your file Login.php needs to require or include the file TemplateLogin.php:
require_once 'TemplateLogin.php';
Or php will not know how the class TemplateLogin is defined.
An alternative to manually including/requiring every file is to define an autoloading function.

Class 'App\Http\Controllers\Project' not found

I am developing web based project management tool using laravel 5. when I execute it occurred following error.
FatalErrorException in ProjectController.php line 37: Class
'App\Http\Controllers\Project' not found
Make sure you import your Project class with proper use statement, otherwise PHP will look for this class in current namespace.
E.g. if your Project class is in App\Models namespace, add the following at the top of your controller file:
use App\Models\Project;

Drupal 8 autoload don't load custom class

I recently decided to develop a new website with drupal 8 (i never used drupal 7 or other version).
I had to create a module and i need a custom class in this module and i create a service to use it. But i've an error, my custom class is not find.
When i had a require of my class in the autoload.php, it's work. So my service is correct but my class is not include in my autoload.
Anyone have a solution for my problem ?
Do you "use" the class? Like that:
use Drupal\your_namespace\yourClass;
Of course your class needs a namespace to make this work.
you need follow PSR4 rule, if your class is defined in module, you should put your class file into the correct folder structure , for example if your class namespace defined as "Drupal\your_module_name\yourClass" , the file folder structure should be: modules\your module name\src\ (your Class file)

Yii2 namespace autoloader doesn't find copied files

I am running the Yii2 framework locally, and I want to reuse an model I created in a earlier project.
So I copy the file TestForm.php to the models directory, change the namespaces from namespace backend\models to namespace app\models and try to create an object from it with:
$model = new \app\models\TestForm;
Which gives me
Unable to find 'app\models\TestForm' in file: /var/www/html/operators/basic/models/TestForm.php. Namespace missing?
Which is weird because the namespace is correct.
However, if I create the file TestForm.php myself and copy the contents of the older file over, everything works fine.
What's going on?
(I use ubuntu 15.04)
I think in your /models/TestForm.php you don't have specified the correct namespace eg :
namespace basic\models;

Phalcon php - Undefined namespace Phalcon

I am working on a project in php Phalcon.
I am working with the Xampp server. The installation process that I followed is on this link:
http://docs.phalconphp.com/en/latest/reference/install.html
I am following the documentation on the website as guide and tutorial.
My problem is, every time I type "class MyClass extends \Phalcon\Mvc\Model"
it says undefined namespace "Mvc" and in other files it also gives error that Phalcon is an undefined namespace.
The installation seems okay.
Please help me out.
I think this is not really a problem with the installation of Phalcon.
I have recognized the same behaviour of my IDE because Phalcon is only loaded as an extension of PHP and not available as real PHP files which can be indexed by your IDE.
The easiest way to check if install was ok is to create a info.php in your project root.
<?php
phpinfo();
If you open this file in browser it should show a block with information about phalcon.
There is a script that creates stub files for you that can be integrated in you project.
https://github.com/phalcon/phalcon-devtools/blob/master/ide/gen-stubs.php
If these files are indexed by your IDE, the message of Undefined namespace should be gone.
If your code works. And IDE shows Mvc undefined namespace then you have to install Phalcon developer tool plugin for your IDE. the plugin is available for PHPStorm. Phalcon is a C extention and for this if you not install developer tool plugin then IDE will show undefined namespace.
Phalcon has different ways to use model like register model class, register namespace or register dir. If you create the model by command rather than manually write code you will get the proper base model class to extend. If still problem then there is problem with Phalcon installation.
Use --namespace="" for model:
phalcon create-model profiles --namespace="Application\Models"
For scaffold:
phalcon create-scaffold profiles --ns-models="Application\Models" --ns-controllers="Application\Controllers"
If you do not register the model namespace and register only model directory then edit the model file after creation and remove the namespace definition.
first check if php load phalcon module. for that in terminal type
php -r "echo phpinfo();" | grep 'phalcon'
if everything went write you should see line
phalcon => enabled
in windows grep wont work and you should look for that line yourself.

Categories