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');
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
Controllers/home.php code is:
<?php
defined('BASEPATH') OR exit('No direct script access allowed');
class Home extends CI_Controller {
public function index()
{
$this->load->view('index');
}
}
?>
Config/routes.php code is:
$route['default_controller'] = 'home';
This code is for view only index page. I create folder in views named pitanja, and several pages in that folder. Problem is when i click on site on that pages, i get error 404 page. Where i miss?
$this->load->view('pitanja/index');// relative to APPPATH.'views' directory
Just store pitanja folder with application|system|user_guid and it will display pages. Solved!
I'm aware of the ways to set up custom error pages for expected errors. However, what I'd like to do is a set up a pretty, catch-all page that viewers will see on any error. So for example instead of "Unable to connect..." or whatnot, they get "We're sorry, an error occurred...".
Is there a view that can be modified or overridden to provide this functionality?
The error views are defined in /application/views/errors/html. There is one for php errors and one for exceptions. If you don't want to edit those you can extend the CI_Exceptions class and override show_php_error or what ever else you would like. If you wanted to try that you should create a file called "MY_Exceptions.php" in the /application/core/ folder and in it put....
<?php
defined('BASEPATH') OR exit('No direct script access allowed');
class MY_Exceptions extends CI_Exceptions {
public function show_php_error($severity, $message, $filepath, $line)
{
echo "Caught random php Error...";
}
}
I have a problem when I call this function I am getting the following error:
"Fatal error: Uncaught exception 'Exception' with message 'load error: failed to find test.less' in C:\xampp\htdocs\project\application\views\lessc.inc.php:1818"
<?php
require('lessc.inc.php');
$less = new lessc;
echo $less->checkedCompile("test.less","hoba.css");
?>
and I have test.less, hoba.css and lessc.inc.php all in the views folder
Try,
<?php
require('lessc.inc.php');
$less = new lessc;
echo $less->checkedCompile(site_url()."application/views/test.less",site_url()."application/views/hoba.css");
?>
I'm not familiar with the lessphp class, but try putting the "less.inc.php" (and any other files associated with it) in application/third_party. Next create a file "less.php" in application/libraries. In that file, paste the following:
<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');
require_once APPPATH."/third_party/less.inc.php";
class Less extends lessc {
public function __construct() {
parent::__construct();
}
}
In the controller where you need it, something like:
$this->load->library('less');
$data['css'] = $this->less->checkedCompile(base_url()."path/to/test.less",base_url()."path/to/hoba.css");
$this->load->view('your_view', $data);
Also, it looks like you're storing .less and .css files in the application/views folder. You should store these outside the application folder, in a folder called "assets/css" or something similar.
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');