Method load fails in codeigniter 3 - php

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...

Related

CodeIgniter - Hyperlink creation

I have tried to create a hyperlink to another page using anchors however it doesn't seem to work.
My function is called calendar and its stored in calcontrol.php within a controllers directory.
<?php
defined('BASEPATH') OR exit('No direct script access allowed');
class Calendar extends CI_Controller{
public function __construct()
{
parent::__construct();
$this->load->helper('url');
}
public function index()
{
$this->load->view('calendar');
}
}
?>
I have tried other methods but they do not seem to work.
edit : this is my a href
Link
Filename and classname must be the same, otherwise CI will not be able to load it. And if using CI 3, make sure your class name and filename are both Ucfirst. If you have everything set up like this, then you should be able to view the page through http://yourdomain.com/calendar/calendar
Try this code. You forgot to load url helper. File Calendar.php - nogice capital C if CI3:
<?php
defined('BASEPATH') OR exit('No direct script access allowed');
class Calendar extends CI_Controller
{
public function __construct()
{
parent::__construct();
$this->load->helper('url');
}
public function index()
{
$this->load->view('calendar');
}
}

codeigniter controller won't load view

I am new to coding and have fallen in love with codeigniter and recently moved from a wamp server to a LAMP server. I've extracted codeigniter into /var/www/ and set the root directory of the host in apache. I can see the codeigniter welcome page, however if I change the default controller in config.php to my controller and load this controller:
class Site extends CI_Controller {
public function index() {
$this->load->view('home_view');
}
}
I get this text in my browser:
$this -> load -> view ('home_view'); }}
The only line of my index function as well as a codeigniter generated 404 error below it.
base_url() and default controller are set, codeigniter welcome page works fine, but my page does not.
Does anyone have an idea as to why? Your help is very much appreciated.
Make sure your controller is inside application/controllers and the name is site.php
<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');
class Site extends CI_Controller {
public function __construct()
{
parent::__construct();
}
public function index()
{
$this->load->view('home_view');
}
}

Unable to locate the model after upgrate

i started a website using codeigniter 3 -dev about couple of month ago , today i've upgrade it to latest version on github .... it works fine on localhost but when i upload it on server it couldn't find the models !!
http://epatil.com/ci_test
my only controller :
<?php
defined('BASEPATH') OR exit('No direct script access allowed');
class Welcome extends CI_Controller {
public function index()
{
$this->load->model('test');
$this->test->echo_print();
$this->load->view('welcome_message');
}
}
my test.php model
<?php
class test extends CI_Model {
public function __construct(){
parent::__construct();
}
function echo_print(){
echo 1234;
}
}
her eis the result :
Unable to locate the model you have specified: Test
btw changing it's name to Test wouldn't help and it used to work fine with lowercase before upgrade
According to the version 3 user guide, the class names MUST match the file name, whereas this wasn't the case, in version 2.
http://www.codeigniter.com/userguide3/general/models.html#anatomy-of-a-model

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

Placing Private Function in Subdirectories in Codeigniter/PHP not working

I am utterly and completely confused. I've looked through all the documentation and I can't find a solution. Setup: CI 2.1.3, QNAP server.
Problem: I cannot use a private function on a controller:
<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');
class Signup extends CI_Controller {
public function index()
{
_loadcontent();
}
private function _loadcontent()
{
$this->load->view('welcome_message');
}
}
/* End of file signup.php */
/* Location: ./application/controllers/account/signup.php */
it won't work and gives an HTTP Error 500 (Internal Server Error). HOWEVER, placing the file in the main controller directory works. Does anybody have any clue? is this a bug? Thanks in advance.
You need to call the function using $this.
public function index()
{
$this->_loadcontent();
}

Categories