All Questions

Tagged with
Filter by
Sorted by
Tagged with
23 votes
8 answers
45k views

How would I use ON DUPLICATE KEY UPDATE in my CodeIgniter model?

I have a CodeIgniter/PHP Model and I want to insert some data into the database. However, I have this set in my 'raw' SQL query: ON DUPLICATE KEY UPDATE duplicate=duplicate+1 I am using CodeIgniter ...
Jack's user avatar
  • 9,693
20 votes
4 answers
22k views

Can you access a model from inside another model in CodeIgniter?

I am writing a webapp using CodeIgniter that requires authentication. I created a model which handles all my authentication. However, I can't find a way to access this authentication model from inside ...
Eldila's user avatar
  • 15.6k
14 votes
5 answers
33k views

Loading and using a codeigniter model from another model

Fellow coders, using codeigniter 1.7.3 can I load a model from the code of another model? I have read many posts theoretical and practical but none gave a final answer. I have a model that has a ...
djeetee's user avatar
  • 1,827
12 votes
5 answers
11k views

How to Inherit A Model from Another Model in CodeIgniter

i'm using codeigniter for my project and i have this class model which i call Genesis which looks like this: class Genesis_model extends CI_Model { function __construct() { parent::...
dqiu's user avatar
  • 327
12 votes
5 answers
7k views

Difference between Controller and Model in MVC

I'm little confused about controller and model in MVC framework (codeIgniter). Its clear to me that controller methods calls the views and Model methods interact with database. However, I'm little ...
Roman's user avatar
  • 3,749
11 votes
13 answers
81k views

Unable to locate the specified class: Session.php in Codeigniter

The browser: Unable to locate the specified class: Session.php This is my Controller: <?php class Chat extends CI_Controller { public function __construct() { parent::__construct(...
thais's user avatar
  • 133
11 votes
1 answer
7k views

How to access model to query database from a helper function?

I am trying to create authentication for my php website. I am using the codeigniter framework. I will have to validate the session in all the pages of my website. So to avoid the code repetition, i am ...
Vinod's user avatar
  • 32.5k
10 votes
2 answers
7k views

How can I use proper object-oriented models in CodeIgniter with constructors?

The way I create CodeIgniter models at the moment is (i.e. no constructor, having to pass userID all the time and limited to one object): $this->load->model('User'); $this->user->...
Matt Votsikas McLean's user avatar
9 votes
3 answers
12k views

codeigniter instance of model class

I'm developing a site with codeigniter. Now, normally when you use a class in codeigniter, you basically use it as if it were a static class. For example, if I head a model called 'user', I would ...
bigblind's user avatar
  • 12.7k
9 votes
3 answers
12k views

Object Oriented Approach in Codeigniter Model

I have been wondering what is the right way to write code in OO style in model. Certainly you can have a function that retrieve data from DB and then map to model-level variables. This approach, ...
Troy's user avatar
  • 95
8 votes
4 answers
10k views

how load model in another modules in hmvc in codeigniter?

I want to use The Modular Extensions HMVC in my Project like this: modules module01 models models01.php controllers controller01.php ...
aya's user avatar
  • 1,605
7 votes
4 answers
11k views

Codeigniter: how can i tell if a model is already loaded?

Are there native codeigniter functions I can use to tell if a certain model has already been loaded? Can php's class_exists() be used to tell if a model has already been loaded?
Zaki Aziz's user avatar
  • 3,712
7 votes
3 answers
11k views

How to load a model from another module with CodeIgniter

Im using the HMVC extension with CodeIgniter and i got 2 modules modules/frontpage -- controllers frontpage.php ( <- this controller needs to load the person model) -- models -- views ...
Vidar Vestnes's user avatar
6 votes
1 answer
6k views

Codeigniter Unit-testing models

I'm new to unit-testing, so this is maybe a little dumb question. Imagine, we have a simple model method. public function get_all_users($uid = false, $params = array()){ $users = array(); if(...
DCrystal's user avatar
  • 711
6 votes
1 answer
7k views

How to send complete POST to Model in Code Igniter

What would be the best way to send a complete post to a model in Code Igniter? Methods I know are as follow: Name form elements as array, eg. <input type="text" name="contact[name]"> <...
Constant Meiring's user avatar
6 votes
3 answers
5k views

Single transaction on multiple model function with CodeIgniter

I need to insert into 2 tables if anything goes wrong while inserting in any of the table I want to rollback commited queries. I wrote queries inside controller for example: $this->db->...
bhanushalimahesh3's user avatar
6 votes
1 answer
3k views

Codeigniter one transaction with two model

Is it possible to have one "transaction" with to separate models. I want to insert a post with their tags. Tags and Posts are in two separate models. How can i achive to handle it with a transaction? ...
Iamzozo's user avatar
  • 2,361
5 votes
5 answers
57k views

$this->load->model() not working in CodeIgniter

I'm using CodeIgniter 2.1.2 and here's my situation right now. I have a model named math.php in C:\wamp\www\cr8v\application\models. I am trying to load this in my controller from C:\wamp\www\cr8v\...
Charmie's user avatar
  • 2,522
5 votes
2 answers
11k views

Codeigniter and Set Session in Model

I want to unset and set session in model function depend on passed id. I have language field for every record and should change session considering that. in sample word i have a link like this : http:/...
Bahrami-Reza's user avatar
5 votes
3 answers
9k views

Codeigniter - return my model object instead of stdClass Object

Not sure the best way of phrasing this so bear with me. Within Codeigniter I can return a record set of my object no problem but this is returned as a stdClass object not as an "model" object (for ...
simnom's user avatar
  • 2,610
5 votes
1 answer
3k views

Should you handle session data in a controller or a model for an MVC framework?

I am working with an MVC framework (specifically, PHP's CodeIgniter). I am trying to follow "best practices" as much as possible, but I don't have much experience with MVC. Is it bad practice for me ...
Scott Fink's user avatar
5 votes
2 answers
1k views

CI affected_rows always return 0 even after Updated

I use Codeigniter 3.0.6 to build a system. Usually, I use affected_rows() to check whether my database is updated or not. function update($id=0,$data=array()) { $this->db->...
shevado's user avatar
  • 73
4 votes
1 answer
72k views

Codeigniter: foreach method or result array?? [Models +View]

I am currently following tutorials on viewing data from the database using the Framework Codeigniter. There are various ways in which I've learnt. Is there is a more realiable way- either displaying ...
Shimsham84's user avatar
4 votes
3 answers
9k views

Codeigniter MY_Model class

I'm trying to write my own MY_Model base class but I'm facing a weird problem: /core/MY_Model.php function __construct() { if ( !empty($this->table)) { // query db, ...
Steph's user avatar
  • 149
4 votes
3 answers
1k views

Codeigniter models are just utility classes?

In the MVC that I'm accustomed to, model classes (usually) represent tables and objects of these classes are rows/domain objects. I don't understand in CodeIgniter why model classes appear to just be ...
takteek's user avatar
  • 7,060
4 votes
4 answers
23k views

Code Igniter Model To Model Relationship

In CI, how do you relate each other the models?I have four models right now Users, UsersDepartment, UsersToDepartment, UserStatus and I need to join those four models to be able to pick up all the ...
user1149244's user avatar
4 votes
3 answers
315 views

Is it bad to use a model directly from a view in codeigniter?

I know normally the data is passed thru to the view with the controller. however, currently in my view I load my model ($this->load->model('Db_model');) so i can use it in a loop to retrieve a users ...
jason's user avatar
  • 41
4 votes
1 answer
2k views

Codeigniter form validation external callbacks

I need to check if the user_id that was inserted exists. I was going to use callbacks in Codeigniter form validation but they require the function that does the validation be in the controller. I'm ...
Dylan Buth's user avatar
  • 1,646
4 votes
3 answers
6k views

Codeigniter abstract base model

Is it possible to implement an abstract base model in Codeigniter? I have created a abstract class which has basic CRUD functionalities but I am receiving a "Cannot instantiate abstract class" error. ...
GazNicoll's user avatar
4 votes
1 answer
152 views

Record some data to database in Codeigniter

I got a problem I have a questionnaires website using students as respondents to fill in the matter of the website. The Problem is, when sending data contained on the results of questionnaires to the ...
Ron Ashrovy's user avatar
3 votes
4 answers
6k views

My Model (by Jamie Rumbelow) - how to use 'where' with the model

I have integrated the Jamie Rumbelow My Model for doing active record queries with codeigniter from github - https://github.com/jamierumbelow/codeigniter-base-model I'd like to use the normal ...
Zabs's user avatar
  • 14k
3 votes
4 answers
794 views

PHP MVC Principles

I'm not using an off-the-shelf framework and don't particularly want to (nor d I want to go into the reasons why...). Anyway, onto my question(s), I hope it make sense.... I'm trying to get my head ...
George's user avatar
  • 47
3 votes
2 answers
633 views

General rule - when to use a model (Codeigniter)

I was just curious as to what the rule of thumb was for models. Generally, I use them only for situations where I need to add/edit or update database entries for an object. However, I'm building an ...
pingu's user avatar
  • 614
3 votes
2 answers
4k views

Should I call redirect() from within my Controller or Model in an MVC framework?

I'm using the MVC PHP framework Codeigniter and I have a straight forward question about where to call redirect() from: Controller or Model? Scenario: A user navigates to www.example.com/item/555. ...
justinl's user avatar
  • 10.5k
3 votes
2 answers
9k views

How to use Multiple Tables in Codeigniter 4

I have worked with CI 3 so far and would like to address several database tables separately (no joins) in a new model (in CI 4). <?php namespace App\Models; use CodeIgniter\Model; class MyModel ...
Tom's user avatar
  • 79
3 votes
2 answers
26k views

CodeIgniter load database in Controller or Model?

Model : class Users_model extends CI_Model { function __construct() { parent::__construct(); $this->load->database(); } public function get_all_users() { ...
dango sjv's user avatar
  • 173
3 votes
1 answer
2k views

Codeigniter gettiing one to many relation from model and parsing in view

I have 3 tables namely - celebs, celeb_roles, celeb_industry. celebs is the main table with one to many relation with other 2 tables. celebs is having the columns - id, name, nationality, status. ...
user1638279's user avatar
3 votes
2 answers
758 views

model to fetch single result from db with jquery

I have a controller function which is called by jquery: function get_sku_prices(){ $this->load->model('Sales_model'); if (isset($_GET['term'])){ $q = strtolower($_GET['term']); ...
Smudger's user avatar
  • 10.6k
3 votes
1 answer
490 views

Error loading Model in Codeigniter 1.7.3

Hello and thanks for reading, I have a problem, I have a controller "Articles" that is supposed to load Model called "Articles", only problem is I get a 500 server error when I try to load that model?...
hypervisor666's user avatar
3 votes
4 answers
2k views

How should i handle errors in my Codeigniter Models?

i am starting to put validation/sanitization in my codeigniter models, and before diving in too deep I am looking for some suggestions on best practices. the form validation library for controllers is ...
Andrew Brown's user avatar
  • 5,408
3 votes
1 answer
3k views

Codeigniter MY_Model composite primary key

I'm working with a base class MY_Model for accessing the database, which contains all the CRUD methods. The model which I'm using is Jens Segers' MY_Model: https://github.com/jenssegers/CodeIgniter-...
Tomzie's user avatar
  • 1,358
3 votes
1 answer
1k views

fat model and skinny controller design confusion between the controller method and model method

i'm newbie in MVC (using codeIgniter as my example) and i have read MVC fat model and skinny controller for like 3 times, what i got : model does the hardwork while controller calls the model and ...
mohur's user avatar
  • 1,855
3 votes
2 answers
2k views

codeigniter initialize variable on each model method call

In codeigniter I want to initialize variables every time I call method of a model. I tried using constructors but constructors are called only when your model is loaded once and after that any call to ...
Kaushil Rambhia's user avatar
3 votes
1 answer
2k views

How to migrate from CodeIgniter database to Laravel database

I have decided to migrate from my CodeIgniter app to laravel specially for their rails-likely handling of the database. The problem though is that i have 800mb of database to migrate. How can I do ...
Håkan Nylén's user avatar
2 votes
2 answers
6k views

CodeIgniter: Can't load database from within a model

I've written a new model for my CodeIgniter framework. I'm trying to load the database from within the constructor function, but I'm getting the following error: Severity: Notice Message: Undefined ...
thedp's user avatar
  • 8,401
2 votes
2 answers
14k views

Model loaded in Codeigniter controller's constructor is not available by other functions of same controllers

My model: as seen below, very basic class User extends CI_Model { function __construct() { parent::__construct(); } function getAll() { $this->db->order_by("...
user1082522's user avatar
2 votes
4 answers
6k views

codeigniter model not loading into controller, but no errors

I am having trouble with a models in Codeigniter. I setup a model called Usermodel in /models/usermodel.php. and when I attempt to load it is stops the scrip and anything after it. When I purposely ...
Timmeh's user avatar
  • 135
2 votes
3 answers
1k views

Help with Codeigniter and MVC model pattern

I am creating a site much like a wordpress blog whereby the front page will display a post loop: with the post_summary, author info, and tags. I have four tables: posts | users | tags | tag ...
CruisinCosmo's user avatar
  • 1,157
2 votes
4 answers
12k views

codeigniter pass variable from controller to model

simple issue I presume. My controller is getting the if to display from the url using $this->uri->segment(3). This will always be a single value. I am putting this in an array to pass to the ...
Smudger's user avatar
  • 10.6k
2 votes
2 answers
2k views

Codeigniter config file change from model or controller

How can we edit config file details from model or controller...? I want to change currency based on location of the user...
Nishit Modi's user avatar

1
2 3 4 5
10