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

Looking Full-stack developer

$
0
0
Hi, 

company provides hosting services and currently is looking for full stack developer who could start from April 1st. Salary and all job conditions will be negotiated when candidate approach company via email. 
For contacts and more information related to company and position check Hostens.com website.

Problem with Image Manipulation Library

$
0
0
I want to compress the image by 60%. My code is given bellow. I have uploaded an image of 627Kb. The code block is executed but not compressing. Is there any error in my code?

Thanks in advance.

PHP Code:
$this->load->library('image_lib');
if(
$this->upload->data('file_size') > 300){
 
   $config['image_library'   'gd2';
 
   $config['source_image'    $this->upload->data('full_path');
 
   $config['quality'         '60%'// Also tried $config['quality']          = 60;
 
   $config['new_image'       $this->upload->data('full_path');
 
   $this->image_lib->clear();
 
   $this->image_lib->initialize($config);
 
   $this->image_lib->resize();
    echo 
'I am ok';

PHP 7.3.2 Released Bugfix

Problems with Unit Testing - HTTP Feature Testing - CI4

$
0
0
Hello, i'm trying to make a simple test using 'HTTP Feature testing' as described in Documentation. But, after hours of trying I couldn't achieve it.

This is my implementation class:

PHP Code:
<?php

namespace App\Controllers;

//use App\Libraries\Traits\ExtendedController;
use CodeIgniter\Controller;

class 
Home extends Controller
{
 
  // use ExtendedController;

 
   public function index()
 
   {
 
       return view('welcome_message');
 
   }



And this is my Test class:
PHP Code:
<?php
namespace Tests;

use 
CodeIgniter\Test\FeatureTestCase;

class 
TestHome extends FeatureTestCase
{

 
   public function setUp()
 
   {
 
       parent::setUp();
 
   }

 
   public function tearDown()
 
   {
 
       parent::tearDown();
 
   }

 
   public function testIndex()
 
   {
 
       $result $this->call('get'site_url());
 
       $this->assertSee('Welcome to CodeIgniter');
 
   }


And this is the error thrown:
Code:
There was 1 error:

1) Tests\TestHome::testIndex
CodeIgniter\Exceptions\PageNotFoundException: Controller or its method is not found: App\Controllers\\Http:::ci4.extctrl.docker:8080

/var/www/html/ci4-extendedcontroller/vendor/codeigniter4/framework/system/Exceptions/PageNotFoundException.php:14
/var/www/html/ci4-extendedcontroller/vendor/codeigniter4/framework/system/CodeIgniter.php:889
/var/www/html/ci4-extendedcontroller/vendor/codeigniter4/framework/system/CodeIgniter.php:249
/var/www/html/ci4-extendedcontroller/vendor/codeigniter4/framework/system/Test/FeatureTestCase.php:122
/var/www/html/ci4-extendedcontroller/tests/TestHome.php:21

In my phpunit.xml, i've defined my env app.baseUrl as:    
Code:
<php>
       <env name="app.baseURL" value="http://ci4.extctrl.docker:8080/"/>
   </php>

Validation with Arrays as Field Names

$
0
0
I am trying to use Form Validation with an Array for field names. I was hoping that it was possible to validate each field individually, I've followed the documentation closely but I when I submit the form the validation message should display for one field but it displays for all fields. What have I done wrong?
[Image: screenshot%202019-02-07%2016-47-50.png?raw=1]

View:
Code:
<!DOCTYPE html>
<html lang="en">
<head>
   <meta charset="UTF-8">
   <title>Document</title>
</head>
<body>
   <form method="post">
       <input type="text" name="options[]" value="<?php echo set_value('options[]'); ?>">
       <?php echo form_error('options[]'); ?>
       <br>
       <input type="text" name="options[]" value="<?php echo set_value('options[]'); ?>">
       <?php echo form_error('options[]'); ?>
       <br>
       <input type="text" name="options[]" value="<?php echo set_value('options[]'); ?>">
       <?php echo form_error('options[]'); ?>
       <br>
       <input type="submit">
   </form>
</body>
</html>

Controller Method:
PHP Code:
public function array_validation()
{
    
$this->load->helper'form' );
    
$this->load->library('form_validation');
    
$this->form_validation->set_rules('options[]''Options''trim|numeric');
    if (
$this->form_validation->run() == FALSE) {
        
// form empty or validation failed
    
} else {
    }
    
$this->load->view('welcome/array_validation');

In Dropdown href not taking method in controller

$
0
0
I have below code in view file - menu.php: (lines reduced for ease of checking..)
______________________________________________
<h3>ABC Fruits</h3>
<div id="Startup">

<ul class="" id="">
<li>Format
            <ul><li><a href="localhost:8015/citest3/index.php/soft1/sell">sell</a></li></ul>
            <ul><li><a href="localhost:8015/citest3/index.php/soft1/buy">buy</a></li></ul>
</li>

<li>Exit</li>
</ul>
__________________________________________________



And below Code in Controller - Soft1.php file:
___________________________________________________
<?php
defined('BASEPATH') OR exit('No direct script access allowed');

class Soft1 extends CI_Controller {

public function index()
    {
       $this->load->view('menu');
    }
    
    public function sell()
        {
            echo "Sales Done";
        }
    
    public function buy()
        {
            echo "Purchase Done";
        }
    
}
___________________________________-

I get a menu as per attachment when I run the code. But when I click on menu option I expect the respective function (method) in the controller to run. (for eg: if I click on sell - the sell method in controller should run & "Sales Done" should get displayed). But it is not responding. But if I put "www.goole.co.in" it goes there. Also, when I copy the "localhost:8015/citest3/index.php/soft1/buy" on browser it works! 

But it is not working when I click on the menu item.

What could be the problem? please suggest a solution.

.png   href-prob.png (Size: 120.56 KB / Downloads: 2)

Rewriting query in query builder

$
0
0
Hi there,

I'm pretty new to Codeigniter. I have trouble with Mysql query converting to CI query builder.

So, original query is this:

PHP Code:
$query $this->db->query('SELECT' .
' p_pedestal.*,' .
' dev.dev_name AS device,' .
' p_port.title AS port,' .
' UNIX_TIMESTAMP(p_pedestal.created) AS created_t,' .
' UNIX_TIMESTAMP(p_pedestal.updated) AS updated_t' .
' FROM p_pedestal' .
' LEFT JOIN p_port' .
' ON p_pedestal.port_id = p_port.id' .
(
$this->system->isOwner()?
' JOIN p_port_user_rel ON (p_port_user_rel.username = "' .
strtolower($_SESSION['user']['username']) .
'") AND p_port_user_rel.port_id = p_pedestal.port_id' ''
) .
' INNER JOIN dev' .
' ON p_pedestal.dev_id = dev.dev_id' .
' ORDER BY p_pedestal.formatted_address ASC '
); 


It works fine, all is good.

Now, I tried rewriting it and it just never works, I have no idea why.
This is what I got so far:

PHP Code:
$query $this->db
->select('p_pedestal.*,
dev.dev_name AS device,
p_port.title AS port,
UNIX_TIMESTAMP(p_pedestal.created) AS created_t,
UNIX_TIMESTAMP(p_pedestal.updated) AS updated_t'
)
->
from('p_pedestal')
->
join('p_port''p_pedestal.port_id = p_port.id''left')
->
join('p_port_user_rel''p_port_user_rel.username =' strtolower($_SESSION['user']['username']) )
->
where('p_port_user_rel.port_id''p_pedestal.port_id')
->
join('dev''p_pedestal.dev_id = dev.dev_id''inner')
->
order_by('p_pedestal.formatted_address')
->
get(); 


And second part of my question is- how would you go about $this->system->isOwner()?
Would you put it in if statement, run one query or run another one with additional Join?

Thanks in advance Smile

CMS Admin Dashboard Example

$
0
0
Hi,
I am building a website using CI for a customer.
I wasting time trying to implement structure for general needs.

For example in Admin Dashboard:
1. Users can create pages
2. Users can create blog posts
3. Users can create announcements
4. Users can create categories
5. Users can create galleries
6. Users can create slider

As I does not have experience in this type of project I am wasting to much time in finding right DB structures for these requirements. 


Can anybody suggest me free/paid template project that meet these requirements?

installing on new PC

$
0
0
I am trying to install CI on a new Linux laptop. I modified index.php to point at the CI directory at /Home/codeigniter/CodeIgniter-3.1.10/system, but when I type localhost in the browser I am getting

"Your system folder path does not appear to be set correctly. Please open the following file and correct this: index.php"

I modified index.php to be:




*---------------------------------------------------------------
 * SYSTEM DIRECTORY NAME
 *---------------------------------------------------------------
 *
 * This variable must contain the name of your "system" directory.
 * Set the path if it is not in the same directory as this file.
 */
$system_path = '/Home/codeigniter/CodeIgniter-3.1.10/system';

/*

what is wrong? Do I need to also update the application_folder path?

The way I moved over from the Windows PC is that I copied my application directory which is c:/xampp/htdocs/sub_crud. It contains application, system, etc. Does this mean that I didn't need to do a reinstall of CI? Could I have just pointed $system_path at /var/www/html/sub_crud/system  on the Linux PC?

set sql variable before main query

$
0
0
Is it possible to set sql variable before other queries?(not $this->db->query())

I'd like to do something like this.


PHP Code:
$this->db->query("SET @min_id := (SELECT min_id FROM shop_parameter)");
$this->db->select('item_id');
$this->db->from('products');
$this->db->where('(item_id > @min_id',NULL,FALSE);
$this->db->where(array('item_stat >'=>10));
$query=$this->db->get();
foreach(
$query->result() as $r){
   $products[$r->item_id]=$r; }

Session Issues

$
0
0
So I'm having a strange issue with sessions on one of my websites. Before getting into too much detail, I have two websites using the same CI version (3.1.10) configured exactly the same and both are also using PHP 7.2. Sessions are working perfectly fine on one, but not on the other. Upon using the browser debug tools, I see that on the site that is not working, the session is showing the full array instead of the session ID. The extent of the differences between both websites are the HTML, CSS, Domain, and DB credentials (shared VPS, same PHP INI, same DB version). Both domains use SSL.

Here is my session configuration in config.php:

$config['sess_driver'] = 'database';
$config['sess_cookie_name'] = 'ci_session';
$config['sess_expiration'] = 7200;
$config['sess_save_path'] = 'ci_sessions';
$config['sess_match_ip'] = FALSE;
$config['sess_time_to_update'] = 300;
$config['sess_regenerate_destroy'] = FALSE;

In browser debug under storage (firefox) working website shows:

ci_session: "f89h3983hf89h389fh3" (ID isn't real, just wanted to show you what I see).

And website that has the issue shows:

ci_session: array 0 : "blah" 1 : "blah: 2 : "blah" (all the way up to...) 22 : "blah"

Funny part is that if I swap the DB configuration from the non-working site over to the working site and post information, it works without issue, which is what I've been doing to circumvent the issue in the interim.

I turned on logging and there were no errors. Figured I'd just suck it up and ask for help because at this point I'm just spinning my wheels. Let me know if there is anything else I can provide that might shed some light on the issue.

For Cpanel, it works perfectly, however, it fail in plesk server.

$
0
0
For Cpanel, it works perfectly, however, it fail in plesk server.
Home page fine but for sub pages 
 Not Found

The requested document was not found on this server.

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);
 
 

Array helper - more function required

$
0
0
I have gone through the ArrayHelper file and found only one function.

There are multiple functions which we use in our development, which we wish to have in core helpers

Can we suggest those as well to be a part of core functionality instead of custom?

This might help all developers to get the one-stop solution

Suggested functions can be,

  1. array_sort_by_column
  2. array_remove_empty_elements
  3. array_search_by_key
  4. array_search_by_value
  5. array_change_key_case_recursive
  6. array_trim

PostgreSQL Master-Slave

$
0
0
Hi guys, does anybody knows how to extend CI postgre driver to implement support of master-slave replication by standard query-builder class ? Is somewhere any tutorials or best practices which can cover this topic? thanks!

Codeigniter Pagination with AJAX JQuery on XAMPP

$
0
0
Hello to all of you as premise I say I'm very basic with Codeigniter

hopefully some Ci expert could hint what is wrong with this

this is Ci 3.1.10

I suspect my issue is matter of a wrong configuration in some file Confused


This Codeigniter pagination with ajax is running localhost on xampp

Here it is the code of this  really simple experiment,
https://itsolutionstuff.com/post/codeign...ample.html

mean a short tutorial
just matter of db creation
one controller using the codeigniter pagination library
and one view with jquery ajax at bottom


Well

the codeigniter folder has been renamed ci-pag
it is in
Code:
http://localhost/ci-pag
and pointing to there I have the standard welcome controller with CI welcome message

I have created the test db as in the tutorial using the provided query and filled in some data

briefly copied and pasted the provided controller and view with obviously the same names

configured codeigniter as ususal (for my xampp experiments) mean
- created .htaccess
- added the rewrite stuff for index.php removal
- changed the config.php to remove the index.php and set the base path to http://localhost/ci-pag/

THE ISSUE
when I point to
Code:
http://localhost/ci-pag/post
it does show only the header of the page but for the rest nothing  Sad

you can see the screenshot here No table just header


also

can you kindly hint how to approach some debug in a case such the current one? Thank you for this too if any

Thank you
Cor

Ion Auth problems after Ion Auth upgrade

$
0
0
Hi, I've just upgraded Ion Auth for my app, but am unable to create a new user anymore with the register function without a password.

In my original implementation, admin create the users, and users receive an email activation link upon being created. Clicking the link sends the user to a set password page, where upon completion ion_auth->activate is called.

Is there some way around this? I mean I could create a long random string for the password argument, but it seems a bit hacky.

Thanks.

bug for multi insert for single mysql query

$
0
0
database structure >> table (game_odds) >> fields (ID_MATCH) (BANKER) (SME)


query data here

$q = "

INSERT INTO game_odds ( ID_MATCH, BANKER, SME )
SELECT * FROM (
SELECT '1553203', '1', 'S') AS tmp 
WHERE NOT EXISTS (
SELECT ID_MATCH FROM  game_odds
WHERE ID_MATCH = '1553203' AND SME = 'S'  AND BANKER = '1'
) LIMIT 1;

INSERT INTO game_odds ( ID_MATCH, BANKER, SME ) 
SELECT * FROM (
SELECT '1553203', '3',  S' ) AS tmp
WHERE NOT EXISTS (
SELECT ID_MATCH FROM game_odds
WHERE ID_MATCH = '1553203' AND SME = 'S' AND BANKER = '3'
) LIMIT 1;


";

this->db->query($sq);




========================================
statement run unsuccessful,  it will show

A PHP Error was encountered
Severity: Warning
Message: Cannot modify header information - headers already sent by (output started at /var/www/ball/application/controllers/Get.php:158)
Filename: core/Common.php
Line Number: 570
Backtrace:
File: /var/www/ball/application/controllers/Get.php
Line: 241
Function: query

File: /var/www/ball/index.php
Line: 315
Function: require_once

How to manage large database without stalling or slowing the application?

$
0
0
Hi,

I need some advice or help on how I can manage/optimize my large recordset in our database without stalling or making the application slow.

Currently, our database has over 100,000+ records and I have a query that simply fetch unique values for my filter (for export report):
PHP Code:
protected $options = array();

public function 
fetch_filter_options()
{
    if (empty(
$this->options))
    {
        
$res $this->db
                
->select('t.*')
             
   ->select('NULLIF(CONCAT(`u`.`firstname`, " ", `u`.`lastname`), "") AS `initiator_name`')
             
   ->from('casetracker as t')
             
   ->join('users as u''u.uid = t.initiator''left outer')
             
   ->get()
             
   ->result();

        
// Initialize
        
$options = [
            
'weeknumber'        => [],
            
'teamleader'        => [],
            
'solver'        => [],
            
'initiator_name'    => [],
            
'numtimesedited'    => []
        ];

        foreach (
$que as $res)
        {
            foreach (
$options as $key => $array)
            {
                if ( ! 
array_key_exists($res->{$key}, array_keys($options[$key])))
                {
                    
$options[$key][$res->{$key}] = $res->{$key};
                }
            }
        }

        
$this->options $options;
    }
    
    return 
$this->options;

(I alter the code because it contains sensitive information, sorry)

When I tried to fetch 100,000+ rows, I get the "Fatal error: Allowed memory size".
Some suggest to use unbuffered queries. But I use Query Builder. I don't know how to do that.
Or maybe I should re-structure my code?

Thank you.

Sentry Raven

$
0
0
Just wondering if people have managed to get Sentry error tracking working properly. I have a MY_Log class that works fine but when you turn off errors it turns off the error tracking! 

The code that I have is based on this: https://gist.github.com/755/3930723 just tweaked slightly to use Composer vs directly loading it like they have done.
Viewing all 14343 articles
Browse latest View live


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