Where do I put image files, css, js, etc. in Codeigniter?

I have a setup like this: application system assets js imgs css I then have a helper function that simply returns the full path to this depending on my setup, something similar to: application/helpers/utility_helper.php: function asset_url(){ return base_url().’assets/’; } I will usually keep common routines similar to this in the same file and autoload it … Read more

PostgreSQL next value of the sequences?

RETURNING That’s possible with a single round-trip to the database: INSERT INTO tbl(filename) VALUES (‘my_filename’) RETURNING tbl_id; tbl_id would typically be a serial or IDENTITY (Postgres 10 or later) column. More in the manual. Explicitly fetch value If filename needs to include tbl_id (redundantly), you can still use a single query. Use lastval() or the … Read more

Using Mysql WHERE IN clause in codeigniter

You can use sub query way of codeigniter to do this for this purpose you will have to hack codeigniter. like this Go to system/database/DB_active_rec.php Remove public or protected keyword from these functions public function _compile_select($select_override = FALSE) public function _reset_select() Now subquery writing in available And now here is your query with active record … Read more

Uploading a csv into Codeigniter

I got it working by adding cbrandolino’s suggested mimetypes to the config/mimes.php (great tip jljohnstone). So the csv property of my $mimes looks like this now: ‘csv’ => array(‘application/vnd.ms-excel’, ‘text/anytext’, ‘text/plain’, ‘text/x-comma-separated-values’, ‘text/comma-separated-values’, ‘application/octet-stream’, ‘application/vnd.ms-excel’, ‘application/x-csv’, ‘text/x-csv’, ‘text/csv’, ‘application/csv’, ‘application/excel’, ‘application/vnd.msexcel’)

COUNT / GROUP BY with active record?

I believe you’ll want something like this: $this->db->select(‘user_id, COUNT(user_id) as total’); $this->db->group_by(‘user_id’); $this->db->order_by(‘total’, ‘desc’); $this->db->get(‘tablename’, 10); This will produce a result like | USER_ID | TOTAL | | 12 | 3 | | 15 | 2 | | 18 | 1 | UPDATE: As some pointed out in the comments the original query was summing … Read more

Codeigniter image resize?

You shouldn’t load image_lib in foreach. Try to use code below $this->load->library(‘image_lib’); foreach($results as $row) { $config[‘image_library’] = ‘gd2’; $config[‘source_image’] = ‘/img/proizvodi/’.$row->proizvodid.’.jpg’; $config[‘create_thumb’] = TRUE; $config[‘maintain_ratio’] = TRUE; $config[‘width’] = 75; $config[‘height’] = 50; $this->image_lib->clear(); $this->image_lib->initialize($config); $this->image_lib->resize(); } If it wont work – check the upload folder permissions.

Correct naming structure for CodeIgniter

URLs Your URLs should typically be all lowercase letters. If you expect capital letters, there’s a chance you could accidentally exclude their lowercase counterparts, even though they’re the same URL. Example: www.example.com/controller/method/param Controllers Controller class names should be all lowercase, except the first letter. If your URL is www.example.com/gallery, the controller name is Gallery. If … Read more