getting error when adding a class in codeigniter - php

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

Related

hidden magic in Laravel blade components

I had anonymous component resources\views\components\homepage\feedback.blade.php to render feedback on homepage. From the beginning it was just html. Then I decided to connect Class file. I already had another View Class component and I just copied it manually instead of using artisan command.
App\View\Components\Feedback.php
namespace App\View\Components;
use Illuminate\View\Component;
use App\Models\Feedback;
class Feedback extends Component
{
public $feedbacks;
public function __construct()
{
$this->feedbacks = Feedback::wherePublished(true)->take(5);
}
public function render()
{
return view('components.homepage.feedback');
}
}
And then {{ dd($feedbacks) }} in view file gives me error that this variable is not defined.
Undefined variable: feedbacks (View: C:\laragon\www\lara7\resources\views\components\homepage\feedback.blade.php)
If I try to create Test component with artisan command and put this code inside it works, but then I cannot rename it back to Feedback class. It gives me error
Symfony\Component\ErrorHandler\Error\FatalError
Cannot declare class App\View\Components\Feedback because the name is already in use
But old class already deleted, so I cannot understand what is wrong.
It seems like there is some hidden link between View Class and Blade components, which needs to be erased. But where is this link located?
When switching component type from anonymous to class and back, you have to clear compiled view files:
php artisan view:clear
That's because Laravel incorporate specific component type invocation into the compiled view code.
I found problem.
I got $feedbacks is undefined, because my anonymous component without variables initially was located in resources\views\components\homepage\feedback.blade.php and when I decide to create View Class for this component there was no link established.
Laravel creates automatic link between feedback.blade.php and app\View\FeedbackComponent.php only when blade file located directly in resources\views\components folder. And my component was in subfolder.
So laravel tried to render resources\views\components\homepage\feedback.blade.php with $feedback variable inside and it cannot find where $feedback is defined.
So I just manually register FeedbacksComponent class like that in appservice provider boot method
Blade::component('homepage-feedbacks', FeedbacksComponent::class);
and then use <x-homepage-feedbacks/> to render it
I would say documentation is not very clear. It says that outside of components folder automatic discovery is not working.
But it doesn't say that inside components subfolder automatic discovery is not working.
In Laravel 8 you can use and no need to declare the component
<x-homepage.feedback />
I think you're right I have been having the same issue and and I've been really struggling with it. Finally I found a workaround which is if you change the file name it works so I think it's a problem with the laravel framework and I think they need to address this issue

laravel FatalThrowableError "calss not found"

I am new with laravel and I add "steffenbrand/dmn-decision-tables" package then I created the function to use it
like this step steffenbrandDmn
but when I use the function don't work and throw an exception
Class 'App\Http\Controllers\HitPolicy' not found
canyoneone help me???
You have created a policy and you are using it within your controller, but haven't imported.
So in your controller class, above the class declaration put:
use App\Policies\HitPolicy;
or the path to the HitPolicy class wherever is created.

Using PHP Class in view works, but not in controller

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.

Class not found error in Lithium Framework (li3)

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.

Codeigniter Doctrine is not working with underscore( _ ) class name

Hello guys i created Entity folder inside application/model/. In Entity folder i created file Mj_user.php and give class name as same Mj_user.
but when i try to access that class using
$User= new Entity\Mj_user;
it's giving me error
Fatal error: Class 'Entity\Mj_user' not found in C:\xampp\htdocs\project\application\controllers\user.php on line 15
what should i do Please help me..but when i remove Mj_ then put only file name as User.php. Its working properly..Please help me
When creating a new class you have to be careful, the name of the class must be:
class Mj_user extends CI_Model {
function __contruct()
{
partent::construct();
}
}
The file must be mj_user.php and for using this model you must load it before start using it
it can be preloaded for all in the configuration or you can load it whenever you need it like this
$this->load->view('mj_user');
And in the error seems that is looking for a file called user.php and should be mj_user.php

Categories