I'm facing one weird problem with my Codeigniter project.
I have two model files in the following paths:
models/public/Dish_model.php
models/admin/Dish_model.php
For front-end and back-end models respectively.
In the controller which is in the following path:
controllers/admin/Dish.php
I'm trying to load the admin area model file using:
$this->load->model('admin/dish_model');
But it is loading the public model file.
Even if I comment this line out the public model file still gets loaded.
This all happened suddenly it was working fine before and I haven't changed any of the mentioned files recently.
Any help?
In case anyone else encounter the same issue.
In my case and after carefully following the execution path of the controller I found that the other model was being loaded by a library in the autoload list.
Removing that library from the autoload array fixed the problem.
to call/load a model from its subdirectory or subfolder.
models/public/Dish_model.php
let's say in Dish_model
class Dish_model extends CI_Model{
public function __construct(){
parent::__construct();
}
public function the_method(){
return 'return value';
}
}
models it's a native ci model directory and public it's a subdirectory. so to load the Dish_model do this on controller
$this->load->model('public/Dish_model','DModel');
the DModel it is like an alias.
so to call the model from the controller is
echo $this->DModel->the_method();
and it will return return value
hope its help.
Related
I am trying to add controller view in my existing project that consider model view controller structure in php with laravel.
class CashFlowdataController extends Controller {
public function index() {
return view('CashFlowdata::create');
}
}
When I implement this, it shows me error for,
InvalidArgumentException
No hint path defined for [CashFlowdata].
I have added file in route.php and web.php as added other controller data. Only for this one it shows message like this.
you code is wrong you should to something like this
class CashFlowdataController extends Controller {
public function index() {
return view('CashFlowdata.create');
}
}
here CashFlowdata.create
its means in laravel
folder structure should be
view>CashFlowdata>create.blade.php
laravel view() function is a helper to load view file
ref link https://laravel.com/docs/8.x/helpers#method-view
I had the same issue in nwidart/laravel-modules due to module.json file was miss place.
I move the file to the root of module now working fine.
When I am going to run my file, it shows an error like this,
Unable to locate the model you have specified: users
I have controller, models and view in Modules folder and I think its a HMVC structure.
What is wrong with it?
Load the model before you use it.
$this->load->model('users');
Also make sure that your model starts like:
class Users extends CI_Model{ }
CI version 2.1.4
I am trying to work in HMVC architecture; i am working in laravel 4.2.
I install the HMVC of laravel but got some problem.
Class 'App\Modules\Users\UsersServiceProvider' not found
Above error occurred while putting following code in module.json
{
"enabled": true,
"provider": [
"App\\Modules\\Users\\UsersServiceProvider"
]
}
and UsersService Provider is as follows:
<?php namespace App\Modules\Auth;
class UsersServiceProvider extends \Illuminate\Support\ServiceProvider
{
public function register()
{
\Log::debug("UsersServiceProvider registered");
}
}
While I remove the provider section in module.json it works fine; but have another problem.
View can not be loaded from corresponding views folder and I wrote the route as follows: (here controller works fine)
Route::get('users',array('uses'=>'UserController#getIndex'));
<?php
class UserController extends BaseController{
public function getIndex(){
echo 'Yes this works.';
return View::make('users::users');
}
?>
echo 'yes this works'; // works fine
while i moved to next line of code it always in the search of Views folder if users file is not in main view then it generates error.
Can anybody tell me, whats wrong with my code; guide me to have correct way to do things in HMVC, so that i can getting things done.
Your .php class says its in the "App\Modules\Auth"
While the .json is looking in the namespace: "App\Modules\Users"
So you have to change one to the right namespace.
i installed fresh cakephp. its app controller working fine. but when i write my controller and its view but this result in page not found. My code is given below
class PostsController extends Controller {
public $helpers = array('Html', 'Form');
public function index() {
$this->set('posts', $this->Post->find('all'));
}
}
and create folder named Posts in view folder and over there create index.ctp file as well. but its result in page not found. Please help what may be mistake by me or is there any need to configuration. Thanks
Your controller should be named PostsController.php (ie plural)
Just spotted it, you need to extend AppController in CakePHP 2.x, not Controller: ie:
class PostsController extends AppController {
there might problem apache rewrite module. if you are using WAMP, just put on your rewrite module.
I'm a new user of both Stack Overflow and laravel.
I just started to learn L4 in their official site but now I'm having a small problem in loading the views.
Now my views is not working properly. Any file I call under the views dir results in "file doesn't exist" error.
This is my code ....
Authors controller is:
class AuthorController extends BaseController{
public $restful = true;
public function get_index()
{
return View::make('authors.index');
}
}
On routes.php I added
Route::get('authors',array('uses'=>'authors#index'));
under views/authors/index.php
Any html text
Change
Route::get('authors',array('uses'=>'authors#index'));
to
Route::get('authors',array('uses'=>'AuthorController#get_index'));
If you dont plan on doing complex logic you could skip the controller and just call the view from the router. And also its a good practice to keep the functions as camelCase so in your case getIndex().
Route::get('authors', 'AuthorController#getIndex');