I am trying to run a project but I am getting the below error.
Fatal error: Class 'CI_Controller' not found in E:\wampserver\www\NeoBook\application\controllers\usercp.php on line 2
I checked all the solutions in SO but none worked for me. I am a newbie to CodeIgniter, can anybody help me out in fixing this issue?
Please let me know if you need anymore information about this question.
Also while using
if ( ! defined('BASEPATH')) exit('No direct script access allowed');
//Page is responding as `No direct script access allowed`
class Usercp extends CI_Controller {
public function __construct()
{
parent::__construct();
include_once('member/library/Am/Lite.php');
$this->is_logged_in();
$this->load->model('model_facebook');
$this->load->library('pagination');
$this->load->library('Layouts');
$this->load->model('model_user');
}
}
This is the code. Wherever class CI_Controller been used is not working.
You are using PHP tag inside a PHP tag use this (Removed '
if ( ! defined('BASEPATH')) exit('No direct script access allowed');
//Page is responding as `No direct script access allowed`
class Usercp extends CI_Controller {
public function __construct()
{
parent::__construct();
include_once('member/library/Am/Lite.php');
$this->is_logged_in();
/// More of your code.
$this->load->library('Layouts');
$this->load->model('model_user');
}
}
Related
I have a problem with namespaces. Follow the code:
<?php
defined('BASEPATH') OR exit('No direct script access allowed');
class NavBar extends fwportal\controllers\template\NavBar {
function __construct()
{
var_dump('navBarPortal');
parent::__construct();
}
}
And the main class:
<?php
namespace fwportal\controllers\template;
use fwportal\controllers\NavbarPermissoes;
if (!defined('BASEPATH')) {
exit('No direct script access allowed');
}
Abstract class NavBar extends \CI_Controller
{}
This return the error below:
Fatal error: Class 'fwportal\controllers\template\NavBar' not found in /var/www/portalsibe/sistema/controllers/template/NavBar.php on line 6
Anyone can help me with this?
I don't know why this error occur, because I used in other files with the same mode and works ok.
If you are using Codeigniter 3 then most probably you can not extend "\CI_Controller" while you are defining namespace on a class.
May be this is the reason of getting error.
I was using codeigniter 2.2.1. And now codeigniter 3 released. I just tried it and ended up with error.
When I try to load method as in codeigniter2.x, it shows
Unable to locate the model you have specified: Demo
where Demo is my method file.
Controller - welcome.php
<?php
defined('BASEPATH') OR exit('No direct script access allowed');
class Welcome extends CI_Controller {
public function __construct() {
parent::__construct();
$this->load->model('demo');
}
public function index() {
$data = $this -> demo ->check();
print_r($data);
}
}
Model - demo.php
<?php
if (!defined('BASEPATH'))
exit('No direct script access allowed');
class Demo extends CI_Model {
public function __construct() {
$this->load->database();
}
}
I can't figure-out what is wrong with this code. Please help. Thank you in advance..
Edit:- This is works well in my wamp machine. But I am checking it now in another local machine where my institute host the websites. There it is not working
It was a small issue. I changed model name from demo.php to Demo.php. And it works...
I'm building a Codeigniter application with ION Auth, which is going relatively OK. I've set up the ION Auth framework following this guide http://www.rappasoft.com/tutorials/5-building-a-simple-codeigniter-application-using-ion-auth.html#.U0Q5ufldUrU and when I log in using the default username and password I'm redirect to my homepage. So far, so good.
Problem then is that when I access one of my protected pages (i.e. a controller which extends MY_Controller), I'm redirected to the login page again.
I'm quite new to this, so just looking for some pointers of where to look. It seems I'm being logged in, but I don't really know how to check for sure.
I've tried this line of code in my view, but I get a couple of errors: user_info is undefined & trying to get property of a non object.
<?php echo $user_info->username;?>
MY_Controller in application/core:
if ( ! defined('BASEPATH')) exit('No direct script access allowed');
class MY_Controller extends CI_Controller {
public function __construct() {
parent::__construct();
if (!$this->ion_auth->logged_in()) {
redirect('auth/login');
} else {
//Store user in $data
$data->user_info = $this->ion_auth->user()->row();
//Load $the_user in all views
$this->load->vars($data);
}
}
}
My 'members only' area controller class declaration:
<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');
class Manage extends MY_Controller {
function __construct()
{
parent::__construct();
$this->load->database();
$this->load->library('grocery_CRUD');
}
//other functions omitted
Add this to your MY_Controller and see what is returned
var_dump($this->ion_auth->logged_in());exit;
I am a new user of CodeIgniter. First I install CodeIgniter, then wrote the following code and try to run it with the help of my browser. I save the program in htdocs/application/controllers/hello.php but it shows the error:
Warning: define() expects at least 2 parameters, 1 given in D:\xampp\htdocs\ci_intro\hello.php on line 2
No direct script access is allowed.
What is the problem?
<?php
if(!define('BASEPATH','')) exit('no direct script access allowed');
class Hello extends CI_Controller{
public function index()
{
echo "this is my index function";
}
public function one()
{
$this->load->view('one');
}
}
?>
It should be defined not define.
<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');
I have some codeigniter application. It works well on my local server. After I uploaded it to the hosting server it won't work and resulting an error:
Fatal error: Class 'System_Controller' not found in /home/k2113138/public_html/test/application/controllers/login.php on line 3
Here is my System Controller that extending CI_Controller:
<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');
//location: application/core/
class System_Controller extends CI_Controller {
public function __construct(){
parent::__construct();
//some code
}
}
my controller:
<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');
//location: application/controllers/
class Login extends System_Controller {
public function __construct()
{
parent::__construct();
}
}
i have set my config as my desired configuration like this:
<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');
$config['base_url'] = 'http://xx.com/subfolder/';
$config['subclass_prefix'] = 'System_';
?>
I have read many article that discuss this matter but still cannot found the solution. Really confuse about the problem, because everything works well in local server. I have configured the config file as what it's needed like the database and the routes configuration. Is there any other things that i need to re-configure?
EDIT: My Codeigniter version is 2.1.3
Ok, you changed the filename to lowercase, now, try change the classname too:
class system_controller extends CI_Controller
If don't run, play with the classname and the filename, this is a problem of your server, very common in shared servers.
Sometimes, the PHP version and its configuration, play a important rol in this cases.