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

Username
  

Password
  





Search Forums

(Advanced Search)

Forum Statistics
» Members: 17,933
» Latest member: Juchrist
» Forum threads: 71,498
» Forum posts: 367,161

Full Statistics

Latest Threads
update form validation
Forum: CodeIgniter 4 Support
1 hour ago
» Replies: 2   » Views: 34
Paypal Integration
Forum: General Help
1 hour ago
» Replies: 1   » Views: 13
Can not use CURL in codei...
Forum: CodeIgniter 4 Support
2 hours ago
» Replies: 2   » Views: 52
sending mail in html
Forum: General Help
3 hours ago
» Replies: 1   » Views: 40
Email Class TLS 587 SASL ...
Forum: General Help
3 hours ago
» Replies: 2   » Views: 55
Setup for Apache on Ubunt...
Forum: CodeIgniter 4 Support
3 hours ago
» Replies: 0   » Views: 19
suggest to change the pos...
Forum: CodeIgniter 4 Feature Requests
6 hours ago
» Replies: 0   » Views: 14
web hosting and ci4
Forum: Installation & Setup
6 hours ago
» Replies: 0   » Views: 18
Query Builder "Where" wit...
Forum: General Help
6 hours ago
» Replies: 7   » Views: 313
affect vs effect
Forum: Lounge
8 hours ago
» Replies: 11   » Views: 7,373

 
  Controller validation works, Config/Validation - Syntax error
Posted by: BilltheCat - 05-19-2020, 08:59 AM - Forum: CodeIgniter 4 Support - Replies (3)

Maybe this will be an obvious question, but I can't see what's wrong with it.

If I use this validation rule in my Controller, it works fine.  Doing basically the same thing in Config/Validation, and my IDE gives me a syntax error message

Controller: 

PHP Code:
        // validate form input
        $this->validation->setRules([
            'identity' => [
                'label' => str_replace(':'''lang('Auth.login_identity_label')),
                'rules' => 'required'
                ],
            'password' => [
                'label' => str_replace(':'''lang('Auth.login_password_label')),
                'rules' => 'required'
                ]
        ]); 


Config/Validation:
PHP Code:
public $login = [
            'identity' => [
                'label' => str_replace(':'''lang('Auth.login_identity_label')),
                'rules' => 'required'
                ],
            'password' => [
                'label' => str_replace(':'''lang('Auth.login_password_label')),
                'rules' => 'required'
                ]
        ]; 


Syntax error:
[Image: kGeO1B.jpg]


  curl lib response getBody return binary string
Posted by: sandip002 - 05-19-2020, 05:52 AM - Forum: CodeIgniter 4 Discussion - Replies (1)

Today I'm trying to fetch some testing data from "https://jsonplaceholder.typicode.com/todos/1",
but when I get a response and try to get data it will give binary string.

Code:
        $this->client = \Config\Services::curlrequest([
            'base_uri' => 'https://jsonplaceholder.typicode.com'
        ]);

        $data = $this->client->get('/todos/1');

        d( $data->getBody() ); // also try getJSON()

output:

Code:
���RPP*-N-�LQ�R0�q3̒̒�T%+��Ԝ���b���N�U+H��-�I-IiIK�)N�7��S

is anything I'm doing wrong.

EDIT:

I'm trying to get data in json or array format from api.

ALREADY TRIED THINGS: 

Code:
        $data = $this->client->get('/todos/1');

        dd( $data->getBody() ); // give binary string,

        dd( json_decode( $data ) ); // error: json_decode() expects parameter 1 to be string, object given

        dd( $data->getJSON() ); // error: Failed to parse json string, error: "Malformed UTF-8 characters, possibly incorrectly encoded".


  webp and gdlib
Posted by: starchild - 05-19-2020, 05:21 AM - Forum: Libraries & Helpers - Replies (3)

Is there a way we can resize/save as webp using gblib in CI 3?

I can't find anything anywhere.....


  prepared statements
Posted by: joseCarlos - 05-19-2020, 03:57 AM - Forum: CodeIgniter 4 Support - Replies (4)

Hi again.



So I was trying to improve safety in my project by using prepared statements, and it just doesn't seems to work.

would you be so kind as to take a look and see if you find anything out of place?



this is the model function

 

PHP Code:
public static function insert_contactos($data_array)
  {
    $db db_connect();

    $pQuery $db->prepare(function ($db) {
      return $db->table('contactos')
        ->insert([
          'ativo_contacto' => '',
          'nome_contacto' => '',
          'cod_cliente_contacto' => ''
        ]);
    });

    $result $pQuery->execute(
      $data_array['ativo_contacto'],
      $data_array['nome_contacto'],
      $data_array['cod_cliente_contacto']
    );

    return $result;
  

This is the controller function
PHP Code:
  public function insert()
  {
    if ($this->request->isAJAX()) {


      $data_array['ativo_contacto'] = $_POST['ativo_contacto'];
      $data_array['nome_contacto'] = $_POST['nome_contacto'];
      $data_array['cod_cliente_contacto'] = $_POST['cod_cliente_contacto'];


      if (Contactos_model::insert_contactos($data_array)) {
        echo 'success';
      } else {
        echo 'fail';
      }
    }
  

after running in debug mode, i get this exception from

Exception has occurred.
ErrorException: Uninitialized string offset: 1
"C:\xampp\htdocs\pgp4\system\Database\Query.php"



As always, thank you for your time.

Messed with it again by trying a manually built statement, but still hangs on that exception, the thing is it is inserting the data correctly, but it stops afterwards.


  [SOLVED] Model Update Fails
Posted by: 68thorby68 - 05-19-2020, 03:51 AM - Forum: CodeIgniter 4 Support - No Replies

Hi,

I'm trying to update 1 record in my table. But $this->update($id, $data) just fails.

I've tried every which way but ... well my frustration ...

My db (has aprox 50 records and player_id 12 does exist)

TABLE `player_master` (
  `player_id` int(10) unsigned NOT NULL,
  `first_name` varchar(50) NOT NULL,
  `last_name` varchar(50) NOT NULL,
  `image_path` varchar(200) NOT NULL,
  `telephone` varchar(15) DEFAULT NULL,
  `email` varchar(50) DEFAULT NULL,
  `handicap` int(3) NOT NULL,
  PRIMARY KEY (`player_id`) USING BTREE
) ENGINE=InnoDB DEFAULT CHARSET=utf8;


My model

PHP Code:
namespace App\Models\Admin;

use 
CodeIgniter\Model;

class 
Players extends Model {
    
    protected 
$table      'player_master';
    protected $primaryKey 'player_id';

    protected $returnType 'array';

    function 
player ($id) {
        return 
$this->where('player_id'$id)
        ->
find();
    }
    
    function 
player_update($id$data) {
        return    
$this->update($id$data);
    }

My code
PHP Code:
$players_func = new \App\Models\Admin\Players;                
$this->$data['player_name'] = $players_func->player($id);

//Player Data returned OK

$id=12;
$data=[
    
'image_path'=>'path_to_my_image'
    
];


$this-$data['update']= $players_func->player_update($id$data);

//This just fails - no error, just fails 

Note: the function player_update does not receive the var $id and $data.


Please help I am at a total loss ....

OK, so after thinking I'm going mad (more mad). I think I've sussed this out.

By defining allowed fields in the class, the update seems to have worked OK.

My model now reads
PHP Code:
namespace App\Models\Admin;

use 
CodeIgniter\Model;

class 
Players extends Model {
    
    
protected $table      'player_master';
    protected $primaryKey 'player_id';
    
    
protected $returnType 'array';
    protected $allowedFields = ['image_path'];

    function player ($id) {
        return $this->where('player_id'$id)
        ->find();
    }

meaning I can call update directly, without having to create a function,

ie.

PHP Code:
$players_func = new \App\Models\Admin\Players;                
$this
->$data['player_name'] = $players_func->player($id);

//Player Data returned OK

$id=12;
$data=[
    'image_path'=>'path_to_my_image'
    ];


$this-$data['update']  $players_func->update($id$data); 

Hope this help others


  email notification doesn't work anymore
Posted by: skummet - 05-19-2020, 02:54 AM - Forum: Lounge - Replies (2)

It looks like the email notification doesn't work anymore. I no longer receive email when somebody reply to a thread I'm subscribed to.


  SQL injection question with codeigniter
Posted by: ashilnayak2 - 05-18-2020, 09:51 PM - Forum: General Help - Replies (1)

I'm working on a project using codeigniter where I've got a form that writes to a database.
I'm using CI's Active Record Class with form validation rules for the input and escaping the inputs as well.
The db driver being used is mysql. Am I doing enough to prevent sql injection attacks or missing the point on how to keep this site safe?


  Problems in views when reinstall appserv
Posted by: Edel - 05-18-2020, 05:58 PM - Forum: CodeIgniter 4 Support - Replies (2)

Hello everyone. I am developing in CI 4. I changed the appserv version recently.
I saved my project from the old www folder and copied it into the new www in my new installation. but when I send variables to the view it doesn't recognize them.

PHP Code:
$result->adverts $adverts//ad list
$dat['result'] = $result;
$view = \ Config\Services::renderer();
$view->setData($dat);
$data['previews'] = $view->render('tools/previews'); 

In my view : APPPATH/Views\tools\previews.php
Code:
<?    
print_r($result); //line 2
print_r($result->adverts);//line 3
foreach($result->adverts as $advert){
        $time = Time::parse($advert->date);        
?>
    <div class=" preview col-lg-2 col-md-2 col-sm-3 col-xs-12">
            <div class="box">
                <a href="<?=$advert->getHref(NULL, $m_category)?>"> //line 9

the error that return is "ErrorException, Undefined variable: advert" in APPPATH/Views\tools\previews.php at line 9
the lines 2 and 3 don't print anything.

why if lines two an three does not print anything code is executed inside the foreach

I have not changed anything within my project. I suppose the problem is related to some php or apache configuration.
php 7.3.10

Thanks in advance.


  Where to place Services?
Posted by: Zark - 05-18-2020, 01:59 PM - Forum: CodeIgniter 4 Support - Replies (3)

I am wondering what's the best practice or convention for a location wherein to store custom 'Services'?
E.g. Authentication service.

If I may suggest a change to docs, adding in this info under Services would be helpful.


  Change output in post_system Event
Posted by: mickrus - 05-18-2020, 04:33 AM - Forum: CodeIgniter 4 Support - Replies (1)

In CI3 i used display_override - hook like this:

PHP Code:
function placeholders()
{
    
$CI =&get_instance();
    
$buffer $CI->output->get_output();
 
    
$buffer str_replace(array('{field1}','{field2}'), array('data1','data2'), $buffer);
 
    
$CI->output->set_output($buffer);
    
$CI->output->_display();
}
?>

How can I access from CI4 Event's (post_system) controller to output?



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