Quantcast
Channel: CodeIgniter Forums - All Forums
Viewing all 14082 articles
Browse latest View live

Pagination Help

$
0
0
Hi All,

I'm running into an issue with Pagination. Not used CI in years so a little rusty.

The issue is when I click on a page it does not load the data for that page and keeps it as the first record but the page number changes.
What noob mistake have I done?

Controller - Site.php
PHP Code:
    public function view($offset 0)
    {
        
$this->output->enable_profiler(TRUE);
        
$this->load->model('View_Model');
        
        
$limit 1;
        
$result $this->View_Model->get_images($this->uri->segment(2),$limit$offset);
        
$count $this->View_Model->count_images($this->uri->segment(2));
        
$data['images'] = $result['rows'];
        
        
$config = array();
        
$config['base_url'] = base_url() . "view/".$this->uri->segment(2)."";
        
$config['total_rows'] = $count['num_rows'];
        
$config['per_page'] = $limit;
        
$config['uri_segment'] = 3;
        
$config['use_page_numbers'] = TRUE;
        
$config['cur_tag_open'] = '&nbsp;<a class="current">';
        
$config['cur_tag_close'] = '</a>';
        
$config['next_link'] = 'Next';
        
$config['prev_link'] = 'Previous';
        
        
$this->pagination->initialize($config);
        
        
$data['pagination'] = $this->pagination->create_links();
        
        if (
$this->uri->segment(2) == TRUE)
        {
            
//Select Album Info
            
$get_album_slug $this->db->get_where('albums', array(
                
'album_slug' => $this->uri->segment(2)
            ));
            
            
//Check to see if an album record is found and fail if not
            
if ($get_album_slug->num_rows() <= 0) {
                echo
"Nothing Found";
            }
            
            
// Load Template Output
            
$data['main_content'] = 'view';
            
$this->load->view('template'$data);
        }
        else
        {
         
       Echo"Failed Seg 3";
        }
    } 

Model - View_Model.php
PHP Code:
       public function __construct()
 
       {
 
               // Call the CI_Model constructor
 
               parent::__construct();
 
       }

 
       public function get_images($album_slug$limit$offset)
 
       {
                if (
$offset 0) {
                    
$offset = ($offset 1) * $limit;
                }
                
//Get Images assigned to the Album
                
$this->db->select('*');
                
$this->db->from('albums');
                
$this->db->where('album_slug'$album_slug); 
                
$this->db->join('images''albums.album_id = images.album_id');
                
$this->db->limit($limit,$offset);
                
$result['rows'] = $this->db->get();
                return 
$result;
 
       }
        
        public function 
count_images($album_slug)
 
       {
                
//Get Images assigned to the Album
                
$this->db->select('*');
                
$this->db->from('albums');
                
$this->db->where('album_slug'$album_slug); 
                
$this->db->join('images''albums.album_id = images.album_id');
                
$result['num_rows'] = $this->db->count_all_results();
                return 
$result;
 
       

Routes.php
PHP Code:
$route['view/(:any)'] = 'site/view/(:any)';
$route['view/(:any)/(:num)'] = 'site/view/(:any)/$1';
$route['view'] = 'site/view'

CI 3.1.1 Session not kept

$
0
0
HI 

I had updated to CI 3.1.1 and i had a problem with session not being kept from 2 urls. If i rollback to codeigniter 3.1.0 works ok.

is there any info on session for the upgrade?
 
PHP Code:
class Test extends CI_Controller {
 

 
public function index(){
  
$this
->session->set_userdata('key',"val1");
var_dump($this->session->userdata);

echo 
"hi";
 

}
public function 
p(){
var_dump($this->session->userdata);
}



Thanks

Searching with serialized id's

$
0
0
When the user types in the search PHP it should find the questions that have category id of 1

I store my category id in a column in question called "tags" it's serialized of couse because the user may have chosen multiple tags / categories.

The category table name is category and columns "category_id" "name" "status"

a:2:{i:0;s:1:"1";i:1;s:1:"4";}

I can search for questions fine but cannot search if it is a category they are searching for.

Any idea's and examples thanks for your time

PHP Code:
public function get_questions($search) {
    $this->db->select('*');
    $this->db->from($this->db->dbprefix 'question');
    $this->db->like('title'$search);
    $query1 $this->db->get();

    if ($query->num_rows() > 0) {

        foreach ($query->result_array() as $key) {
            $data[] = array(
                'question_id' => $key['question_id'],
                'title' => $key['title'],
                'votes' => $key['votes'],
                'answers' => $this->answer_model->count_answers($key['question_id']),
                'views' => ''
            );
        }
    }

    return $data;



Controller



PHP Code:
<?php 

class Search extends MY_Controller {

    public function __construct() {
        parent::__construct();
        $this->load->library('user_agent');

        if ($this->input->get('q') == FALSE) {
            redirect($this->agent->referrer());
        }

        $this->load->model('answers/answer_model');
    }

    public function index() {
        if ($this->input->post('search')) {

            $q str_replace('+',  ' '$this->input->get('q'));

            $data['title'] = 'Questions ' "'" $q "'";

            $question_results $this->get_questions($q);

            $data['questions'] = array();

            if (isset($question_results)) {
                foreach ($results as $result) {
                    $data['questions'][] = array(
                        'question_id' => $result['question_id'],
                        'title' => $result['title'],
                        'votes' => $result['votes'],
                        'answers' => $this->answer_model->count_answers($result['question_id']),
                        'views' => ''
                    ); 
                }
            }

            $data['page'] = 'search/search_results';

            $this->load->view($this->config->item('config_template') . '/template/template_view'$data);

        }
    }



.php   Search.php (Size: 1.59 KB / Downloads: 1)

Calling index() on form validation failure

$
0
0
Hello, I'm doing something like this in my controller:

PHP Code:
       if ($this->form_validation->run() == FALSE) {
 
           $this->index();
 
       } else {
 
           $this->load->view('template/meta-head'$custom);
 
           $this->load->view('template/header');
 
           $this->load->view('fastauditthx');
 
           $this->load->view('template/footer'$custom);
 
       

Basically, if form fails, send back to form, if good, then send to "Thank you view".

For testing I have added only one set_rules() rule:

PHP Code:
$this->form_validation->set_rules('f_eventname''Event Name''required|trim|min_length[3]|max_length[100]|callback_customAlpha'); 

The action goes to index as expected, but f_eventname always seems to fail, no matter what I put in there.

callback_customAlpha is in a helper file that is loaded in the construct function.

Anyway, I thought I'd post here to see what you all think as my eyes are "end of day eyes" right now.

Thanks,
Donovan

Upload Class - Some EPS files fail to upload

$
0
0
Version: CI 3.1.0

Uploading EPS files via form, however, in some instances we receive the following error

Quote:Error:

The filetype you are attempting to upload is not allowed.

All EPS file mime-types have been declared in application/config/mimes.php.  Have tried them both individually and as an array below.

Code:
'eps' => array('application/postscript', 'application/eps', 'application/x-eps', 'image/eps', 'image/x-eps'),

The issue appears to be some EPS files contain a first line beginning with ÅÐÓÆ which seems to be and identifier that the EPS file containts a TIFF/WMF preview thumbnail.  This line can mistakenly be interpreted as a Postscript command.

A standard EPS file begins immediately with the type identifier such as "%!PS-Adobe-3.1 EPSF-3.0" .  Apparently code igniter can then not identify this file type properly and fails with the error.  If we open the file in a text editor and remove the offending line, upload succeeds as expected.

Is there a generic mime-type I can use to force and upload without actually identifying the file or some other work around?  We are receiving artwork from many sources and would be unable to inform them of a requirement for modifying their Adobe settings.

Need help with Hotelbed API

Inserting data in a column with condition

$
0
0
When on of the admin clicks an approve button its supposed to add the user_id of the person approving to a field in approval table 

This is the button

     <?php echo anchor('admin/messages/approve/'.$message->id.'', 'Approve', 'class="btn btn-success"'); ?>


This is the approve function in Controller

    public function approve($id) {

    $data  = array(
      'first_approval' =>  $this->session->userdata('user_id')
     );


$this->Message_model->approve($id, $data);


//isset Message
$this->session->set_flashdata('success', 'Your approval was send');

//Redirect
redirect('admin/messages');

}


This is the approve method inside the Model

    public function approve($data) {

       $this->db->select('*');
       $this->db->from('approval');
       $this->db->join('messages', 'messages.id = approval.sms_id');

       $this->db->where('id', 'sms_id');
       $this->db->set('first_approval', $data);
       $this->db->update('approval');
    }


I have sms_id, first_approval, second_approval and third_approval columns in my approval table but for now I'm just testing if I can put session->user_id in the column 'first_approval'

how to dynamically update data

$
0
0
hi all,

I wanted to get dynamically data from the database when i am making a new invoiceif customer exists, then when i type the first few words, 
I wanted the names in the drop down listif the name is not there, then under the same drop down list, there should also be an option to create a new customer.Similarly I wanted the same for adding products in the invoice.Can you help me here.?I am using codeigniter3 with PHP7I have also attached the pics of what i want.

Please help !!

.png   createproduct.png (Size: 24.34 KB / Downloads: 11)

.png   createcompany.png (Size: 20.53 KB / Downloads: 10)

auto_loading model and library problem

$
0
0
Reference from Github: https://github.com/bcit-ci/CodeIgniter/i...-255716662

I have changed the line in autoload.php file. I am trying to call the this model in my controller. This is not working. 
     $autoload['model'] = array("M_functions"=>"function");

If I call this model in the controller manually. It works fine.

     $this->load->model("M_functions","function");


## Error 

`
A PHP Error was encountered

Severity: Notice

Message: Undefined property: Diagnose::$function

Filename: controllers/Diagnose.php

Line Number: 21

Backtrace:

File: /var/www/html/hfs/application/controllers/Diagnose.php
Line: 21
Function: _error_handler

File: /var/www/html/hfs/index.php
Line: 315
Function: require_once
Fatal error: Call to a member function password_generator() on null in /var/www/html/hfs/application/controllers/Diagnose.php on line 21
A PHP Error was encountered

Severity: Error

Message: Call to a member function password_generator() on null

Filename: controllers/Diagnose.php

Line Number: 21

Backtrace:
`

I have function name password_generator() in the M_functions model.  Same thing is happening for libraries also. I have manually load the session, form_validation library. 

###For input library. 

    $autoload['libraries'] = array('database','../core/input','encrypt');

I have  to call the library like this. If I was trying to call without relative path. input library is also not working.

I have CodeIgniter 3.1.0. I have compared my Loader.php file with latest developed branch and 3.1.0 branch file. Both are same. 
someone suggest this[ solution. ](https://github.com/bcit-ci/CodeIgniter/issues/3733)



when I try to autoload the library session.
I have this error.
Unable to locate the specified class: Session.php

Memcached Sessions

$
0
0
So I just upgraded our existing sites to Codeigniter 3 and for the most part I have not had any issues with it. However, we have a very AJAX heavy application on our intranet that has taken a huge performance hit from CI3.

I've converted most of our session data back into normal cookies to take some of the load off, but we're still having performance issues. We're also getting our logs flooded with errors from session data failing to save.

PHP Code:
UnknownFailed to write session data (user). Please verify that the current setting of session.save_path is correct (localhost:11211Unknown 0 

That error gets thrown every AJAX call. I tried adding session_write_close() to certain functions and that made it 10x worse...

Now we are on PHP 5.4, but I'm upgrading it to 5.6 tomorrow with hopes it'll clear up some issues. I've also checked memcached logs in debug mode and it didn't tell me much sadly.

These are the stats from memcached (I can already see issues with the "misses" being quite high):

PHP Code:
STAT pid 22704
STAT uptime 1048142
STAT time 1477501922
STAT version 1.4.4
STAT pointer_size 64
STAT rusage_user 914.320002
STAT rusage_system 2830.748660
STAT curr_connections 12
STAT total_connections 12158032
STAT connection_structures 125
STAT cmd_get 5310707
STAT cmd_set 6077020
STAT cmd_flush 0
STAT get_hits 2451993
STAT get_misses 2858714
STAT delete_misses 193
STAT delete_hits 226226
STAT incr_misses 0
STAT incr_hits 0
STAT decr_misses 0
STAT decr_hits 0
STAT cas_misses 0
STAT cas_hits 0
STAT cas_badval 0
STAT auth_cmds 0
STAT auth_errors 0
STAT bytes_read 2148258516
STAT bytes_written 1242867905
STAT limit_maxbytes 4294967296
STAT accepting_conns 1
STAT listen_disabled_num 0
STAT threads 4
STAT conn_yields 0
STAT bytes 803034
STAT curr_items 4974
STAT total_items 5489053
STAT evictions 0
END 

[Feature] Database table size estimation

$
0
0
When paginating an API for example, it is often crucial to know how many pages you have (or how many rows you have) so you will show the correct amount of pages, show infinite scrolling when needed, etc..

The simplest, DB engine agnostic solution would be:
select("COUNT(1) as c")->from("table")->where()->where()....->where()->group()
(No order, no limit)

This way is very naive, and can take alot of time sometimes.

Feature request:
DB to have:
$this->db->estimate();


Simplest? will execute the prepared query, with no limit and no order
Better? 
- MySQL has an efficient way of calculating, selecting `SQL_CALC_FOUND_ROWS`
- Postgre has it's own solution
and I guess every DB has it's own.

So the flow would be something like:
$this->db->select("something")->from("somewhere")->where("some", "value")->order_by('key', 'asc')->limit(10, 10)->estimate();
$query = $this->db->get();
$result = $query->result();
$estimation = $query->estimation();


I think it is very functional.

If my explaination is not great, please et me know how to fix it Smile

Blurry Logo

$
0
0
This issue relates to size and CSS, I am using Twitter Bootstrap for my front-end. I've uploaded a logo (709x134) and this is what's in my style.css file:

Code:
.navbar-brand {
   float: left;
   padding: 12px 15px;
   font-size: 19px;
   line-height: 21px;
   height: 62px;
   max-width: 220px;
   display: table;
}

Should I change anything in here? I've already increased the width by 20 pixels. The logo looks better in Firefox than in Chrome.

Thanks!

Encrypt important data

$
0
0
Hello, all good guys?

Guys, I'm developing a CMS and would like opnion of you, what is the best and safest method to encrypt important data such as passwords and other personal informations?

I'm using the recently launched IC 3.1.1

Thank you!

[split] URI routing in 3.1.1

$
0
0
I found two bugs in URI Routing in version 3.1.1, in version 3.1.0 was no such!

First. If named function same name controller.
Example:

class Bug extends CI_Controller
{

   function bug()
   {
       exit(1);
   }

}
Link http://site/bug/bug does not work!

Second. If add to existing function any URI segment in URL without routes.php not shown error 404.
Example:

http://site/bug/bug/dawdad
http://site/bug/bug/3123
http://site/bug/bug/dawdad/3123/dad/3123/...

Community Auth Login Problems

$
0
0
Im currently running into some problems setting Community Auth up in CodeIgniter i have managed to set it up and cant seem to understand what is causing the problem of me not being able to be logged in all the time.

According to the AJAX login form im getting the right tokens from the form, they are submitted and it gives me a correct callbac. But it cant seem to keep me logged in.

Code:
DEBUG - 2016-10-26 20:35:40 --> UTF-8 Support Enabled
DEBUG - 2016-10-26 20:35:40 --> Global POST, GET and COOKIE data sanitized
DEBUG - 2016-10-26 20:35:40 --> Config file loaded: C:\Users\Staffan\Dropbox\xampp\htdocs\tinderbox\application\third_party/community_auth/config/db_tables.php
DEBUG - 2016-10-26 20:35:40 --> Config file loaded: C:\Users\Staffan\Dropbox\xampp\htdocs\tinderbox\application\third_party/community_auth/config/authentication.php
DEBUG - 2016-10-26 20:35:40 --> Session: "sess_save_path" is empty; using "session.save_path" value from php.ini.
DEBUG - 2016-10-26 20:35:40 --> Encryption: Auto-configured driver 'openssl'.
DEBUG - 2016-10-26 20:35:40 -->
string     = user
password   = USer1234
form_token = 6beaa401
token_jar  = ["5d6bde62","6beaa401"]
DEBUG - 2016-10-26 20:35:40 --> Config file loaded: C:\Users\Staffan\Dropbox\xampp\htdocs\tinderbox\application\third_party/community_auth/config/examples/password_strength.php
DEBUG - 2016-10-26 20:35:40 --> Config file loaded: C:\Users\Staffan\Dropbox\xampp\htdocs\tinderbox\application\third_party/community_auth/config/form_validation/examples/login.php
DEBUG - 2016-10-26 20:35:41 -->
user is banned             = no
password in database       = $2y$11$MwtJlO8o2Ho1vWFxax62OuJngskSjSfGx./v2fuL1hjbmGDypnF2a
supplied password match    =
required level or role     = 1
auth level in database     = 9
auth level equivalant role = admin
DEBUG - 2016-10-26 20:35:41 --> Total execution time: 0.6556
DEBUG - 2016-10-26 20:35:46 --> UTF-8 Support Enabled
DEBUG - 2016-10-26 20:35:47 --> Global POST, GET and COOKIE data sanitized
DEBUG - 2016-10-26 20:35:47 --> Config file loaded: C:\Users\Staffan\Dropbox\xampp\htdocs\tinderbox\application\third_party/community_auth/config/db_tables.php
DEBUG - 2016-10-26 20:35:47 --> Config file loaded: C:\Users\Staffan\Dropbox\xampp\htdocs\tinderbox\application\third_party/community_auth/config/authentication.php
DEBUG - 2016-10-26 20:35:47 --> Session: "sess_save_path" is empty; using "session.save_path" value from php.ini.
DEBUG - 2016-10-26 20:35:47 --> Encryption: Auto-configured driver 'openssl'.
DEBUG - 2016-10-26 20:35:47 -->
string     = user
password   = User1234
form_token = b26f70f9
token_jar  = ["b26f70f9"]
DEBUG - 2016-10-26 20:35:47 --> Config file loaded: C:\Users\Staffan\Dropbox\xampp\htdocs\tinderbox\application\third_party/community_auth/config/examples/password_strength.php
DEBUG - 2016-10-26 20:35:47 --> Config file loaded: C:\Users\Staffan\Dropbox\xampp\htdocs\tinderbox\application\third_party/community_auth/config/form_validation/examples/login.php
DEBUG - 2016-10-26 20:35:47 --> Total execution time: 0.2476
DEBUG - 2016-10-26 20:35:47 --> UTF-8 Support Enabled
DEBUG - 2016-10-26 20:35:47 --> Global POST, GET and COOKIE data sanitized
DEBUG - 2016-10-26 20:35:47 --> Config file loaded: C:\Users\Staffan\Dropbox\xampp\htdocs\tinderbox\application\third_party/community_auth/config/db_tables.php
DEBUG - 2016-10-26 20:35:47 --> Config file loaded: C:\Users\Staffan\Dropbox\xampp\htdocs\tinderbox\application\third_party/community_auth/config/authentication.php
DEBUG - 2016-10-26 20:35:47 --> Session: "sess_save_path" is empty; using "session.save_path" value from php.ini.
DEBUG - 2016-10-26 20:35:47 --> Encryption: Auto-configured driver 'openssl'.
DEBUG - 2016-10-26 20:35:47 --> Total execution time: 0.0758
DEBUG - 2016-10-26 20:35:47 --> UTF-8 Support Enabled
DEBUG - 2016-10-26 20:35:47 --> Global POST, GET and COOKIE data sanitized
DEBUG - 2016-10-26 20:35:47 --> Config file loaded: C:\Users\Staffan\Dropbox\xampp\htdocs\tinderbox\application\third_party/community_auth/config/db_tables.php
DEBUG - 2016-10-26 20:35:47 --> Config file loaded: C:\Users\Staffan\Dropbox\xampp\htdocs\tinderbox\application\third_party/community_auth/config/authentication.php
DEBUG - 2016-10-26 20:35:47 --> Session: "sess_save_path" is empty; using "session.save_path" value from php.ini.
DEBUG - 2016-10-26 20:35:47 --> Encryption: Auto-configured driver 'openssl'.
DEBUG - 2016-10-26 20:35:47 --> Total execution time: 0.0760

This is my log file and according to that everything seems fine :/

Im using Xampp on a localhost

[split] Session bug in 3.1.1

$
0
0
Session bug in 3.1.1

My login system stopped work...
I replace system/libraries/Session from 3.1.0 and worked again

using database driver

Custom routes not working

$
0
0
I'm trying to build a custom route. I'd like to map /account-overview to the AccountOverview class method processRequest() so I entered this as my /application/config/routes.php:


$route['default_controller'] = 'accountOverview/processRequest';   // just to test the controller when it would not come up
$route['404_override'] = '';
$route['translate_uri_dashes'] = FALSE;
$route['account-overview'] = 'accountOverview/processRequest';


The page comes up when I enter just localhost - so the page itself is functional but when I try the /account-overview URL I get NOT FOUND. I've tried adding a second part to the URL like /account-overview/page and mapping that but all I get is 404 NOT FOUND. I even tried using /accountOverview/processRequest and still got NOT FOUND. What is wrong? This is the most basic function of a framework if this doesn't work then I can't use codeIgniter. How can I execute class AccountOverview method processRequest  ??? Ideally with a friendly URL ???

I've checked and there are no .htaccess files anywhere that could mess with the URL. I do not have a _remap function anywhere. There's nothing in the log files. How do I debug the framework itself?The bug would be _parse_routes of /system/core/Router.php - I can start debugging from there. Something tells me i'm going to extend yet another /system/core class. I'd prefer not to. Any ideas?

Session Issue On Subdomain

$
0
0
Hi ,

I'm facing session problem on subdomain.

During login i have stored session data in variable. If i am printing session in this login controller then it is displaying session variables properly.

If i am redirecting to another controller after successful login then it is displaying nothing on print of session.
my url is here cportal.peerallylaw.com

Could you please help me to figure out the issue?

[split] session upoload progress (CodeIgniter 3.1.1 Released)

LINGUO: CodeIgniter Language Frontend Editor

$
0
0
Hi everyone,

Just wanna show you a small library that I've developed for CodeIgniter. It generates a small UI to create/edit/update/delete language files and allows to clone/sync language files and strings from one language to another.

You can check it on my github repo:

https://github.com/destinomultimedia/ci_linguo
Viewing all 14082 articles
Browse latest View live


<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>