Welcome, Guest
You have to register before you can post on our site.



Search Forums

(Advanced Search)

Forum Statistics
» Members: 8,927
» Latest member: dushee
» Forum threads: 66,205
» Forum posts: 415,477

Full Statistics

Latest Threads
How to create resful web ...
Forum: Learn More
7 hours ago
» Replies: 0   » Views: 44
download remote file wit...
Forum: General Help
11 hours ago
» Replies: 2   » Views: 61
Query Caching or NOT?!!!
Forum: Best Practices
11 hours ago
» Replies: 4   » Views: 152
Fetch data in a selected ...
Forum: CodeIgniter 3.x
Today, 09:56 AM
» Replies: 8   » Views: 216
JWT for APIs
Forum: Lounge
Today, 09:37 AM
» Replies: 4   » Views: 203
Common function
Forum: General Help
Today, 08:39 AM
» Replies: 1   » Views: 53
Message before redirect
Forum: General Help
Today, 08:30 AM
» Replies: 2   » Views: 45
Make sure show result at ...
Forum: General Help
Today, 05:51 AM
» Replies: 2   » Views: 52
php mailer
Forum: General Help
Today, 04:55 AM
» Replies: 2   » Views: 56
CodeIgniter Filipino Comm...
Forum: Regional User Groups
Yesterday, 08:28 PM
» Replies: 21   » Views: 7,145

  Remove index.php without .htaccess
Posted by: krystian2160 - 06-21-2017, 07:21 AM - Forum: CodeIgniter 4 Feature Requests - Replies (3)

It would be great to have no index.php in address without needing of .htaccess file with

RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php/$1 [L]

I don't like it.  Confused

  Query Caching or NOT?!!!
Posted by: pb.sajjad - 06-21-2017, 07:13 AM - Forum: Best Practices - Replies (4)

Hi to all developers...
I'm using last version of CI, created a blog system (some posts, series, commenting, payment link, login,... and more) and want run it on a shared host.

In order to get best performance, I want to use CACHE. As you an option is to cache whole page, but I think it is not good (at least for me!). Another option is Query Caching, that I think it's good (but not sure!). Instead to get a post or other thing from database (for second attempt and up), it read from generated files. And when I update a post, I could delete files in order to regenerating.
(I test output profiler to see loading time and memory usage, loading time is different and same to when do not use query caching, memory usage is a little more.)

My Questions:
What's your opinion about this option? What are advantages/disadvantages? How could I handle this issue in best way? What about other options (like libraries)? And any guide to reach best performance for CI app.

thanks to all (especially experts!) Smile

  I have a problem
Posted by: weserve - 06-21-2017, 06:30 AM - Forum: General Help - Replies (2)

i have error ==> Parse error: syntax error, unexpected T_CONST in /home/weserveint/domains/weserve.in.th/public_html/WeShop/system/core/CodeIgniter.php on line 58

help me pls. 

remark ==> version 3.1.4  up

  how to use order by codeigniter
Posted by: kayinja.denis - 06-21-2017, 03:58 AM - Forum: General Help - Replies (8)

am trying to use order by but i don't get all the results in table.
i have payment table 

          paymentid|academicID| studentID| invoiceID| amount
             1     |     1    |     1    |     1    |   2000  
             1     |     1    |     1    |     2    |    300  
             1     |     1    |     1    |     1    |     5  
             1     |     1    |     1    |     3    |    600
             1     |     1    |     1    |     3    |     10 

 and i have these two scripts
PHP Code:
function get_order_by($array=NULL) {
       if($array != NULL) {
           $query $this->db->get();
           return $query->result();
       } else {
           $query $this->db->get();
           return $query->result();

PHP Code:
function joide($array$value$key=NULL) {
   $returnArray = array();
   if(count($array)) {
       foreach ($array as $item) {
           if($key != NULL) {
               $returnArray[$item->$key] = strtolower($value) == 'obj' $item $item->$value;
           } else {
               $returnArray[] = $item->$value;
   return $returnArray;

PHP Code:
function get_order_by_amount($array=NULL) {
       $query parent::get_order_by($array);
       return $query;


PHP Code:
$payments joide($this->amount_m->get_order_by_amount(['academicID' => $academicID]), 'obj''invoiceID');

$this->data['amount'] = $payments

so when i run  <?php dd($mummy) ?> i don't get all the results,  i mean it won't get the amount = 3 and 10 where invoiceid =1 and 3 respectively but it returns  the 2000, 3000 and 600, it seems it doesn't return the amount where invoiceID is the same like for 1 and 3

  Model accessing other Models - best practice
Posted by: CINewb - 06-21-2017, 03:34 AM - Forum: Best Practices - Replies (2)

What I wanted to find out is the best practice approach to a model accessing other models.  I've done some research and there doesn't seem to be a general consensus as to whether a model should be able to access other models.  Some people say if the models are "related" then it's fine, other people say models shouldn't talk to other models and such communication should be directed through a controller.  The latter is the approach I took until recently, but then my controllers were becoming "fat" which people say is also bad.

Here's an example of a controller which displays a product.  A product can have an image, with images also being a model of their own (since images can relate to not just products but also other entities):

PHP Code:
class Product extends CI_Controller {

   public function index($product_code null) {

       // Get the product model
        $product $this->product_model->get($product_code);

        if ($product) {
           // Get the product's image
            $product['image'] = $this->image_model->get($product_code"product");

           // Display the product
        } else {
            // Display 404 error

However, this is a fairly basic example.  In reality a product might have an image, a set of attributes, a set of bullet points, a list of related products and some custom fields.  Some of these might be their own models, others might be part of the product model.  In any case, my controller now looks like this:

PHP Code:
class Product extends CI_Controller {

    public function index($product_code null) {

       // Get the product model
        $product $this->product_model->get($product_code);

        if ($product) {

           // Get the product's image
            $product['image'] = $this->image_model->get($product_code"product");

           // Get the product's custom fields
            $product['custom_fields'] = $this->customfield_model->get_custom_fields($product_code"product");

           // Get the product's attributes
            $product['attributes'] = $this->product_model->get_attributes($product_code);

           // Get the product's bullet points
            $product['bullets'] = $this->product_model->get_bullets($product_code);

           // Get the product's related products
            $product['related_products'] = $this->product_model->get_related_products($product_code);

           // Display the product
        } else {
            // Display 404 error

Whilst this is OK I have to make a lot of different calls to various models whenever I want to fetch a product, and the controllers get quite cluttered.

An alternative approach I've taken recently is for the product model to have access to all of the associated models, and to pass in a set of arguments to determine which elements I want to get.  This means I don't need to query sub-tables and other models unnecessarily if I only wanted to get, say the product name and nothing else:

PHP Code:
class Product extends CI_Controller {

    public function index($product_code null) {

       // Arguments specifying which product details we want to fetch
        $args = array(
            'fields'           => array('product_name''product_description'), // Get product_name and product_description fields
            'image'            => true// Get the product's image
            'custom_fields'    => true// Get the product's custom fields
            'attributes'       => false// Don't bother getting attributes on this occasion
            'bullets'          => true// Get product's bullet points
            'related_products' => true// Get product's related products

       // Get the product based on specified arguments
        $product $this->product_model->get($product_code$args);

       // Display the product
        if ($product) {
        } else {
            // Display 404 error

I realise there is no right or wrong answer, but I was looking for some guidance as to the best way of handling this.  The only downside I can see with the final example is that models have to load each other and then become dependent on each other.

The disadvantage with the first and second example is that the controllers become quite cluttered - you can't get a complete product with a single call to a model.  You also have to remember which models to query rather than just passing in a bunch of arguments.

Thanks in advance.

  How to add session item as a property of $this->session?
Posted by: krystian2160 - 06-21-2017, 02:21 AM - Forum: General Help - Replies (2)

In documentation we can find 3 ways to add session data.

  • By $_SESSION array (undescribed how to do it, but this actually is well known from php's)
  • As a property of $this->session (undescribed...)
  • By userdata old method (described)

Old method described and other 2 not?...

And question is.
How to add session data as a property of $this->session
And not old method of assigning it as userdata

[Image: 0K0t9we.jpg]

  HMVC Routes: Protected methods result in warning instead of 404
Posted by: RBX - 06-20-2017, 02:35 PM - Forum: Issues - Replies (1)

I've been using HMVC modular extensions. I have a base class in which I've defined some protected methods available to all inheriting controller, however I don't want them to be accessible using URL. When trying to access with URL, I get a warning instead of 404 error. It would be great if these could return 404 as I believe only public methods are intended to be available as routes.

Severity: Warning

Message: call_user_func_array() expects parameter 1 to be a valid callback, cannot access protected method Controller::method()

Filename: core/CodeIgniter.php

Line Number: 532

  Display results in a table
Posted by: ozzy - 06-20-2017, 01:41 PM - Forum: General Help - Replies (4)

I have made a simple CRUD site, i have attached files, i would like to be able to display results in a table, is this possible? how would i apply this to my code? 
any guidance will be helpful.

Thank You

Attached Files
.php   options_view.php (Size: 1.03 KB / Downloads: 15)
.php   site_model.php (Size: 472 bytes / Downloads: 12)
.php   site.php (Size: 724 bytes / Downloads: 10)

  Form validation don't work
Posted by: pippuccio76 - 06-20-2017, 01:03 PM - Forum: CodeIgniter 3.x - Replies (2)

Hi this is my form user/register :

<!DOCTYPE html>

       <meta charset="UTF-8">
       <?php   echo form_open('user/register'); ?>
       <input type="hidden" name="<?php echo $this->security->get_csrf_token_name(); ?>" value="<?php echo $this->security->get_csrf_hash(); ?>">

           <?= form_label('Email*:' ,'email') ;?>
           <?= form_input('email' ,set_value('email'),'id="email_id"') ;?>
           <?= form_label('Username:' ,'username') ;?>
           <?= form_input('username' ,set_value('username'),'id="username_id"') ;?>
           <?= form_label('Password*' ,'password') ;?>
           <?= form_input('password' ,'','id="password_id"') ;?>
           <?= form_label('Repeat Password*' ,'repeat_password') ;?>
           <?= form_input('password' ,'','id="password_id"') ;?>
           <?= form_submit('submit','Login') ;?>
           <?= form_close();?>
       <?php  echo form_close();?>
       <div><?= validation_errors(); ?></div>


This is my controller function :

function register(){
      $this->form_validation->set_rules('email','Email','required|valid_email', array('required' => 'Inserisci la mail','valid_email'=>'la mail deve essere valida'));
      $this->form_validation->set_rules('repeat_password','Password Confirmation','required');    
      $this->form_validation->set_rules('username','Username','min_length[6]|max_length[12]',array('min_length'=>'Lunghezza minima 6 caratteri', 'max_length'=>'Lunghezza massima 12 caratteri'));
       $data['errors']    = $this->user_model->errors;
       $data['messages']  = $this->user_model->messages;
       $this->load->view('user/register', $data);

But if i insert email  and password i have this error :

The Password field is required.

if i insert password and password_repeat to i have this error :

The Password Confirmation field is required.

this is a test application :


  Opinion to documentation
Posted by: krystian2160 - 06-20-2017, 12:58 PM - Forum: CodeIgniter 4 Feature Requests - Replies (1)

In my opinion it would be better when you first say ;This method is DEPRECATED; or something else, and not at the bottom of method or something.

Because It's like

Go here.
Reading, reading, reading.
There is note. `Deprecated`.
Ugh.... :/ couldn't this not be earlier before I had read all?

Just saying Smile.

  Theme © 2014 iAndrew  
Powered By MyBB, © 2002-2017 MyBB Group.