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

getting a runtime error

$
0
0
I am getting a runtime error: Unable to locate the model you have specified: User

system/core/Common.php:653

file=/var/www/html/sub_crud/system/core/loader.php

I took a look in /core and I don't have loader.php. But I do have MY_loader.php

Any idea of what is going wrong? Cool

Getting the number of images of an item : Join and Count

$
0
0
Hi there,

As you may guess from topic title I have got 2 tables : (let's say) posts and post_images.

POSTS TABLE consists of:
     post_id - posts_name - post_text - post_date


POST_IMAGES consists of:
    post_image_id - post_id - post_url

And on my admin panel I have got a page which lists posts as a table (as a result of this Model and Controller).

Model: 

PHP Code:
function my_posts(){
 
   $mp $this->db->SELECT('*')
 
   ->from('posts')
 
   ->get()
 
   ->result();

 
   return $mp;
 
      

Controller:

PHP Code:
public function posts(){    

    $this
->load->model('Backend_model');
 
   $data['posts'] = $this->Backend_model->my_posts();
 
   $this->load->view('admin/posts'$data);
 
 

result page :

post_name   -   post_date    -    how-many-images-does-this-post-have
 example1        01.12.2019                   ??????
 example2        02.12.2019                   ??????

How can I get the image number of each blog post?

P.S. I have tried lots of examples on stackoverfow and here about joins-counts and grouping even, however as I couldn't succeed it, I am posting here as plain as possible

Thanks in advance

Managing large recordset and maintaining database (MySQL)

$
0
0
Hi,

Need some help about databases. I'm currently using MySQL as my database and CI as my framework. I created a web page where I can upload a CSV file and insert them to my table. I have CSV file with 90K+ lines in it.

After the upload and insert process, and checking the dashboard of my app, it became slow. My app took around 5 seconds load time.

How can I manage large database without stalling or slowing the application? Is there any special technique on database or source code?

Thank you.

By the way, I use DataTables + Ajax to display records.

If else in view

$
0
0
I have added a new field in my controller

$output['ticket:types'][$key]['plus'] = "Yes"

or

$output['ticket:types'][$key]['plus'] = "No"


there is also an existing $output['ticket:types'][$key]['download


In the view there is


{if ticket:types}

                    {ticket:types}']

                   {dropdown}

                    {/ticket:types}
                  {else}
                        
                        <label>No ticket types available.</label><br />
                {/if}        
  {/if}




How do I test the value of $output['ticket:types'][$key]['plus']  in the view? I doesn't recognise {if plus == "Yes}


Thanks

Forum Messaging

$
0
0
If your going to send me an email message then turn on Private Messaging or do not send it!

Seeding -> Class not found

$
0
0
Hello,

i used CI 3 before and i liked it a lot and now i want to write a inhouse Solution for my Company. So i thought it would be nice to start  with the new seeding possibilites.

But somehow my seed class cant be found. I even tried the example from the docs and created the SimpleSeeder Class:
PHP Code:
<?php namespace App\Database\Seeds;

class 
SimpleSeeder extends \CodeIgniter\Database\Seeder
{
 
       public function run()
 
       {
 
               $data = [
 
                       'username' => 'darth',
 
                       'email'    => 'darth@theempire.com'
 
               ];

 
               // Using Query Builder
 
               $this->db->table('users')->insert($data);
 
       }

The class is located in app/Database/Seeds/SimpleSeeder.php

And in the example Controller "Home.php" i called the seeder with:
PHP Code:
    public function index()
    {
 
               $seeder = \Config\Database::seeder();
 
               $seeder->call('SimpleSeeder');
        return 
view('welcome_message');
    } 

But every time i call the home Controller ill get the error Message that SimpleSeeder class could not be found. What am i missing here? And yes, i did the configuration for the Database in app/Config/Database.php

mysql 8

$
0
0
Upgrading our systems to code igniter 3.  First we want to roll out the db upgrade to mysql 8 and CI 2 gives an error  Server sent charset unknown to the client.  It seems not to occur in CI 3.   Any idea if its possible to run MySQL 8 in CI 2?

CodeIgniter - Appropriate for medium scale

$
0
0
Hi all,

I've come across a business opportunity that will likely result in what I'd call a medium scale website.  I'm not 100% sure my scaling estimate is accurate but lets just say it could have 50,000 users, probably close to 500 at a time during various periods of the year.

The website is fairly simple and is basically a database app keeping track of things.

I've written four smaller websites in CodeIgniter and I'm very happy with the framework and what it provides.  One of my smaller sites was a website that offered music upload and playback for artists.  That website had enough traffic and use that my host provider was kind of mad at me for bandwidth.  CI performed well in that instance.

I realize that my choice of hosting plays a big role in how well a website performs under load but I've never tried to use it for something that could be as large as this opportunity.   

For those of you that do this professionally would you chose CodeIgniter for a site of this potential size?  The primary criteria I can give at this time is perhaps 500 users online at a time reading, updating, and adding information to various databases.

Thanks in advance

I would also be interested in knowing about your company if you do contract work.

Mark

Basic SQL command will not return object

$
0
0
I am trying to run a very basic query, and I can not get an object to return.. Other functions (using the same database) in this model work just fine, I am querying a MS-SQL database

PHP Code:
function tmp2()
 {
 echo 
'CodeIgniter: '.CI_VERSION.'<br>';
 
$lines $this->db->select('*')->from('Util_TMP_Calibrate')->get();
 if(
is_object($lines)){ 
           
$nr=$lines->num_rows(); 
 } else { 
           echo 
'not object'
           
$nr=0
 } 

Code:
CodeIgniter: 3.1.6
not object
SELECT * FROM "Util_TMP_Calibrate"

Can Codeigniter hmvc supports multiple controllers from a module?

$
0
0
Hello All. I am new to this forum and new to Codeigniter Hmvc as well.  
I have a question. Can this hmvc supports calling multiple controller functions from single controllers folder. For example I have modules folder . Under modules I have controllers folder and views folder. In controllers folder I have created two controller functions. 

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

/**
* HODController
*/
class Hod extends MY_Controller
{
    public function 
__construct()
    {
        
parent::__construct();
        
    }
    public function 
index()
    {
         
$this->load->view('welcome');
    }
    public function 
sayHi()
    {
        
$this->load->view('sayhi');
    }




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

/**
* HOD1Controller
*/
class Hod1 extends MY_Controller
{
    public function 
__construct()
    {
        
parent::__construct();
        
    }
    public function 
index()
    {
        
$this->load->view('welcome');
    }

    public function 
sayhi()
    {
        
$this->load->view('sayhi');
    }


http://localhost/adeptra_hmvc/index.php/hod/sayhi - this is working
http://localhost/adeptra_hmvc/index.php/hod1/saybye - this says 404 - page not found error. So is it possible to work with calling multiple controllers from a module in hmvc?
Thanks ,
Ajay K.

How to debug migration config issues

$
0
0
Hey guys,

I'm currently ramming my head against the wall, trying to break through "Migrations has been loaded but is disabled or set up incorrectly."  I know it isn't disabled (code to follow), so what does this mysterious "not set up correctly" mean?  I guess it makes sense to END USERS (it means the developer made an ID-10-T error someplace lol - but they shouldn't see this kind of message anyway IMO) but is there any way to get some additional info?  Nothing is logged, there is no stack trace, it may as well just say "dude, here's yer solution - git reset --hard $ID10T" lol

As promised, here's my config file:

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

/*
|--------------------------------------------------------------------------
| Enable/Disable Migrations
|--------------------------------------------------------------------------
|
| Migrations are disabled by default for security reasons.
| You should enable migrations whenever you intend to do a schema migration
| and disable it back when you're done.
|
*/
$config['migration_enabled'] = TRUE;

/*
|--------------------------------------------------------------------------
| Migration Type
|--------------------------------------------------------------------------
|
| Migration file names may be based on a sequential identifier or on
| a timestamp. Options are:
|
|   'sequential' = Sequential migration naming (001_add_blog.php)
|   'timestamp'  = Timestamp migration naming (20121031104401_add_blog.php)
|                  Use timestamp format YYYYMMDDHHIISS.
|
| Note: If this configuration value is missing the Migration library
|       defaults to 'sequential' for backward compatibility with CI2.
|
*/
$config['migration_type'] = 'timestamp';

/*
|--------------------------------------------------------------------------
| Migrations table
|--------------------------------------------------------------------------
|
| This is the name of the table that will store the current migrations state.
| When migrations runs it will store in a database table which migration
| level the system is at. It then compares the migration level in this
| table to the $config['migration_version'] if they are not the same it
| will migrate up. This must be set.
|
*/
$config['migration_table'] = 'migrations';

/*
|--------------------------------------------------------------------------
| Auto Migrate To Latest
|--------------------------------------------------------------------------
|
| If this is set to TRUE when you load the migrations class and have
| $config['migration_enabled'] set to TRUE the system will auto migrate
| to your latest migration (whatever $config['migration_version'] is
| set to). This way you do not have to call migrations anywhere else
| in your code to have the latest migration.
|
*/
$config['migration_auto_latest'] = FALSE;

/*
|--------------------------------------------------------------------------
| Migrations version
|--------------------------------------------------------------------------
|
| This is used to set migration version that the file system should be on.
| If you run $this->migration->current() this is the version that schema will
| be upgraded / downgraded to.
|
*/
$config['migration_version'] = 20190112182800;

/*
|--------------------------------------------------------------------------
| Migrations Path
|--------------------------------------------------------------------------
|
| Path to your migrations folder.
| Typically, it will be within your application path.
| Also, writing permission is required within the migrations path.
|
*/
$config['migration_path'] = APPPATH.'migrations/';

I don't see anything blatantly wrong here, but apparently it saw something somewhere it didn't like.  I tried rolling back to a previous migration, updating to the migration I want, and nothing so far seems to get past this.  The only idea (that just now occurs to me) is maybe set the log level to EVERYTHING, and pray that generates some information.  Any other ideas?  Thanks.

Filter the results to be shown using pagination the right way

$
0
0
Hello

I have used the search function of the forum, searching by title with various queries,

but I can't find a thread that helps with the subject BUT I see many pagination threads so it looks like that pagination is an HOT TOPIC


I feel that, for a Codeigniter newbie, this is one of the trickier topics


together with turning the mind to the MVC and to the mechanism of calling controllers through the CI URLs mechanism



The idea is ALSO to UPDATE THE PAGINATION CONCEPTS to the CURRENT Codeigniter 3.1.10
since out there , the infos are a great confused mixture of the various CI versions. Is this the Most Important Codeigniter Forum? Isn't it? So let's make order :-)



Here it comes this thread where I kindly ask:



Are there some gentle CI guru that may show a bunch of frequent pagination with filtering situations best practices?



Yes it requires time, sharing is caring, and fills the souls. I teach and I like teaching and see students understanding the point. If I were a Codeigniter guru, I would take the time to fill the below sections by myself Confused but I'm a CI newbie



What I wish is that some CI guruS of good will, will develop/add/share THE GOOD example in a CONTEMPORARY "Codeigniter the Right Way Style" :-)



which also (to me) mean to kindly teach good advices on how to project the URL structure for the controllers and methods

BEFORE to begin coding

AND OR about routes in the routes.php and whatever else could be involved


Idea  and where an hypothetical CI FORUM GURU's COUNCIL will check the entries and eventually discuss and add modifications



Thank you in advance to those developers that will take the time to teach to people.


Here you the first common situations that comes to my mind


1. FILTER RESULTS WITHOUT PASSING QUERY PARAMETERS FILTERS

As it may suggest the title of this first situation, the view evoked by this controller will always show a paginated result with a prefixed query

PHP Code:
   
    $this
->db->where('ticketstatus'0);
 
   $this->db->join('dept''dept.id = ticket.dept_id');
 
   $this->db->order_by('lastactivity''DESC');
 
   $this->db->limit(200); 

In current Codeigniter 3.1.10 which is the best practice to show pagination with a fixed filters set?

I mean in the wide meaning, so it also mean which is the suggested better practice to structure the project
- VC only or MVC
- use query builder or the queries strings



2. PAGINATION PASSING QUERY PARAMETERS SERVER SIDE
Mean within the code without user interaction



3. PAGINATION PASSING QUERY PARAMETERS CLIENT SIDE - ALLOW THE USER TO FILTER THE RESULTS
Here the situation is that we are showing to the user e.g. the table of the customers of an international company and we allow him to filter the HUGE list
so in the view he will have some dropdown where to select the nation, male/female, age range

and when he clicks to change the pagination page the filter is still applied

4. ...

5. ...

Thank you for teaching the right way to use Codeigniter pagination and if in Codeigniter 4 pagination is going to change, also thank you for advices on that

I wish this could become a useful thread for newbies ( like I'm )

Cor

Mysql request problem

$
0
0
Hello,
I can not solve the good qty in this request.
She always gives me double the value of qty.
The result is false when I put the following condition:

PHP Code:
$this->db->select_sum('qty_alert');
$this->db->join('stocks_alert''stocks_alert.id_product = stocks.id_product');
$this->db->having('qty < qty_alert'); 


Here is the complete request:

PHP Code:
$this->db->select('products.id, products.reference, products.label');
$this->db->select_sum('qty_alert');
$this->db->select("(SUM(CASE WHEN slug IN ('orders','variation','transfer','add') THEN stocks.qty ELSE 0 END) - SUM(CASE WHEN slug ='used' THEN stocks.qty ELSE 0 END)) as qty");
$this->db->from('products'); 
$this->db->join('stocks''stocks.id_product = products.id'); 
$this->db->join('stocks_alert''stocks_alert.id_product = stocks.id_product');
$this->db->group_start();
$this->db->like("products.reference"$_POST["search"]["value"]);  
$this
->db->or_like("products.label"$_POST["search"]["value"]);
$this->db->group_end();
$this->db->having('qty < qty_alert');
$this->db->group_by('products.id'); 

I also tried sub-query, but I can not do it.

Would anyone have an idea to put me on the track.
Thank you to all of you. 

Excuse me for my english.

Is my post in the right section of the forum?

$
0
0
Hello I have written this thread

Codeigniter 3.1.10 pagination How to setup the right way?
https://forum.codeigniter.com/thread-72805.html

I think the right place where it should have been placed is in the "Best Practices"

can you kindly confirm?

Otherwise thank to moderators to move it in the right place

post the new name of images in database with insert batch

$
0
0
Hi!
When i post the name of my images in database is the original name and not the new name that i have selected in $config['file_name'].

The images are uploaded on server with the new name (and this is ok), but in database are posted the original name (and isn't ok).

Thanks for help me.
PHP Code:
//
// CONTROLLER
//

public function add()
{
 
 
  if 
(!empty($_FILES))
 
 {
 
   $folder $this->input->post('id_article');
 
   $file_name $folder."_".date('dmy').'_';

 
   if (!is_dir('/media/images/uploads/gallery/'.$folder))
 
   {
 
     mkdir('./media/images/uploads/gallery/' $folder0777TRUE);
 
   }

 
   $files $_FILES;
 
   $count count($_FILES['multimages']['name']);

 
   for($i 0$i $count$i++)
 
   {
 
     // configurazione
 
     $config['upload_path'  './media/images/uploads/gallery/'.$folder;
 
     $config['file_name'    $file_name;
 
     $config['allowed_types'] = 'gif|jpg|png';
 
     $config['max_size'     1024;
 
     $config['max_width'    1920;
 
     $config['max_height'   1080;
 
     $config['overwrite'    FALSE;
 
     $config['remove_spaces'] = TRUE;

 
     $_FILES['multimages']['name'    $files['multimages']['name'][$i];
 
     $_FILES['multimages']['type'    $files['multimages']['type'][$i];
 
     $_FILES['multimages']['tmp_name'] = $files['multimages']['tmp_name'][$i];
 
     $_FILES['multimages']['error'   $files['multimages']['error'][$i];
 
     $_FILES['multimages']['size'    $files['multimages']['size'][$i];

 
     $this->load->library('upload'$config); // carico la libreria di CI
 
     $this->upload->initialize($config); // inizializzo la configurazione

 
     if ($this->upload->do_upload('multimages'))
 
     {
 
       $data = array('upload_data' => $this->upload->data());
 
     }
 
     else
      
{
 
       $this->session->set_flashdata('result''<div class="uk-alert-warning" uk-alert><a class="uk-alert-close" uk-close></a>Si è verificato un problema nel caricamento delle immagini!</div>');
 
       redirect('images/index');
 
     }

 
   }

 
   $name_image  $files['multimages']['name'];
 
   $data = array();

 
   for($i=0$i<$count$i++)
 
   {
 
     $data[$i] = array(
 
       'id_article'  => $this->input->post('id_article'),
 
       'name_image'  => $name_image[$i],
 
       'title_image' => $this->input->post('title_image')[$i],
 
       'text_image'  => $this->input->post('text_image')[$i],
 
       'alt_image'   => $this->input->post('alt_image')[$i],
 
     );

 
   }
 
   $this->Images_model->add_image('tbl_images'$data);

 
   $this->session->set_flashdata('result''<div class="uk-alert-success" uk-alert><a class="uk-alert-close" uk-close></a>Immagini caricate correttamente!</div>');
 
   redirect('images/index');
 
 }

}

//
// MODEL
//

 
 function add_image($table$data)
 
 {
 
   $query $this->db->insert_batch($table$data);
 
 

htaccess rewrite assets directory

$
0
0
Hello,

i have multiple ci instances in different folders, each folder has only 3 files .htaccess index.php and /config/config.php.

only problem i face is assets which is called through base_url('assets/.....'), modifying code is not an option since program developers pushes frequent updates and my changes will be overwritten, what i need to do is make rewrite rule in htaccess which will modify mysite.com/folder/assets to mysite.com/assets. 

i tried lots of combination but none of them works, i think it has something to do with my current htaccess parameters


Original code

Code:
RewriteEngine on
RewriteCond $1 !^(index\.php|resources|robots\.txt)
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php?/$1 [L,QSA]
AddDefaultCharset utf-8

I have added bellow code, but js functions which are adding css parameters doesn't work any more.

Code:
 RedirectMatch 301 ^/demo/assets/(.*)$ /assets/$1

in linus hostng it works perfectly, however, it fail in windows hosting

$
0
0
I developed a web application in codeigniter. It works properly in linux hosting but when i switch to window hosting home page working fine but sub page could not open. It display page not found.

Send value to menu view

$
0
0
Hi , sorry for english , in every controller i have :

Code:
       $this->load->view('templates/header_user',$data);
       $this->load->view('templates/menu_user',$data);
       $this->load->view('controller/view', $data);
       $this->load->view('templates/footer_user',$data);

Because menu_user are used in several controller  and i want send a value  to menu , how can i do this ?

How save timestamp according to Asia timezone

$
0
0
Hi
I receive timestamp base of UTC and save it into database
Now i need report all data example between 2:30 to 14:43
And i am Tehran with GMT +3:50
Can i save timestamp base of Asia/Tehran timezone or i can only get their base of my favorite timezone?
Can i set timezone to Asia/Tehran on mysql when i use SELECT command?
Thanks

Uploading text file without saving?

$
0
0
I have a form and I want to upload text file and then read it and display the content on a textarea. The text is just a temp file so I don't want to save it.

Currently I am using the upload library like this

PHP Code:
$config['allowed_types'] = 'txt';
$config['max_size' '100';

$this->load->library('upload'$config);
$this->upload->initialize($config);

if ( ! 
$this->upload->do_upload()){
 
   $data['error'] = $this->upload->display_errors();
}
else{
 
   $text_file $this->upload->data();
 
   $data['$content'] = file_get_contents($text_file);
 
   echo "success";


I didn't specify the upload path in the config and want to only save the text to the temp folder. But that doesn't seems to work as it complains about invalid upload path.
Viewing all 14343 articles
Browse latest View live


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