Codeigniter error : define() expects at least 2 parameters - php

I got a strange error in Codeigniter error : define() expects at least 2 parameters in Line 1.
What is wrong with my code below
<?php if ( ! define('BASEPATH')) exit('No direct script access allowed');
class Login extends CI_controller {
function __construct(){
parent::__construct();
}
public function index(){
$this->load->view('login_view');
}
}

I think your looking for the function: defined()
With define() your defining a constant!
With defined() your checking if a constant is defined!
So try this:
!defined('BASEPATH')

Try this may be it works:
defined('BASEPATH') OR exit('No direct script access allowed');

Related

codeigniter cli is not working showing errors with ./system/core/Log.php on line 131

I am trying to use codeigniter function via cli but it is showing me error
<?php
defined('BASEPATH') OR exit('No direct script access allowed');
class Msg_controller extends CI_Controller {
public function __construct()
{
parent::__construct();
}
public function send_in_background($key_with_info){
echo "working";
log_message("error","Key ".$key_with_info);
}
}
CALLING IT LIKE -:
php index.php cli/msg_controller/send_in_background '12547'
ERROR
PHP Warning: mkdir(): Invalid path in /var/www/html/pro/system/core/Log.php on line 131
If i am calling same function from browser it is working fine.
http://localhost/pro/cli/msg_controller/send_in_background/12547
The correct way to run via CLI is
php path/to/index.php controller method params
In your case:
php index.php msg_controller send_in_background 12547
Give that a try

Namespace not found on extending class

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.

How can I change the welcome.php in Codeigniter to something like index.php?

I'm currently learning Codeigniter. As you know, there is a default file called welcome.php in the controller when you first install the package.
I tried to modify that page to index.php, and here is the code:
<?php
defined('BASEPATH') OR exit('No direct script access allowed');
class Index extends CI_Controller {
public function index()
{
$this->load->view('welcome_message');
}
}
I also changed the route.php in the config file:
<?php
defined('BASEPATH') OR exit('No direct script access allowed');
$route['default_controller'] = 'Index';
$route['404_override'] = '';
$route['translate_uri_dashes'] = FALSE;
Then I access the page by entering this path: http://localhost/CI/index.php, but it says there are two errors:
Message: Undefined property: Index::$load. Filename: controllers/Index.php
Message: Call to a member function view() on null. Filename:controllers/Index.php
Did I forget to change something else in order to make it work?
I downloaded CI3.0.2 and tried your code in my computer. I encountered the same problem, and with a few time debug I found what caused this problem.
Your class is Index and your function is index two, in php class when you don't define constructor __construct it will try to find if there's a method that have same name with class nameIndex, so in this situation index function is the constructor of class Index. if this confuse you see this document : constructor php official document
Solution:
class Index extends CI_Controller {
public function __construct()
{
parent::__construct();
}
public function index()
{
$this->load->view('welcome_message');
}
}

CodeIgniter error solving

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');

Fatal error: Class 'CI_Controller' not found

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');
}
}

Categories