I have a new problem with Codeigniter HMVC when deploy my project to hosting Unix (it works well on localhost)
$this->load->model('User_management/Muser_management');
When I call User_management model file in User_profile controllers it throws an error:
Type: RuntimeException
Message: Unable to locate the model you have specified: Muser_management
The same problem with other controllers when when load model from another modules
My structure
>root
>application
>modules
>User_management
>controllers
User_management.php
>models
Muser_management.php
>User_profile
>controllers
User_profile.php
>models
Muser_profile.php
My Muser_mangement file:
<?php
defined('BASEPATH') or exit('No direct script access allowed');
class Muser_management extends MY_Model{
public function get_listuser()
{
$this->db->select('id,label,email,role');
$user=$this->db->get('user');
return $user->result();
}
}
?>
Please help, thanks
[SOLVE]Anyway, I have fixed it. The solution is:
_the folder name of modules must be in lowercase
_the controller and model files name must be in uppercase for the 1st letter only
_the class in controller and model must be in uppercase for the 1st letter only
Related
I am trying to make a Codeigniter 3 application to authenticate to a CAS server.
I installed the phpcas package with composer but I cant find any details or examples on how to do this. I want the access to this application to be only from authentication users.
I believe that I have to edit a config file but I cant find any to write down the cas server url, etc. Also, in the controller of the page, I have to call somehow the library but I need some example for that.
So the main question is how can i get to use phpcas inside my controller methods amd how to configure it?
I created a controller and have inside:
?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');
class AuthController extends CI_Controller {
public function actionLogin()
{
$this->module->casService->forceAuthentication();
$username = $this->module->casService->getUsername();
$this->module->casService->getAttribute('mail')
$this->module->casService->getAttribute('title')=='TEACHER';
//$auth->assign($casRole, $user->id);
}
public function actionLogout()
{
$this->module->casService->logout(Url::home(true));
// In case the logout fails (not authenticated)
return $this->redirect(Url::home(true));
}
}
I place to the controller file the line:
require_once(APPPATH . '/../vendor/autoload.php');
and I init with:
$phpCAS = new phpCAS;
phpCAS::client(CAS_VERSION_2_0, 'sso-test.sch.gr', 443, '', false);
I need help with using sub directory controllers in CodeIgniter 4.
I just can't make it work for some reason.
This is the URL for example: www.example.com/admin/dashboard
In the controllers folder, I created a folder named Admin, and a file named Dashboard.php.
I used this code in Dashboard.php:
namespace App\Controllers;
class Dashboard extends BaseController
{
public function index()
{
}
}
I tried changing the class name to AdminDashboard, Admin_Dashboard, pretty much every logical name but every time I get a 404 error, saying:
Controller or its method is not found:
App\Controllers\Admin\Dashboard::index
I know the file itself gets loaded successfully, but I think I don't declare the classname correctly and it keeps throwing me those 404 errors.
The documentation of CI4 isn't providing any information about what the classname should be called unfortunately...
UPDATE #1
I managed to make it work by changing few things:
namespace App\Controllers\Admin;
use CodeIgniter\Controller;
class Dashboard extends Controller
{
public function index()
{
}
}
But now it won't extend the BaseController which has some core functions that I built for my app.
Any ideas to how to make it extend BaseController?
I must admit that I don't have much knowledge about namespacing yet, so that might be the reason for my mistakes.
As I imagined, the problem was that I didn't learn about namespacing.
I needed to point the use line at the BaseController location.
namespace App\Controllers\Admin;
use App\Controllers\BaseController;
class Dashboard extends BaseController
{
public function index()
{
}
}
Now www.example.com/admin/dashboard/ goes directly to that index function, as intended.
php spark make:controller /Subfolder/ControllerName
$routes->add('/(.+?)_(.+?)/(.+?)$', 'subdir\\\\$1_$2::$3');
$routes->add('/(.+?)_(.+?)$', 'subdir\\\\$1_$2::index');
I was able to map with this setting.
The route mapping could be as simple as:
$routes->group('admin', static function ($routes) {
$routes->get('dashboard', 'Admin\Dashboard::index');
});
i need to access the admin controller in codeigniter using the url mywebsite.com/admin
but it returns "The requested URL was not found on this server. If you entered the URL manually please check your spelling and try again" error
my code is
routes.php
$route['admin'] = 'admin/adminmain';
adminmain.php (admincontroller)
<?php
defined('BASEPATH') OR exit('No direct script access allowed');
class Adminmain extends CI_Controller {
public function index()
{
$this->load->view('admin/adminhome');
}
}
In Codeigniter 3 or above controllers name should be capitalized.
The controller file name should be Adminmain.php
controller file name should be Adminmain.php and try to define route like: $route['admin'] = 'admin/Adminmain'; and also check r u defining admin folder under controller folder
As standard in Codeigniter
A Controller is simply a class file that is named in a way that can be associated with a URI.
And the Controller Class Name = File name but the first char is Capitalized
For example
The URL
example.com/index.php/blog/
The controller
<?php
class Blog extends CI_Controller {
public function index()
{
echo 'Hello World!';
}
}
?>
My need
In my application we require the URL seems like that
example.com/index.php/Non-ASCII-chars-String/
So How we gain that?
I think that if you want to fix this thing. You need to understand how CI work and especially router in CI.
I think this is the thing that you want: Routing in codeigniter doesn't work with non english characters
Sorry about my English.
not sure what is the problem? My class that is in Application/core folder, and here it is:
if (!defined('BASEPATH'))
exit('No direct script access allowed');
class MY_Image_lib extends CI_Image_lib {
public function __construct() {
parent::__construct();
}
function tesit($msg) {
log_message('error', $msg);
}
}
I get this error :
Fatal error: Call to undefined method CI_Image_lib::testit()
when I call it like this : $this->image_lib->testit('not working');
What I am missing, this is so strange.
Only the following classes are core classes all others should be extended in library folder.
http://ellislab.com/codeigniter/user-guide/general/core_classes.html
Benchmark
Config
Controller
Exceptions
Hooks
Input
Language
Loader
Log
Output
Router
URI
Utf8
Move your class to the application/library folder and it will override the one in the system folder when you call it.