I had a working project uploaded to server 2 week before. It was working fine until now. Below is code for model awsmodel.php
class Awsmodel extends MY_Model {
function __construct()
{
}
// some other functions
}
MY_Model again extends to CI_model.
class MY_Model extends CI_Model {
// required functions
}
From controller pages.php I am calling the function like below.
class Pages extends MY_Controller {
public function index()
{
$data = $this->allCommonMenu();
$this->load->model('Awsmodel');
$data['featured'] = $this->Awsmodel->featuredProp();
$this->load->view('home_pz',$data);
}
}
The above code suddenly stooped working today. After some test and tries, I got to know that when I comment below 2 lines from controller function then The page loads.
$this->load->model('Awsmodel');
$data['featured'] = $this->Awsmodel->featuredProp();
I have changed environment variable to 'development' and tested but still no error message shows. In firefox its showing a blank page, where as in chrome it shows 500 server error. The same code was working since 2 weeks. Don't know why its not working now. If anyone can help me out ?
I am using CI version 2.1.4
If you using CI 3.0 please load model like this
class Pages extends MY_Controller {
public function index()
{
$data = $this->allCommonMenu();
$this->load->model('awsmodel'); //as your model filename: awsmodel.php
$data['featured'] = $this->Awsmodel->featuredProp();
//$data['featured'] = $this->awsmodel->featuredProp();// for CI version 2.1.4 –
$this->load->view('home_pz',$data);
}
}
Related
Hi I followed this tutorial: https://book.cakephp.org/3/en/tutorials-and-examples/blog/part-two.html and having problem when tried to access the links: localhost/myprojectname/articles/index and localhost/myprojectname/articles/view/1
This is the screenshot:
Error:Missing Controller
I am using XAMPP and Chrome browser. The article model, articles controller and article view are created as written in the tutorial. But when I was trying to access the link at localhost/myprojectname/articles/index, there is missing controller error as shown in the screenshot above.
However, after insert <?php in the top of the articles controller and article model file, still showing same missing controller error as this screenshot: Error: Missing Controller 2
Copy and paste this to your AppController:
<?php
namespace App\Controller;
class ArticlesController extends AppController
{
public function index()
{
$this->set('articles', $this->Articles->find('all'));
}
public function view($id = null)
{
$article = $this->Articles->get($id);
$this->set(compact('article'));
}
}
I want to use pagination in my index page. So I used like following code in my project
class Transactions extends CI_Controller {
function __construct()
{
parent::__construct();
$this->load->model(array("Transaction"));
}
public function index()
{
$cond = array();
if($_POST){
$cond = $this->input->post();
}
// load Pagination library
$this->load->library('pagination');
It's work fine in my localhost, but when I upload this in live server, here show the following error..
An Error Was Encountered
Unable to load the requested class: Pagination
enter image description here
php v7.2
codeigniter v3.1.11
Please anyone help me how to solve this problem.
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
Well< I try to run CodeIgniter on my localhost with MAMP. I've changed base_url in config.php on $config['base_url'] = 'http://localhost:8888/codeigniter';
Also I've created blog.php as in tutorial I use:
<?php
class Blog extends Controller {
function index()
{
echo 'Hello World!';
}
}
?>
But, when I go to http://localhost:8888/codeigniter/index.php/blog/, there is output of my index.php ('test' - string) but there is no hello world there, what am I doing wrong?
the biggest breaking change between Codeigniter 1.7 -- which many tutorials are based on -- and Codeigniter 2 is the first line of code in the controllers and models
class Blog extends Controller {
change that to
class Blog extends CI_Controller {
same for models
class Donotmakemodeljokes extends CI_Model {
i use ubuntu 10.10 and codeigniter 2.0.2
i have successfully installed CI by opening welcome index page
later on i was following tutorial and have added new controller to my project:
class Start extends CI_Controller{
var $base;
var $css;
function __construct() {
parent::__construct();
$this->base=$this->config->item('base_url');
$this->css=$this->config->item('css');
}
function hello($name){
$data['css'] = $this->css;
$data['base'] = $this->base;
$data['mytitle'] = 'Welcome to this site';
$data['mytext'] = "Hello, $name, now we're getting dynamic!";
$this->load->view('testview', $data);
}
}
as well as view(testview.php) and css variable in question. then upon trying to test it by executing http://localhost/ci/index.php/index/start/hello/fred i get 404 page not found.
thank you
use this class declaration instead
class Start extends CI_Controller{
and instead of your php4 constructor
use this instead of Start()
function __construct(){
parent::__construct();
$this->base=$this->config->item('base_url');
$this->css=$this->config->item('css');
}
The actual reason you're getting a 404 is because you're telling it to find a function called fred. The url you're probably meaning to hit is this...
http://localhost/ci/index.php/start/hello/fred
Since 2.0.x , Codeigniter has changed their base controller class names and moved everything to php5 style constructors, among other things.
You are probably following a older tutorial.
It seems you have used an old tutorial. In CodeIgniter 2, some things are different.
extend CI_Controller instead of extend Controller
Use __construct for constructors instead of the class name.
function __construct(){
parent::__construct();
// More stuff
}
The url should be http://localhost/ci/index.php/start/hello/fred. CodeIgniter's URLs are used like so:
http://localhost/ci/index.php/<controller>/<method>/<params>