whenever using database library,error message is displayed - php

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()
{
}
}

Related

Codeigniter: PHP error on all pages

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

Cakephp How to access AppController function in ctp file?

I am unable to access AppController.php function in my ctp file.
Please check my code:
AppController
public function commonEmotions($text=null){
$this->loadModel("Sticker");
$this->loadModel("Smiley");
//Smiley
$getSmiley=$this->Smiley->find('all',array('fields'=>array('Smiley.image','Smiley.symbol')));
$emotions=$this->Custom->parseEmotions($text,$getSmiley);
//Sticker
$getSticker = $this->Sticker->find('all',array('fields'=>array('Sticker.uniq_id','Sticker.image')));
$message=$this->Custom->parseStickers($emotions,$getSticker);
return $message;
}
View/Messages/news_feed.ctp
echo $this->requestAction('/app/commonEmotions/'.$getNewsFeed['News_feed']['news']);
When i running my code i am getting fllowing error
Notice (8): Undefined index: News_feed [APP\View\Messages\news_feed.ctp, line 188]
Warning (2): Missing argument 1 for AppController::commonEmotions() [APP\Controller\AppController.php, line 51]
Instead of
echo $this->requestAction('/app/commonEmotions/'.$getNewsFeed['News_feed']['news']);
Do the request to any of your controllers instead of calling the app controller directly
echo $this->requestAction('/Smiley/commonEmotions/'.$getNewsFeed['News_feed']['news']);
As all your controllers inherit the method from the app controller

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.

Magento 1.3.2.2: Fatal error: Call to a member function getUsername() on a non-object

In Magento 1.3.2.2 we get a fatal error:
Fatal error: Call to a member function getUsername() on a non-object in
.../app/design/adminhtml/default/default/template/page/header.phtml on line 31
During an order confirmation, Magento should make a transition to the success page. But we are getting that error instead.
An Admin header is shown with this error. If I refresh, I get to the success page where I should have been taken if everything was ok.
This error happens because header.phtml on line 31 has entry:
$this->getUser()->getUsername();
But getUser() method didn't return valid object. This method pretty simple and looks like this:
return Mage::getSingleton('admin/session')->getUser();
So, you should debug only one place: app/code/core/Mage/Admin/Model/Session.php
Only one method setUser() object to session
public function login($username, $password, $request = null) {
...
$this->setUser($user);
If user object loads and valid it is mean that you have problem with session it self:
check how cookies sets
cookies path and created time
It is not easy find the problem remotely without debugging. So I wish you success.
I had the same error and solved it as follows:
Backup the var folder as (var-back)
Create a new var directory
Backup the locks folder as (locks-back) {if available}
Create the locks directory
Refresh the URL

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