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

Have problems with displaying data from database

$
0
0
Can someone help me , I'm still new with CodeIgniter , I have problems in displaying data from database in another page because I am confused with controller either I should put on the function on default controller or made a new one, and if I made a new one, I don't know how to call the function to display the data from database on another page. 

this is my default controller : 

PHP Code:
<?php 

class Pages extends CI_Controller{
 
   public function __construct(){
 
       parent::__construct();
 
       $this->load->helper('url');
 
   }


    public function 
view($page 'home')
    {
        if ( ! 
file_exists(APPPATH.'/views/pages/'.$page.'.php'))
    {
        
// Whoops, we don't have a page for that!
        
show_404();
    }

    
$data['title'] = ucfirst($page); // Capitalize the first letter

    
$this->load->view('templates/header'$data);
    
$this->load->view('pages/'.$page$data);
    
$this->load->view('templates/footer'$data);

    }

public function 
GetAll(){
 
   $data['all_data'] = $this->exhibitions_model->selectAllData();
 
   $this->load->view('exhibitons'$data);
}

}

?>

and this is my model : 

PHP Code:
<?php
       
public function selectAllData() {
 
       $query $this->db->get('omg_events');
 
       return $query->result();
 
   }
?>


and the page that I want to display data from the database :

Code:
<head>
   <link href="<?php echo base_url() ?>css/about.css" rel="stylesheet">
</head>

<!--==========================
   Intro Section
 ============================-->

 <section id="intro">
   <div class="intro-container">
     <div id="introCarousel" class="carousel  slide carousel-fade" data-ride="carousel">


       <div class="carousel-inner" role="listbox">

         <div class="carousel-item active">
            <div class="carousel-background"><img src="<?php echo base_url() ?>img/events.jpg" alt=""></div>
           <div class="carousel-container">
             <div class="carousel-content">
               <h2>Exhibitions</h2>
             </div>
           </div>
         </div>

     </div>
   </div>
 </section><!-- #intro -->

 <main id="main">

   
   <!--==========================
     Team Section
   ============================-->
   <section id="team">
     <div class="container">
       <div class="section-header wow fadeInUp">
         

       <div class="album py-5 bg-light">
   <div class="container">

      <div class="section-header">
         <h3>EXHIBITIONS ROADSHOWS & SEMINAR</h3>
         <p></p>
       </div>

<table class="table table-hover">

 <thead>
   <tr>
   

   </tr>
 </thead>
 <tbody>
<?php

   foreach ($all_data as $show):
       ?>

   <tr>
     <th scope="row"><?php echo $show->event_id?></th>
     <td width="10%"><?php echo $show->name?></td>
     <td width="10%"><?php echo $show->address?></td>
     <td></td>
     <td></td>
     <td width="15%""><a href="">Send Enquiry</a></td>
   </tr>
  <?php

   endforeach;
   ?>
 </tbody>
</table>
     
     
     </div>

   </section><!-- #team -->


 
 </main>

Upgrading from 3.1.5 to 3.1.6

$
0
0
Hallo everyone, I am Owino from Kenya, East Africa.

I have been using CI for a while now, but I am still stuck at version 3.1.5.

I am sure I have never understood the step 2 at https://www.codeigniter.com/user_guide/i...e_316.html

What I get after I am done with step 1 is

Fatal error: Allowed memory size of 134217728 bytes exhausted (tried to allocate 262144 bytes) in /var/www/html/mysystem/system/core/Loader.php on line 218

Fatal error: Allowed memory size of 134217728 bytes exhausted (tried to allocate 262144 bytes) in Unknown on line 0

I need your help

Severity: error --> Exception: Call to a member function quote() ...

$
0
0
I sometime get the following error in the CodeIgniter error log files :


Code:
ERROR - 2019-01-21 01:12:35 --> Unable to connect to the database
ERROR - 2019-01-21 01:12:36 --> Severity: error --> Exception: Call to a member function quote() on boolean mysite/system/database/drivers/pdo/pdo_driver.php 234


It rarely happens, but happens sometimes. I guess that if the PDO driver can't connect to the database, there is no retry. So the page will display an error.


I reported a bug : https://github.com/bcit-ci/CodeIgniter/issues/5682

But apparently, this is not a bug... Any idea ?

Need verbose logging in system/core/Model.php for "Cannot access empty property" bug

$
0
0
Please implement something along the following into system/core/Model.php. In large programs it can be a pain and next to impossible using php error logs alone to track down an empty property call. This will trace back to the exact line trying to access an empty key. Or at least add something other than a comment stating we have a typo somewhere. Thanks.

CI in the NEWS

using Model throws error

$
0
0
i try to use the model function, and getting this error:

Code:
Fatal error: Class 'CodeIgniter\Model' not found in C:\xampp\htdocs\pna_lists\application\models\TasksModel.php on line 7
A PHP Error was encountered
Severity: Error

Message: Class 'CodeIgniter\Model' not found

Filename: models/TasksModel.php

Line Number: 7

Backtrace:

My Model:
PHP Code:
<?php
namespace App\Models;

use 
CodeIgniter\Model;

class 
TasksModel extends Model
{
 
       protected $table      'tasks';




My Controller
PHP Code:
<?php
defined
('BASEPATH') OR exit('No direct script access allowed');
use 
App\Models\TasksModel;
class 
Tasks extends NA_Controller {
    public function 
create()
    {
        
$model = new TasksModel();
        
$tasks $taskModel->findAll();
        
print_r($tasks);
    }


Can u see my mistake?

Thanks for ya help!

Codeigniter database connection error

$
0
0
I have a database error so guys can you all help me overcome this problem.

this is my database.php file

$active_group = 'default';
$query_builder = TRUE;

$db['default'] = array(
'dsn' => '',
'hostname' => 'localhost',
'username' => 'root',
'password' => '',
'database' => 'electroshop',
'dbdriver' => 'mysqli',
'dbprefix' => '',
'pconnect' => FALSE,
'db_debug' => (ENVIRONMENT !== 'production'),
'cache_on' => FALSE,
'cachedir' => '',
'char_set' => 'utf8',
'dbcollat' => 'utf8_general_ci',
'swap_pre' => '',
'encrypt' => FALSE,
'compress' => FALSE,
'stricton' => FALSE,
'failover' => array(),
'save_queries' => TRUE
);

And I have inserted a image of my error also please look into it all give and answer.
And I'm using the codeigniter version 3.1.8
And I'm using the php version 7.2.5  

please guys help me find the problem.

.png   122334444.PNG (Size: 26.99 KB / Downloads: 29)

CI4 Model or Entity with Relation between two tables

$
0
0
Hello Guys,

i love the new style of models. But i think one of needed thing is to set relation between to tables(models).


When u have two tables (or more) like this:
table1
id
users_id
content

users
id
username

So when i make a model on "table1" it should be possible to join table "users". This was possible with grocery_crud. Is this already possible and i couldnt find it?

I think the moste time you will have some relation between two tables or more. I know i could do it by $afterFind, but it wouldnt the performance would be really bad...

Hope i could explain, what i want.

Thanks for your Help

[split] Unable to load session

$
0
0
(01-16-2019, 11:04 AM)jlp Wrote: CodeIgniter 3.1.10 was released today, with some changes and some bug fixes.

Changes: added ‘ssl_verify’ support to the ‘pdo/mysql’ Database driver; renamed Inflector Helper function 'is_countable()' to 'word_is_countable()' due to the former colliding with one introduced in PHP 7.3.0

Bug fixes: Database library, caching, forge, & mysqli driver; form validation, session & XML-RPC libraries; captcha helper

This is recommended for all users of version 3. Download v3.1.10 now, and we encourage you to read the changelog, and to check the directions for upgrading from a previous version.

hii everybody, im sorry if my english language is bad, i have a problem on CI 3 this the error code Unable to locate the specified class: Session.php , I think I've loaded the session library on autoload but why the error still appear ? please help me


Code:
//this is autoload in config/autoload.php
$autoload['libraries'] = array('database','session');


Code:
// This is my Auth controller
class Auth extends CI_Controller
{

    public function __construct()
    {
        parent::__construct();
        $this->load->model('Auth_model');
        // $this->load->library('session');
    }
    public function login()
    {
        $username = $this->input->post('username');
        $password = $this->input->post('password');

        $data['user']     =  $this->Auth_model->getDataUser($username);
        $data['row']     = $this->Auth_model->getRowUser($username);
        $passhash         = $data['user']['password'];
        $status         = $data['user']['status'];
        $level             = $data['user']['level'];

            if ( $data['row'] == 1 ){ //CHECK JUMLAH USER
                if ( password_verify($password, $passhash ) ) { //CHECK VALIDASI PASSWORD
                    if ( $status == 'on' ){ // CHECK STATUS USER
                        if ( $level == 'customer' ){ // JIKA USER CUSTOMER
                            $data_session = array(
                                'username' => $data['user']['username'],
                                'user_id' => $data['user']['user_id'],
                                'status_login' => "yes"
                            );
                            $this->session->set_uerdata($data_session);
                            var_dump($this->session->userdata());
                            redirect('Home');
                        }elseif( $level == 'admin' ){ // JIKA USER ADMIN
                            $data_session = array(
                                'username' => $data['user']['username'],
                                'user_id' => $data['user']['user_id'],
                                'id_barbershop' => $data['user']['id_barbershop'],
                                'status_login' => "yes"
                            );
                            $this->session->set_uerdata($data_session);
                            redirect('Admin');
                        }elseif ( $level == 'adminDev' ){ // JIKA USER ADMINDEV
                            $data_session = array(
                                'username' => $data['user']['username'],
                                'user_id' => $data['user']['user_id'],
                                'status_login' => "yes"
                            );
                            $this->session->set_uerdata($data_session);
                            redirect('AdminDev');
                        }
                    }elseif ( $status == 'off' ){ // JIKA USER OFF
                        echo "yahh aku OFF nih";
                    }
                }else{ // JIKA PASSWORD USER SALAH
                    echo "SALAH";
                }
            }else{ // JIKA USER TIDAK ADA
                echo "NO";
            }
    }
    
    public function logout(){
        $this->session->sess_destroy();
        redirect('Home/login');
    }

}


Code:
//this is my Auth_model
class Auth_model extends CI_Controller
{
    public function getDataUser()
    {
        $username = $this->input->post('username' , true);
        $query =  $this->db->get_where('users' , ['username' => $username ])->row_array();
        return $query;
    }

    public function getRowUser()
    {
        $username = $this->input->post('username' , true);
        // $query = $this->db->query("SELECT * FROM users ");
        return $this->db->where(['username' => $username ])->from("users")->count_all_results();;
    }
}

Escaping broke query

$
0
0
hey, right after the escaping update, some queries and models dont work anymore.

1. problem : first query after session is loaded ( DatabaseHandler )

PHP Code:
Services::session()->start();
Database::connect()->query'SELECT A FROM B WHERE C=?', [ '2' ] ); 

2. problem : model stores escaping info twice
PHP Code:
class ExampleEntity extends Entity
{
    protected 
$id;
    protected 
$timestamp;
}
class 
ExampleModel extends Model
{
    protected 
$table         'sessions';
    protected 
$primaryKey        'id';
    protected 
$returnType        '\App\Models\ExampleEntity';
}

$Model  new ExampleModel();
$Entity $Model->find'0' );
$New $Entity === null;
if( 
$New $Entity = new ExampleEntity( ['id' => '0' ] );
Database::connect()->setEscapeFlagstrue );
$Entity->timestamp 0;
if( 
$New $Model->protect(false)->insert$Entityfalse );
else 
$Model->protect(false)->update'0'$Entity ); 

insert & update throw exception

-> my current workaround is to disable escaping at all ( before & after every query )
-> but cant use it in production without escaping -> need to wait for fix

Pagination not working

$
0
0
I am making pagination for my page because of too many data from the database, I try an online tutorial, I can show the data from the database, but when I click next or second page on the pagination, it didn't work. 

this is my controller : 

PHP Code:
<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');

class 
Exhibitions extends CI_Controller {
 
   
    function __construct
() {
 
       parent::__construct();
 
       //load pagination library
 
       $this->load->library('pagination');
 
       //load post model
 
       $this->load->model('exhibitions_model');
 
       //per page limit
 
       $this->perPage 5;
 
   }
 
   
    public 
function index(){
 
       $data = array();
 
       
        
//get rows count
 
       $conditions['returnType'] = 'count';
 
       $totalRec $this->exhibitions_model->getRows($conditions);
 
       
        
//pagination config
 
       $config['base_url'   base_url().'pages/exhibitions/';
 
       $config['uri_segment'] = 3;
 
       $config['total_rows' $totalRec;
 
       $config['per_page'   $this->perPage;
 
       
        
//styling
 
       $config['num_tag_open'] = '<li>';
 
       $config['num_tag_close'] = '</li>';
 
       $config['cur_tag_open'] = '<li class="active"><a href="javascript:void(0);">';
 
       $config['cur_tag_close'] = '</a></li>';
 
       $config['next_link'] = 'Next';
 
       $config['prev_link'] = 'Prev';
 
       $config['next_tag_open'] = '<li class="pg-next">';
 
       $config['next_tag_close'] = '</li>';
 
       $config['prev_tag_open'] = '<li class="pg-prev">';
 
       $config['prev_tag_close'] = '</li>';
 
       $config['first_tag_open'] = '<li>';
 
       $config['first_tag_close'] = '</li>';
 
       $config['last_tag_open'] = '<li>';
 
       $config['last_tag_close'] = '</li>';
 
       
        
//initialize pagination library
 
       $this->pagination->initialize($config);
 
       
        
//define offset
 
       $page $this->uri->segment(3);
 
       $offset = !$page?0:$page;
 
       
        
//get rows
 
       $conditions['returnType'] = '';
 
       $conditions['start'] = $offset;
 
       $conditions['limit'] = $this->perPage;
 
       $data['omg_event'] = $this->exhibitions_model->getRows($conditions);
 
       
        
//load the list page view
 
       
       $this
->load->view('templates/header'$data);
 
     $this->load->view('pages/exhibitions'$data);
 
      $this->load->view('templates/footer');
 
   }
 
   


My model : 

PHP Code:
<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');

class 
Exhibitions_model extends CI_Model{
 
   /*
     * Get posts
     */
 
   function getRows($params = array()){
 
       $this->db->select('*');
 
       $this->db->from('omg_event');
 
       if(array_key_exists("event_id",$params)){
 
           $this->db->where('event_id',$params['event_id']);
 
           $query $this->db->get();
 
           $result $query->row_array();
 
       }else{
 
           //set start and limit
 
           if(array_key_exists("start",$params) && array_key_exists("limit",$params)){
 
               $this->db->limit($params['limit'],$params['start']);
 
           }elseif(!array_key_exists("start",$params) && array_key_exists("limit",$params)){
 
               $this->db->limit($params['limit']);
 
           }
 
           
            if
(array_key_exists("returnType",$params) && $params['returnType'] == 'count'){
 
               $result $this->db->count_all_results();
 
           }else{
 
               $query $this->db->get();
 
               $result = ($query->num_rows() > 0)?$query->result_array():FALSE;
 
           }
 
       }

 
       //return fetched data
 
       return $result;
 
   }
}
?>

and my view page : 

PHP Code:
<head>
 
   <link href="<?php echo base_url() ?>css/about.css" rel="stylesheet">
</
head>

<!--==========================
 
   Intro Section
  
============================-->

 
 <section id="intro">
 
   <div class="intro-container">
 
     <div id="introCarousel" class="carousel  slide carousel-fade" data-ride="carousel">


 
       <div class="carousel-inner" role="listbox">

 
         <div class="carousel-item active">
 
            <div class="carousel-background"><img src="<?php echo base_url() ?>img/events.jpg" alt=""></div>
 
           <div class="carousel-container">
 
             <div class="carousel-content">
 
               <h2>Exhibitions</h2>
 
             </div>
 
           </div>
 
         </div>

 
     </div>
 
   </div>
 
 </section><!-- #intro -->

 
 <main id="main">

 
    
    
<!--==========================
 
     Team Section
    
============================-->
 
   <section id="team">
 
     <div class="container">
 
       <div class="section-header wow fadeInUp">
 
         

        
<div class="album py-5 bg-light">
 
   <div class="container">

 
      <div class="section-header">
 
         <h3>EXHIBITIONS ROADSHOWS SEMINAR</h3>
 
         <p></p>
 
       </div>

<
table class="table table-hover">
 
 <?php if(!empty($omg_event)): foreach($omg_event as $post): ?>
  <thead>
    <tr>
     

    </tr>
  </thead>
  <tbody>


    <tr>
      <th scope="row"><?php echo $post['name']; ?></th>
      <td width="10%"><?php echo $post['address']; ?></td>
      <td width="10%"><?php echo $post['name']; ?></td>
      <td></td>
      <td></td>
      <td width="15%""><a href="">Send Enquiry</a></td>
    </tr>
  <?php endforeach; else: ?>
                <tr><td colspan="3">Post(s) not found......</td></tr>
                <?php endif; ?>
  </tbody>
  
</table>
   <ul class="pagination pull-right">
    <?php echo $this->pagination->create_links(); ?>
</ul>    
      
      </div>

    </section><!-- #team -->


   
  </main> 

Form validation with BoostrapValidator

$
0
0
Hi All,

I have created a form like:


Code:
<form action="<to_controller_method>" method="post" id="form">
 
I'm using BootstrapValidator (of course with Bootstrap 3) to validate some fields in this form.

Although I have managed to trigger the validation errors upon a field input error, however when I push the submit button (with no field errors) the form can't be submitted (submit button is being disabled). However, when I update a validated field the form is submitted.

I wonder why the form can't be submitted when the submit button is being pushed for the first time.

[split] Session problem

$
0
0
(01-16-2019, 11:04 AM)jlp Wrote: CodeIgniter 3.1.10 was released today, with some changes and some bug fixes.

Changes: added ‘ssl_verify’ support to the ‘pdo/mysql’ Database driver; renamed Inflector Helper function 'is_countable()' to 'word_is_countable()' due to the former colliding with one introduced in PHP 7.3.0

Bug fixes: Database library, caching, forge, & mysqli driver; form validation, session & XML-RPC libraries; captcha helper

This is recommended for all users of version 3. Download v3.1.10 now, and we encourage you to read the changelog, and to check the directions for upgrading from a previous version.

Fatal error: Class CI_Session_database_driver contains 1 abstract method and must therefore be declared abstract or implement the remaining methods (SessionHandlerInterface::open) in C:\xampp\htdocs\mobooklet\system\libraries\Session\drivers\Session_database_driver.php on line 49
error is coming what i'm do now when  i restart the apache server at time will be working after few mins like(3 to 4 mins) not working same problem can any one tell to the answer for this i' using xampp v3.2.2 php 7 can any one replay

CodeIgniter 4.0.0-alpha.5 Released

$
0
0
CodeIgniter-4.0.0-alpha.5 launches today [Image: smile.gif]

This is a pre-release of 4.0.0. It is not suitable for production!

Release highlights:
  • updated PHP dependency to 7.2
  • lots of bug fixes, especially for the database support
  • code coverage is at 77% ... getting ever closer to our target of 80% Smile
  • new feature branches have been created for the email and queue modules, so they don't impact the release of 4.0.0
  • dropped several language messages that were unused (eg Migrations.missingTable) and added some new (eg Migrations.invalidType)
  • provided filters (CSRF, Honeypot, DebugToolbar) have been moved from app/Filters/ to system/Filters/
  • revisited the installation and tutorial sections of the user guide
     
The app-starter distribution has improved path handling, too Smile
 
Check the changelog for details, and the installation writeup for further directions.

We hope this will be the last alpha, and that the next pre-release will be our first beta ... fingers crossed!
Thank you to the community for stepping up to help make this the best PHP framework!

Do NOT post support questions or feature requests in response to this thread - those will be deleted. We are trying to make the best of the limited resources that we have!

Thank you, and ENJOY!

Htaccess, subdomains & subfolders ?

$
0
0
Hi guys,

Looking to implement some subfolders, where each have a Codeigniter FW.
All my subdomains goes to the "principal folder" and a .htaccess redirect there to the good folder, like that : 
Code:
Options +FollowSymLinks
RewriteEngine On
RewriteCond %{HTTP_HOST} ^(.*)\.apps\.xxx\.io
RewriteRule ^(.*)$ http://app.xxx.io/_deployed/%1/index.php/$1 [P,L]


Example : 
- app1.apps.xxx.io
- app2.apps.xxx.io
- etc...

In each "subfolder", I have another .htaccess for my codeigniter FW, but I think this implementation is not good :
Code:
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php/$1 [L]


Anyone can save me ?  Big Grin

Thanks for your help.

Fresh CI Form Builder

$
0
0
Hi guys,

I developed a little "MVC form builder" for CI, you can try it here : https://github.com/AdrienV/BuildIgniter

Don't know if it can help or not.

In few click you generate :
- controller
- model
- view
- SQL

The builder can create your files automatically, your DB as well.

Kiss.  Heart

google cloud app engine storage

$
0
0
Hello , i am hosting a code igniter based application on google cloud app engine . Everything is working fine now i have a task to allow our users to upload a file such as images , videos etc . How cam i accomplish the task because the normal code igniter upload function is not working . Kindly help me out

fetch values not correctly?

$
0
0
Code:
I want to store checkbox value,two textbox value in array.

public function valinsert()
{
$certids = $this->input->post('certid');  
$nocs = $this->input->post('noc1');   
$amtt = $this->input->post('txt');

$result = array();
  foreach ($certids as $index=>$certid) 
  {
     $result[] = $certid . '_' . $nocs[$index] .'_' . $amtt[$index];
  }

but it displays
Code:
Array
(
   [0] => 1_2_1700
   [1] => 2_3_900
   [2] => 3_0_0
   [3] => 4_0_0
   [4] => 5_3_900
   [5] => 6_3_900
   [6] => 7_3_900
)
how to display those checked checkbox with corresponding row details. some times its working but most of the time return "o". how to solve this

PHP Micro & Router Framework Benchmark

session lock problem

$
0
0
i am using ci 3.1.8 and mysql.
mariadb version is 10.3.12 .
i have multiply users, and sometimes query can return long , than all sessions are locked.
i dont want to locked all sessions,i  just want to lock the session which supposed to be
how can i solve this problem
thanks for suggestions.
Viewing all 14343 articles
Browse latest View live


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