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.
Related
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()
{
}
}
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
Since a couple of days I can't load a model in a codeigniter system anymore.
It gives the following error:
A PHP Error was encountered
Severity: Notice
Message: Undefined property: Clients::$mdl_clients
Filename: controllers/clients.php
Line Number: 48
Controller code:
private function GetAllClients()
{
$this->load->model('clients_model', 'mdl_clients');
$clients = $this->mdl_clients->getClients()->result_array();
return $clients;
}
I read the codeigniter documentation again, and I'am not doing anything wrong that I'am aware of..
Can you guys help me out?
Change the model name by 'clients_model.php' if you dont have, and your class most name 'Clients_model'
It was a weird issue with my server. I uploaded everything to another, and it worked again
I have a controller name ReminderController from which I wanna call admin_index.ctp.
class ReminderController extends AppController {
public function admin_index(){
$this->paginate=array('limit' =>'10');
$this->set('news', $this->paginate('Reminder'));
}
When I call view name admin_index from a controller I found an internal error has been occurred... please help me out from this problem.........
I'm not familiar with cakephp, but according to me error is in below 2 lines:
$this->paginate=array('limit' =>'10');
$this->set('news', $this->paginate('Reminder'));
Because, in the first line you are assigning an array to $this->paginate. But in the second line you are calling it as a function.
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.