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

Username
  

Password
  





Search Forums

(Advanced Search)

Forum Statistics
» Members: 15,467
» Latest member: noviardi
» Forum threads: 70,556
» Forum posts: 362,849

Full Statistics

Latest Threads
How to include TinyFileMa...
Forum: General Help
Less than 1 minute ago
» Replies: 1   » Views: 22
Zip library "Allowed memo...
Forum: Libraries & Helpers
15 minutes ago
» Replies: 6   » Views: 124
How to create Controller ...
Forum: General Help
29 minutes ago
» Replies: 14   » Views: 273
GET_LOCK and database ses...
Forum: General Help
48 minutes ago
» Replies: 7   » Views: 214
how create an self instal...
Forum: Installation & Setup
54 minutes ago
» Replies: 6   » Views: 470
Entity fields not saving ...
Forum: CodeIgniter 4 Support
3 hours ago
» Replies: 0   » Views: 12
[Solved] Unable to genera...
Forum: CodeIgniter 4 Support
4 hours ago
» Replies: 3   » Views: 150
Important News about Jim ...
Forum: News & Discussion
5 hours ago
» Replies: 58   » Views: 13,093
form_checkbox doesn't che...
Forum: Libraries & Helpers
7 hours ago
» Replies: 2   » Views: 101
Update database without r...
Forum: General Help
8 hours ago
» Replies: 1   » Views: 70

 
  Entity fields not saving when using 'business logic' method.
Posted by: larry-ns - 3 hours ago - Forum: CodeIgniter 4 Support - No Replies

Some help / advice requested, please.

Using the 'UserModel' model and 'User' entity examples duplicated from the CodeIgniter4 docs, I have encountered a problem. The saving of the entity to the the database works as expected. But when I add a 'business logic' method to the User entity class, the field involved is not included in the insert query. As follows:

<?php namespace App\Entities;
  use CodeIgniter\Entity;
  class User extends Entity{   
   // without a method
   }

User
array(0) { } ["dates":protected]=> array(3) { [0]=> string(10) "created_at" [1]=> string(10) "updated_at" [2]=> string(10) "deleted_at" } ["casts":protected]=> array(0) { } ["attributes":protected]=> array(5) { ["username"]=> string(11) "usertest101" ["password"]=> string(8) "12121212" ["pass_confirm"]=> string(8) "12121212" ["email"]=> string(18) "usertest101@me.com" ["registerform"]=> string(8) "Register" } ["original":protected]=> array(0) { } ["_cast":"CodeIgniter\Entity":private]=> bool(true) }

Database
SELECT 1 FROM `users` WHERE `username` = 'usertest101' LIMIT 1

INSERT INTO `users` (`username`, `password`, `email`, `created`, `updated`) VALUES ('usertest101', '12121212', 'usertest101@me.com', '2020-01-20 10:38:19', '2020-01-20 10:38:19')

Correct query with password included.

But when a method is added to hash the password, the password is not included in the query.
<?php namespace App\Entities;

  use CodeIgniter\Entity;

  class User extends Entity{   
    protected function setPassword(string $pass)
    {
        $this->password = password_hash($pass, PASSWORD_BCRYPT);
        return $this;
    }       
  }

User
array(0) { } ["dates":protected]=> array(3) { [0]=> string(10) "created_at" [1]=> string(10) "updated_at" [2]=> string(10) "deleted_at" } ["casts":protected]=> array(0) { } ["attributes":protected]=> array(4) { ["username"]=> string(11) "usertest102" ["pass_confirm"]=> string(8) "12121212" ["email"]=> string(18) "usertest102@me.com" ["registerform"]=> string(8) "Register" } ["original":protected]=> array(0) { } ["_cast":"CodeIgniter\Entity":private]=> bool(true) ["password"]=> string(60) "$2y$10$y/K7qeUIilBrZeeDaCr6b.t2UZZy/CoHPFShNTNz3sSdzKPR/iop2" }

Database
SELECT 1 FROM `users` WHERE `username` = 'usertest102' LIMIT 1

INSERT INTO `users` (`username`, `email`, `created`, `updated`) VALUES ('usertest102', 'usertest102@me.com', '2020-01-20 10:57:26', '2020-01-20 10:57:26')

The password field is no longer included in the query. Does anyone have any suggestions? The hashed entity can be read OK from the entity. 

Thank you.


  how to upload a json file?
Posted by: Kaushik - 10 hours ago - Forum: CodeIgniter 4 Support - No Replies

I tried with code, but its showing "The filetype you are attempting to upload is not allowed.". Can someone please help me with this

public function do_upload()
        {
                $config['upload_path']      = './uploads/';
                $config['allowed_types']    = 'jpg|png|php|json';
                $config['detect_mime'] = 'True';
                $config['max_size']        = 1024;

                $this->load->library('upload', $config);
                $data['value']=$this->input->post('company_id');
                if ( ! $this->upload->do_upload('userfile'))
                {
                        $data['error']=$this->upload->display_errors();
                        $data['results']=$this->Users_model->get_brands("1");
                        $this->load->view('add_gajson', $data);
                }
                else
                {
                        $data['results']=$this->Users_model->get_brands("1");
                        $this->load->view('add_gajson', $data);
                }
        }


  How to include TinyFileManager
Posted by: mohs3n - Yesterday, 10:43 PM - Forum: General Help - Replies (1)

Hi

How can I include TinyFileManager in my Codeigniter project?

URL: https://tinyfilemanager.github.io/docs/


  notify send
Posted by: richb201 - Yesterday, 03:13 PM - Forum: General Help - No Replies

Is there anyway I can use notify send from CI to popup a message to the user? Or is that a Linux only feature?


  Zip library "Allowed memory size"
Posted by: ZoeF - Yesterday, 01:10 PM - Forum: Libraries & Helpers - Replies (6)

Hey all

I seem to be a hitting a snag in my program. I have a image gallery that has the function to download the images. When people are downloading 5-15 images there is no issue what so ever. But as soon as the try 50+ (or something close) I get a error. "Fatal error: Allowed memory size of 134217728 bytes exhausted". It links back to the zip library line 410.

I looked online but the only things I found that where a so called solution was to change the php.ini file and increase the limitations. The limitations are curently set to 128 MB and as we are using a hosting service that does not allow changes in these files I am at a loss I suppose.

Is there any solution or diffrent thing I can try to get this to work? Maybe a function to split the download up in bite size chunks? Or something that takes it's time and does not eat up memory? Any idea will be appreciated.

I tried the "ini_set('memory_limit','1G');". But when I do that I recieve "Fatal error: Maximum execution time of 30 seconds exceeded". After I added the time limit and got the memory limit error again.

Just for a note the biggest folder of images at this time is around 680MB. But in the future it might go around 2-3 GB


  Update database without reloading view? (Involving Google Maps API)
Posted by: nfoboy - Yesterday, 10:34 AM - Forum: General Help - Replies (1)

I have my View working so that it shows an infoWindow with a clickable "thumb up/thumb down" for a property that a User is looking at.

However, I cannot get the logic to work for calling an appropriate function within the model or controller such that I am able to run an update to the database reflecting the Users desire.

I do not want the page to have to reload, so all I want is that ability to tell the controller (or model) when a state change to the thumb occurs.


What is the right way to approach doing this?

Controller

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

class Maptest extends CI_Controller {
    
    function __construct() {
        parent::__construct();
        
        // Load form validation ibrary & user model
        $this->load->library('form_validation');
        $this->load->model('mapModel');
        
        // User login status
        $this->isUserLoggedIn = $this->session->userdata('isUserLoggedIn');
    }
    
    public function index($incoming = null){
        //need to load a view
        
        if($incoming == 5) {
            
            return;
        }
        
        //test function for sending data to view
        $data = array('lat' => 32.7157,
                        'long' => -117.1611 ,
                        'zoom' => 10                    );
                        
        
        $data = $this->mapModel->getPropertyMarkers();
        
        //var_dump($data);
        
        $data['markers'] = $this->mapModel->getPropertyMarkers();
        
        
        $string = $this->load->view('maptest/index', $data , FALSE);

    }
    
    
}


Model

Code:
<?php defined('BASEPATH') OR exit('No direct script access allowed');
class MapModel extends CI_Model{
    function __construct() {
        // Set table name
        $this->table = 'users';
    }
    
    public function getPropertyMarkers($data = null) {
        //ideally this function will return the property markers
        //with $data having different arugments to cull out the properties
        //not desired...
        
        //OR there will be a list of propert ID's in $data that will then let this function get
        //the desired rows from the property table
        
        //for now, just return all rows
        
        $this->db->select('lat, long, property_name');
        //$this->db->from('property');
        $query = $this->db->get('property', 5, 5);
        
        return $query->result_array();
        
    }
}

View:  in myFunction is where I "want" to call a Controller or Model function using the various procedures that "should" work at calling a function from a View, but $this->CI =& getInstance() fails miserably  when the code generates within the script for creating the map and markers, as the $this is referring to the View, and I can't figure out how to pass in the pointer to the Controller... 


Code:
<head>
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/4.7.0/css/font-awesome.min.css">
<style>
.fa {
  font-size: 50px;
  cursor: pointer;
  user-select: none;
}

.fa:hover {
  color: darkblue;
}
</style>
<style>
#map_canvas {
  height: 300px;
  width: 50%;
  margin: 0px;
  padding: 0px
}
</style>
</head>

<div id="map_canvas"></div>

<script>
var geocoder;
var map;
var markers = [];
var infowindow;

function initMap() {
      var city = {lat: 32.8244410, lng:-117.109917};
      map = new google.maps.Map(document.getElementById("map_canvas"), {
      center: new google.maps.LatLng(city.lat, city.lng),
      zoom: 11,
      mapTypeId: google.maps.MapTypeId.ROADMAP
    });
  infowindow = new google.maps.InfoWindow();
    
// ------------  This code builds the markers for display of incoming variable 'markers
    <?php $i = 1; ?> //for variable name production    
        <?php foreach ($markers as $marker): ?>  //this creates each position variable brought in the passed variable
        var <?php echo 'place'.$i; ?> = {
            geometry: {
              location: {
                lat: <?php echo $marker['lat'] ?>,
                lng: <?php echo $marker['long'] ?>
              }
            },
            name: <?php echo '"'.$marker['property_name'].'"' ?>
        };
        
        createMarker(<?php echo 'place'.$i; ?>);
        
        <?php $i += 1; ?>     
    <?php endforeach; ?>
}
google.maps.event.addDomListener(window, "load", initMap);

function createMarker(place) {
  var placeLoc = place.geometry.location;
  var marker = new google.maps.Marker({
    map: map,
    position: place.geometry.location
  });
  markers.push(marker);

  google.maps.event.addListener(marker, 'click', function() {
    infowindow.setContent("<div>" + place.name +
    "<br><input type='submit' id='butSubmit' value='A Function'"+
    "onclick='BarFind()'><div id='bar'></div></div>"+
    '<i onclick="myFunction(this)" class="fa fa-thumbs-up"></i>'
    );
    infowindow.open(map, this);
  });
}


function myFunction(x) {
  x.classList.toggle("fa-thumbs-down");
  //add code to call a controller function
  //--------------------------------------------
  // I can' get any PHP code that makes a reference to Controller to work here
}

function BarFind() {
  document.getElementById('bar').innerHTML = "called BarFind()";
  var myDiv = document.createElement('div');
  document.body.appendChild(myDiv);
  myDiv.innerHTML = <?php echo '"' ?>.$answer.<?php echo '"' ?>;

}
</script>
<script async defer
    src="https://maps.googleapis.com/maps/api/js?key=THIS IS MY KEY&callback=initMap">
    </script>


  cannot use contruct.it gives error in both model and controller
Posted by: adil - Yesterday, 04:18 AM - Forum: CodeIgniter 4 Support - No Replies

when i use construct in model it give me this error.

ErrorException

Undefined variable: db [url=https://www.google.com/search?q=ErrorException+Undefined+variable%3A+db][/url]


Model:

<?php namespace App\Models;

use CodeIgniter\Model;
use CodeIgniter\Database\ConnectionInterface;

    class My_model extends Model {
protected $db;

public function __construct()
            {
    parent::__construct();
                  $db = \Config\Database::connect();

            }


public function get_allnames() {

        $query = $db->query('SELECT A.* tbl_products');
        $results = $query->getResultArray();
        return $results;
    }

}

Iam i doing it wrong?


  Codeigniter Form Validation is_unique on Updation
Posted by: ysarsilmaz - 01-18-2020, 03:55 PM - Forum: General Help - No Replies

I have a Form that can change the user name, email and password fields where membership information is kept. These areas are also uniq.

1- The user can change the three fields above, but these changed fields must be uniq except for the password. After all, it doesn't make sense for security to write an email address of an existing user in the system.
2 - Even if the user just changes his password, I get the error that user name already exists in the database.

How should I logic in this problem?


  Routes are conflicting with each other. Is it possible to set priority?
Posted by: desbest - 01-18-2020, 02:35 PM - Forum: Libraries & Helpers - Replies (1)

Code:
$route['(:any)/(:any)/(:any)/(:any)'] = 'main/user/$1/$2/$3/$4';
$route['fetch/(:any)/(:num)/(:any)'] = 'fetch/$1/$2/$3';
$route['fetch/(:any)/(:any)/(:num)'] = 'fetch/$1/$2/$3';


Above is what I have in my routes.php

The route on the first line is making the below routes stop working. Any URL with fetch/apple/banana/123 will make the first line be followed instead of the third one.

Is it possible to set priority in routing, so if more than one rule is applicable, the rule that is above the other ones is what is used first?


  How to integrate Python with PHP?
Posted by: christaliise - 01-18-2020, 06:13 AM - Forum: General Help - Replies (9)

I understand many websites use PHP together with Python but I doubt if they also use CodeIgniter.

I want a language that will facilitate what PHP cant do.

Does anybody know how to integrate Python with PHP?

I would like interaction similar to HTML.



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