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

Username
  

Password
  





Search Forums

(Advanced Search)

Forum Statistics
» Members: 15,101
» Latest member: artanadi
» Forum threads: 70,396
» Forum posts: 362,073

Full Statistics

Latest Threads
CI4 release
Forum: CodeIgniter 4 Discussion
40 minutes ago
» Replies: 3   » Views: 78
why models are not loadin...
Forum: General Help
2 hours ago
» Replies: 9   » Views: 192
[SOLVED - ]Database Forge...
Forum: CodeIgniter 4 Support
4 hours ago
» Replies: 1   » Views: 121
CI 3 using native session...
Forum: Libraries & Helpers
6 hours ago
» Replies: 6   » Views: 172
Cjax - Unable to locate t...
Forum: General Help
7 hours ago
» Replies: 1   » Views: 50
Model Design Question
Forum: CodeIgniter 4 Support
11 hours ago
» Replies: 5   » Views: 390
How to Switch Database Co...
Forum: CodeIgniter 3.x
Yesterday, 04:51 AM
» Replies: 1   » Views: 155
Show your support!
Forum: CodeIgniter 4 Development
Yesterday, 02:24 AM
» Replies: 32   » Views: 17,745
Controller naming PascalC...
Forum: CodeIgniter 4 Feature Requests
12-12-2019, 11:34 PM
» Replies: 2   » Views: 187
When Does Entity Attribut...
Forum: CodeIgniter 4 Support
12-12-2019, 08:12 PM
» Replies: 1   » Views: 186

 
  Dynamic chart Date range to filter records with PHP MySQL
Posted by: webamies - 12-02-2019, 01:11 AM - Forum: Model-View-Controller - Replies (3)

Good Morning,

I have been filtering for a dynamic chart for more than two weeks.
Everything works very well.
After choosing the dates you hardly print anything.
Please leave the code here.


CONTROLLER

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

class Incidencias_ministerio extends CI_Controller {

    public function __construct()
    {
        parent::__construct();    
        $this->load->model('incidencias_ministerio_model');
        
    }

    public function index()
    {
        //ifPermissions('incidencias_ministerio');
        $page_data['incidencias_ministerio'] = $this->incidencias_ministerio_model->get_nombre();
        $page_data['view'] = 'chart/incidencias_ministerio';
        $this->load->view('includes/layout', $page_data);
    }

    public function select_by_date_range() {
        $date1 = $this->input->post('date_from');
        $date2 = $this->input->post('date_to');
        $data = array(
        'date1' => $date1,
        'date2' => $date2
        );
        if ($date1 == "" || $date2 == "") {
        $data['date_range_error_message'] = "Both date fields are required";
        } else {
        $result = $this->incidencias_ministerio_model->show_data_by_date_range($data);
        if ($result != false) {
        $data['incidencias_ministerio'] = $result;
        } else {
        $data['incidencias_ministerio'] = "No record found !";
        }
        }
        $data['view'] = 'chart/incidencias_ministerio';
        $this->load->view('includes/layout', $data);
    }
}

MODEL

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

class Incidencias_ministerio_model extends CI_Model {

    public function __construct()
    {
        parent::__construct();
        $this->load->database();
    }
    
    function get_nombre() {

        $this->db->group_by('name_ministerio');
        $this->db->select('name_ministerio');
        $this->db->join('ministerios', 'ministerios.id = graficas.ministerio_id','inner');
        $this->db->select("count(*) as total");
        return $this->db->from('graficas')
          ->get()
          ->result();
    }

    public function show_data_by_date_range($data) {
        $condition = "add_date BETWEEN " . "'" . $data['date1'] . "'" . " AND " . "'" . $data['date2'] . "'";
        $this->db->group_by('name_ministerio');
        $this->db->select('name_ministerio');
        $this->db->join('ministerios', 'ministerios.id = graficas.ministerio_id');
        $this->db->join('tecnicos', 'tecnicos.id = graficas.tecnico_id');
        $this->db->from('graficas');
        $this->db->where($condition);
        $query = $this->db->get();
        if ($query->num_rows() > 0) {
            return $query->result();
        } else {
            return false;
        }
    }
    
}

VIEW
I'm sure the error comes from the view

Code:
<!-- Load file plugin Chart.js -->     
<script src="<?= base_url()?>/assets/chart/Chart.js"></script>

<div id="show_form" style="margin-bottom: 69px;">
    <div class="col-md-12">
        <?php
            echo form_open('incidencias_ministerio/select_by_date_range');
                echo'<div class="col-md-2">';
                    echo form_label('Buscar De : ');
                echo'</div>';

                echo'<div class="col-md-3">';
                    $data = array(
                    'type' => 'date',
                    'name' => 'date_from',
                    'placeholder' => 'yyyy-mm-dd'
                    );
                    echo form_input($data);
                echo'</div>';
                
                echo'<div class="col-md-1">';
                    echo " A : ";
                echo'</div>';
                echo'<div class="col-md-3">';
                    $data = array(
                    'type' => 'date',
                    'name' => 'date_to',
                    'placeholder' => 'yyyy-mm-dd'
                    );
                    echo form_input($data);
                echo'</div>';

                echo'<div class="col-md-3">';
                    echo form_submit('submit', 'Buscar');
                    echo form_close();
            echo'</div>';
        ?>
    </div>
</div>
    
<!-- /.box-body -->

    <?php
    
    $data_1= "";
    $data_2=null;
    
    foreach ($incidencias_ministerio as $item)
    {
        $data_3=$item->name_ministerio;
        $data_1 .= "'$data_3'". ", ";
        $data_4=$item->total;
        $data_2 .= "$data_4". ", ";
        
    }
    ?>
    <div class="chart">
    <canvas id="myChart"></canvas>
    </div>

<script>
    var ctx = document.getElementById('myChart').getContext('2d');
    var chart = new Chart(ctx, {
       
        type: 'bar',
        
        data: {
            labels: [<?php echo $data_1; ?>],
            datasets: [{
                label:'Incidencia por Ministerio ',
                backgroundColor: [    'rgb(255, 99, 132)',
                                    'rgba(56, 86, 255, 0.87)',
                                    'rgb(60, 179, 113)',
                                    'rgb(175, 238, 239)',
                                    'rgb(255, 99, 132)',
                                    'rgba(56, 86, 255, 0.87)',
                                    'rgb(60, 179, 113)',
                                    'rgb(175, 238, 239)',
                                    'rgb(255, 99, 132)',
                                    'rgba(56, 86, 255, 0.87)',
                                    'rgb(60, 179, 113)',
                                    'rgb(175, 238, 239)'
                                ],
                borderColor: ['rgb(255, 99, 132)'],
                //grafica
                data: [<?php echo $data_2; ?>]
                
            }]
            
        },
        // Configuration options go here
        options: {
            scales: {
                yAxes: [{
                    ticks: {
                        beginAtZero:true
                    }
                }]
            }
        }
    });
</script>


Lightbulb Encrypt & Decrypt Password
Posted by: manigopal - 12-01-2019, 08:13 PM - Forum: General Help - Replies (2)

I'm newbee to CI,

I'm trying to Create & Modify User Profile USING API (REST) json_encode option,

I want to use default encrypt & decrypt for password alone., for Login & Register...



I have added codes in particular files,


@ Config.php :

$config['encryption_key'] = 'aQH76B8hIMuUUVY7ggu1Eo3Rg2KCiqeb';




@ Api.php in Controllers : // Customer Register

public function customer_register_api(){

$path = $_FILES['customer_image']['name'];
$path_tmp = $_FILES['customer_image']['tmp_name'];

$final_name = $path;
move_uploaded_file( $path_tmp, './public/images/customers/'.$final_name );


$customer_name = $_POST['customer_name'];
$customer_image = $final_name;
$customer_address = $_POST['customer_address'];
$customer_city = $_POST['customer_city'];
$customer_state = $_POST['customer_state'];
$customer_pincode = $_POST['customer_pincode'];
$customer_phone_no = $_POST['customer_phone_no'];
$customer_email = $_POST['customer_email'];
$customer_password = md5($_POST['customer_password']);
$status = $_POST['status'];

$customer_password_encrypt = $this->encryption->encrypt($customer_password);

$customer_password_decrypt = $this->encryption->decrypt($customer_password_encrypt);

if(!$customer_name || !$customer_image || !$customer_address || !$customer_city || !$customer_state || !$customer_pincode || !$customer_phone_no || !$customer_email || !$customer_password || !$status){
//$this->response("Enter complete Product information to save", 400);
echo json_encode (
array(
"Status"=>'Failed',
"Error"=>'All Fields are Mandatory',
));
}else{

$result = $this->Model_api->add_customer(array("customer_name"=>$customer_name, "customer_image"=>$customer_image, "customer_address"=>$customer_address, "customer_city"=>$customer_city, "customer_state"=>$customer_state, "customer_pincode"=>$customer_pincode, "customer_phone_no"=>$customer_phone_no, "customer_email"=>$customer_email, "customer_password"=>$customer_password, "status"=>$status));
if($result === 0){
//$this->response("Book information could not be saved. Try again.", 404);
echo json_encode (
array(
"Status"=>'Failed',
//"Seller Details"=>$query->result(),
));
}else{

//$this->response("success", 200);
echo json_encode (
array(
"Status"=>'Success',
//"Seller Details"=>$result->result(),
));
}
}

}




@ Api.php in Controllers : // Customer Login

public function customer_login_api()
{
//$seller_email = $_POST['seller_email'];
$customer_phone_no = $_POST['customer_phone_no'];
$customer_password = $_POST['customer_password'];

//$seller_password = $this->encryption->encrypt($seller_password1);

//$seller_password_encrypt = $this->encryption->encrypt($seller_password);

$query = $this->db->query("SELECT customer_id,customer_name,customer_image,customer_address,customer_city,customer_state,customer_pincode,customer_phone_no,customer_email,status FROM `customers_info` WHERE `customer_phone_no` = '$customer_phone_no' AND `customer_password` = '$customer_password' AND `status` = 'Enable' ");
$num = $query->num_rows();
if($num > 0){
echo json_encode (
array(
"Status"=>'Login Success',
"Customer Details"=>$query->result(),
));
}else{
echo json_encode (
array(
"Status"=>'Login Failed',
"Error"=>'Invalid Credentials OR your account may be Inactive',
));
}
}





@ Api.php in Controllers : // Customer Update

public function customer_update_api(){

$path = $_FILES['customer_image']['name'];
$path_tmp = $_FILES['customer_image']['tmp_name'];

$final_name = $path;
move_uploaded_file( $path_tmp, './public/images/customers/'.$final_name );

$id = $_POST['customer_id'];
$customer_name = $_POST['customer_name'];
$customer_image = $final_name;
$customer_address = $_POST['customer_address'];
$customer_city = $_POST['customer_city'];
$customer_state = $_POST['customer_state'];
$customer_pincode = $_POST['customer_pincode'];
$customer_phone_no = $_POST['customer_phone_no'];
$customer_email = $_POST['customer_email'];
$customer_password = $_POST['customer_password'];
$status = $_POST['status'];

/*$id = $this->put('customer_id');
$customer_name = $this->put('customer_name');
$customer_image = $final_name;
$customer_address = $this->put('customer_address');
$customer_city = $this->put('customer_city');
$customer_state = $this->put('customer_state');
$customer_pincode = $this->put('customer_pincode');
$customer_phone_no = $this->put('customer_phone_no');
$customer_email = $this->put('customer_email');
$customer_password = $this->put('customer_password');
$status = $this->put('status');*/

/*if(!$customer_name || !$customer_address || !$customer_city || !$customer_state || !$customer_pincode || $customer_phone_no || !$customer_email || !$customer_password || !$status){*/

if(!$customer_name){

//$this->response("Enter complete Product information to save", 400);
echo json_encode (
array(
"Status"=>'Failed',
"Error"=>'All Fields are Mandatory',
));
}else{

$result = $this->Model_api->update_customer($id,array("customer_name"=>$customer_name, "customer_image"=>$customer_image, "customer_address"=>$customer_address, "customer_city"=>$customer_city, "customer_state"=>$customer_state, "customer_pincode"=>$customer_pincode, "customer_phone_no"=>$customer_phone_no,
"customer_email"=>$customer_email, "customer_password"=>$customer_password, "status"=>$status));
if($result === 0){
// $this->response("Book information could not be saved. Try again.", 404);
echo json_encode (
array(
"Status"=>'Failed',
//"Seller Details"=>$query->result(),
//$this->response->statusCode(200),
));
//$this->response->statusCode(200);
}else{

//$this->response("success", 200);
echo json_encode (
array(
"Status"=>'Success',
//"Seller Details"=>$result->result(),
));
}
}

}





@ Model_api.php in Model : // Customer Register

<?php

/*** THIS IS MODEL FILE ***/

Class Model_api Extends CI_Model
{
function __construct()
{
parent::__construct();
}


//API call - ADD customer
//API call - add new customer
public function add_customer($data){
if($this->db->insert('customers_info', $data)){
return true;
}else{
return false;
}
}





@ Model_api.php in Model : // Customer Update

//API call - update a customer
public function update_customer($id, $data){
$this->db->where('customer_id', $id);
if($this->db->update('customers_info', $data)){
return true;
}else{
return false;
}
}


}






when i use

$customer_password_encrypt = $this->encryption->encrypt($customer_password);

encrypt is working.,

i use customer_password => varchar(99) at DB, (Not sure 99 is enough or need to increase)

On simple words,
I want to login, register & update with password encrypt & decrypt., only for the field #customer_password

DB @ https://gitlab.com/manigopal/ci-projects..._wings.sql


  Alternative $this->config>set_item($item, $value)
Posted by: simonickalexs - 12-01-2019, 10:20 AM - Forum: CodeIgniter 4 Support - Replies (2)

I notice that this function is not in CI4. But, I need this function to dynamically inject (temporary) array string to public $item = [] from \Config\App.php. Is there any alternative or maybe there's a workaround I'm not noticing?

Thank you!


  Select with string type alias
Posted by: luden - 12-01-2019, 07:41 AM - Forum: General Help - No Replies

Hi,

I try to query with alias a string but it does not work: 

$query=$this->db->query('SELECT id_observation as "1" FROM Observation ');

return $query->result();


but this work well with letters :

$query=$this->db->query('SELECT id_observation as "testcolumname" FROM Observation ');

return $query->result();

I did a print_r($this->db->last_query()); and the result works well directly on phpmyadmin but not within the codeigniter framework
I tried to change some settings to the database configuration but it is still the same problem


  Regarding the HMVC in codeigniter 3x version
Posted by: shahab1992 - 11-30-2019, 09:57 PM - Forum: Addins - Replies (1)

Can wew arrange the folder structure in this way.

Modules
        Admin
            XYZ
               Controller
                Model
                View


  sitemap.xml problem
Posted by: rrashid090 - 11-30-2019, 06:58 AM - Forum: General Help - Replies (2)

Dear Friends,

i am new in CI and dont know much about coding. i have just started a matrimonial site and buy a matrimonial script from ACTIVE ZONE that developed in CI.
I have placed sitemap.xml file in route folder, but it gives error 404.

please help.


  How do you update records in intermediate tables in CI3?
Posted by: kangnguyen - 11-30-2019, 01:22 AM - Forum: General Help - Replies (2)

Tables are Posts and Tags. 
One Post has Many Tags. And One Tag has Many Posts. A so-called 'Many-to-Many' relationship. 
This is solved with a intermediate table (post_tag) with id for post_id and tag_id and a created_at row. 
Now, How do you handle this in CodeIgniter? 
And before you answer. I also wish to learn how to handle updating records in intermediate table. 
As in, I remove a Post or I add a new Tag to a Post. 
Thanks,  Big Grin


  Skipping URI segment to leave default
Posted by: JoellSVK - 11-30-2019, 01:07 AM - Forum: CodeIgniter 4 Support - No Replies

Hello everyone, I would like to ask about skipping URI segment to leave it as default value. I am building API where arguments are filters parameters and some of them I would like to leave sometimes on default like to have URL

Code:
https://localhost/Controller/Method/<blank-to-use-default>/URIsegment2Value

Is it possible? Because now when I leave blank segment it will be skipped but value of the next segment is assigned to the first one. THX Smile


Exclamation PHP 7.4 / CI 4 / Deprecations
Posted by: RedskyThirty - 11-29-2019, 02:23 AM - Forum: CodeIgniter 4 Support - Replies (2)

Hello,

I tried this morning to upgrade to PHP7.4 but I encounter some issues.
I don't know why but sometimes "spark serve" disconnects suddenly. Also, it seems that some pieces of codes are deprecated (example in system/Entity.php, line 605: Array and string offset access syntax with curly braces is deprecated).

Have you planed to support PHP 7.4 for the release? And any idea of the release date?


  How to connect two diffrent diffrent project
Posted by: rahulqdexi - 11-29-2019, 12:13 AM - Forum: CodeIgniter 4 Addins - Replies (1)

I have two different projects (App) one for the admin dashboard and another for the writer dashboard. Both have their own databases. but the problem is that I'm not able to connect both the app so that the writer can get and added file from the admin dashboard and if the writer wants to apply for that then the admin gets a notification for apply from the writer dashboard.



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