Codeigniter: PHP error on all pages - php

I have been working on a site using codeigniter. On localhost, everything works well but when I uploaded it online, all its pages got a php error below the footer. The error is as shown below:
A PHP Error was encountered
Severity: Warning
Message: Unknown: failed to open stream: No such file or directory
Filename: Unknown
Line Number: 0
The Controller
class Home extends CI_Controller {
public function __construct()
{
parent::__construct();
$this->load->helper(array('form','url'));
$this->load->library(array('session'));
$this->load->database();
$this->load->model('property_model');
}
public function index()
{
$data['title'] = "iRent-Home";
$this->load->view('home',$data);
}
}
I thought the error might be caused by the header or footer views since they are loaded on each page. I have counter checked the code in those two views and they look okay. I think it might also be a permissions issue, tried giving several files permission but it didn't work. Anyone with an idea what the problem is?

kindly read the documentation on errors https://ellislab.com/codeigniter/user-guide/general/errors.html and review your code

Related

whenever using database library,error message is displayed

whenever loading this
$this->load->library('database');
error is shown
Unable to load the requested class: database
without the above mentioned code,the following error is shown.
A PHP Error was encountered
Severity: Notice
Message: Undefined property: LoginPage::$db
Filename: core/Model.php
Line Number: 52
Fatal error: Call to a member function select() on null in
C:\xampp\htdocs\Test_LR\application\models\Login_model.php on line 11
FIle permission From Filezilla...
Connect your FTP client to your web server. In FileZilla, right-click the "system" folder on your web server and choose File Permissions to open the file attributes. Type the correct number in the Numeric Value text field
This means CodeIgniter has a library database.
You can include libraries in two ways:
1) In application/config/autoload.php
Code:
$autoload['libraries'] = array('database'); // Include other libraries here like `session`.
2) Run time by using $this->load->library('database'); if not included with first method.
Without it, it will show fatal error.
Have you tried to use:
$this->load->database();
Instead of $this->load->library('database');
Or double check if your database file available on system
Sample example Usersmodel.php
class usersmodel extends CI_Model
{
function __construct()
{
parent::__construct();
$this->load->database();
}
function examplefunction()
{
}
}

Routing in CakePHP 1.3.3 has suddenly stopped working for one folder (beforeFilter issues?)

We've had an application running on CakePHP 1.3.3 for years without a single hitch, but randomly it's started saying "The requested address /task_scheduler/task_scheduler_mailouts was not found on this server." - but it's only effecting this. Everything else running on that server (including other CakePHP applications) are fine.
When I enable debug in core.php, I get the following error messages:
Notice (8): Undefined variable: currentUser [APP\views\themed\default\layouts\default.ctp, line 50]
Error: The Behavior file app\models\behaviors\null.php can not be found or does not exist.
Error: Create the class below in file: app\models\behaviors\null.php
<?php
class NullBehavior extends ModelBehavior {
}
?>
All of the files are present in /task_scheduler/task_scheduler_mailouts and the currentUser variable is working without any problems on the other pages. currentUser is set in the beforeFilter() function in app_controller.php which as far as I know is used for every single page.
function beforeFilter() {
...
$currentUser = ClassRegistry::init('WfEmployee')->getNetworkUser();
...
}
(update) if I hardcode the $currentUser variable I still get the not set notice. I don't think the beforeFilter() function is even running.
Any ideas as to what could have suddenly caused this error please? Thank you.
function beforeFilter() {
parent::beforeFilter();
$currentUser = ClassRegistry::init('WfEmployee')->getNetworkUser();
...
}

Print invoice button gives blank page with error

I want to print the invoice through the back-end of magento at invoices but it gives me this error after I turned on the errors in index.php
Fatal error: Call to a member function getPdf() on a non-object in app/code/core/Mage/Adminhtml/Controller/Sales/Invoice.php on line 119
public function printAction()
{
if ($invoiceId = $this->getRequest()->getParam('invoice_id')) {
if ($invoice = Mage::getModel('sales/order_invoice')->load($invoiceId)) {
$pdf = Mage::getModel('sales/order_pdf_invoice')->getPdf(array($invoice));
$this->_prepareDownloadResponse('invoice'.Mage::getSingleton('core/date')->date('Y-m-d_H-i-s').
'.pdf', $pdf->render(), 'application/pdf');
}
}
else {
$this->_forward('noRoute');
}
}
The error says that this line:
$pdf = Mage::getModel('sales/order_pdf_invoice')->getPdf(array($invoice));
contains an error but I don't see any problem also I don't get it why it gives error on a core folder php file. I haven't modify it in any way too.
First, tell which version of Magento you are using?
Meanwhile, you may try the following:
disable all the installed extensions, and when enabling them one by one, figure out which module is triggering the issue;
clear cache.
Magento uses old Zend PDF library which has an issue:
http://framework.zend.com/issues/browse/ZF-12093
Just comment
//abstract public function __construct();
//abstract public function __destruct();
in
app\code\local\Zend\Pdf\FileParserDataSource.php.

How to load two models in the same controller with CodeIgniter?

I've been searching on Internet and on stackoverflow, but i didn't find a solution, or it wasn't the same problem.
I need to load two models in the same controller, and in the same function. One is "model_membre" and the other "model_annonce". It's the name of the class, the file, and the object.
Individually, they work very good, i can access to properties and methods, but when I'm loading the two models, I can't access to the second, regardless of how I load it (autoload, $this->load->model('model_name'), $this->load->model('model_name', 'object_name')).
I simplified to a "test" controller, to see if it was not another part of my code that made the problem :
public function index()
{
$this->load->model('model_membre', 'membre');
$this->load->model('model_annonce', 'annonce');
$liste = $this->annonce->listerEspeces();
$membre = $this->membre->obtenirMembre(1);
}
I tried to changer the order, and the 2nd loaded never works. I get this message :
A PHP Error was encountered
Severity: Notice
Message: Undefined property: Test::$annonce
Filename: controllers/test.php
Line Number: 15
Fatal error: Call to a member function listerEspeces() on a non-object in /homez.604/animalix/beta/application/controllers/test.php on line 15
Please try the following way...
public function index()
{
$this->load->model(array('membre','annonce'));
$liste = $this->annonce->listerEspeces();
$membre = $this->membre->obtenirMembre(1);
}
The models should extend CI_Model and not CI_Controller! This was the source of the problem.

How to call function from Controller to include into the View page with Codeigniter?

I want to call function from Controller to include into the View page with Codeigniter. Usually when I open any page, I call $this->load->view() in Controller for open that page. Now I want to include sub page into main page, but it can't include any function in View. I try to include function like this.
<body><? include(site_url().'/login'); ?></body>
<body><? include('/login'); ?></body>
<body><? include('./login'); ?></body>
I can open page with this link http://localhost/ci_house/index.php/login. but when I open main page for run my code it show these error.
A PHP Error was encountered
Severity: Warning
Message: include(http://localhost/ci_house/index.php/login) [function.include]: failed to open stream: no suitable wrapper could be found
Filename: views/main.php
Line Number: 8
A PHP Error was encountered
Severity: Warning
Message: include() [function.include]: Failed opening 'http://localhost/ci_house/index.php/login' for inclusion (include_path='.;C:\php5\pear')
Filename: views/main.php
Line Number: 8
I want to show 2 view in 1 page .
function test1()
{ $data['var_for_login_view'] = 'get table1';
$this->load->view('main1',$data);
}
function test2()
{ $data['var_for_login_view'] = 'get table2';
$this->load->view('main2',$data);
}
In views/main.php:
$this->load->view('test1');
$this->load->view('test2');`
I want to show like
<body>
include('main1.php');
include('main2.php');
</body>
but I can show like this in Codeigniter.
I really can't understand your question well, but hey, you can "include" any view within another view without problems..
In main.php:
$this->load->view('login');
You don't even need to pass it the paramwters, as they are buffered so available to any child view you might insert. But please, be more clear on what you actually need.
If you want to include in main() the same views you load in login() method, of course you don't have to include a CI URI, but just create the variables you need to pass inside the controller's method login(), and then call whatever view you want, be it a view which is designed for this specific method or for any other controller's method.
So, for.ex.
function login()
{
$data['var_for_login_view'] = 'a variable';
$data['var_for_this_view'] = 'another variable';
$this->load->view('main');
}
In views/main.php:
echo $var_for_this_view;
$this->load->view('login');
echo $var_for_login_view;
// see? $data was not passed to $this->load->view('login'), but it's still there nonetheless!
What I understand is this: You have some functions defined in one of your controllers and you want to be able to call these functions from another controller/view.
If this is correct, then we can't normally do this. Here are a couple of alternatives:
Move these functions to a library/helper. Load that library/helper wherever you want and then you can call these functions.
If you absolutely need to call these functions from the controller, you can look into HMVC extension.
You can't include using site url, use this $this->load->view('template', $data); for codeigniter.

Categories