When I upload my website on the server I m getting this error
unable to locate the model you have specified
but in localhost, it is working fine
Please state the error which you are facing with more details
Although check the following points
check whether you have loaded the model in controller. It is most preferable that you load model in your constructor
$this->load->model('Example_model');
if you have model in a specific folder then the path will be as following
$this->load->model('folder_name/Example_model');
Check the name on model class. The first letter should be capital
class Example_model extends CI_Model{
}
Related
PhpStorm does not found findOrFail() method. When I try to call it, there isn't auto-complete and the result is always fail. The user found is always on the message.
I try to use Laravel Ide helper and query()->findorfail but I didn't resolve.
The result:
in phpstorm try the Laravel plugin to generate the IDE classes.
please check your User model. It must extend Model class like this.
use Illuminate\Database\Eloquent\Model;
class Lead extends Model {
I guess your User model is missing this "extends Model".
As I know, PHPStorm never detects the findOrFail method even we already installed the Laravel plugin.
But you use it wrong because this method takes an id and returns a single model. If the method can't find any matching data, it will return an error.
You can change the method into:
User::findOrFail($user->id);
I always have this message:
Illuminate\Contracts\Container\BindingResolutionException
Target class [MessagesController] does not exist.
On some route and URL requests,
MessagesController however is not contained on my route web files, and in any of my controllers.
Can someone explain to me why the Controller class gives a warning?
Target class [MessagesController] does not exist.
Follow-up question, is there a way I can remove an unused controller by an artisan command?
The solution I made for this is to import MessagesController class, I'm so dumb I didn't figured it out.
On route:
use App\Https\Controller\MessagesController;
I created Custom ReadRequest Class. Than I created folder with "Order" name in Requests folder, and put there my ReadRequest.php file:
After this manipulation Laravel doesn't see this file in my Controller:
How can I fix that?
You haven't written how you know that Laravel doesn't see this file but looking at your screen it seems your IDE doesn't see it it either. So make sure in your ReadRequest.php file you have
<?php
namespace App\Http\Requests\Order;
class ReadRequest
{
// ...
}
It's very possible that you have invalid classname in this file or invalid namespace, so your IDE shows you the error and also composer cannot load the file.
I'm working on a website that have virtual hosts, like xyz.com, asd.com and so on.
I use Hostname route like ":controller.com", so it routes me to the specific controller.
I created a defaultController to a default behavior and I extended xyzController and asdController from that, so I only modify that I really want.
The problem is that, how can I create my DefaultController to be really default :) I mean, if I haven't created a controller for the specific route (forexample: xyzController for xyz.com), then I don't want to get a Fatal Error like
"Fatal error: Class 'aaaa\Controller\asdController' not found in /var/www/samba/aaaa/www/src/site/vendor/ZF2/library/Zend/ServiceManager/AbstractPluginManager.php on line 177"
Would be better if it route me to defaultController immediately.
I was thinking about the view_manager's templates like 'not_found_template'. That would be great if not_found_controller would exist :)
Is it possible to do somehow?
I recently learned that you can provide a class name to the Query->result() and it will use that to instantiate the results, rather then using plain stdClass. more here
My first attempt was to the in application/models/classes and name them the same as the model, but without the _model suffix. So I would have a Posts_model that returns instances of Post from the database. But the problem is that I also have a Controller named Post and obviously PHP throws a Fatal Error.
So the question is: Is there is a convention as to where to put this classes and how to name them?
As far as Codeigniter goes, there are no convetions, and the built-in loader is kinda ill-suited for only including files and not instantiate them. I would recommend to integrate some psr-0 compatibile autoloader.
As of most mvc web frameworks, they usually uses the plural form for the controllers and singular for models. For example: Users is a controller and User is the modell.