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');
Related
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
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.
Codeigniter is showing blank page after adding comments in any method. eg add //redirect('home'); in controller index method.
Also error reporting can not be enabled from index.php
but after enabling log errors i get this error in error_log file
PHP Parse error: syntax error, unexpected 'endif' (T_ENDIF) in /home/username/public_html/project/application/controllers/Home.php on line 1
here is my controller
<?php defined('BASEPATH') OR exit('No direct script access allowed');
class Home extends CI_Controller {
public function index(){
echo 'Home Page';
//redirect('home');
}
public function test(){
echo 'Test';
}
}
After spending hours and hours i figure out that there was some error on my FTP Client(FileZilla).
On uploading a file via FileZilla it convert all the code into one line therefor if there is any comments then shows error.
Change first line to :
<?php
if (!defined('BASEPATH'))
exit('No direct script access allowed');
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');
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');
}
}