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

display pdf file in browser in CodeIgniter 4

$
0
0
What is the simplest way to display a pdf type file in the browser in CodeIgniter 4?   My file is located in public/files/filename.pdf.

Does CodeIgniter Shield Hash Passwords After Inserting User Data?

$
0
0
Hi everyone!

I'm studying the CodeIgniter Shield code and noticed that the password hash seems to be done after inserting the user's data into the database. Could someone confirm if this is correct and explain why this approach was chosen?Here is a part of the UserModel and User entity code showing this:UserModel.php

UserModel.php
PHP Code:
protected $afterInsert   = ['saveEmailIdentity'];
protected 
$afterUpdate   = ['saveEmailIdentity'];

protected function 
saveEmailIdentity(array $data): array
{
    if (
$this->tempUser === null) {
        return 
$data;
    }

    if (
$this->tempUser->id === null) {
        
$user $this->find($this->db->insertID());
        
$this->tempUser->id $user->id;

        
$user->email $this->tempUser->email ?? '';
        
$user->password $this->tempUser->password ?? '';
        
$user->password_hash $this->tempUser->password_hash ?? '';

        
$user->saveEmailIdentity();
        
$this->tempUser null;

        return 
$data;
    }

    
$this->tempUser->saveEmailIdentity();
    
$this->tempUser null;

    return 
$data;



User.php
PHP Code:
public function saveEmailIdentity(): bool
{
    if (empty(
$this->email) && empty($this->password) && empty($this->password_hash)) {
        return 
true;
    }

    
$identity $this->getEmailIdentity();
    if (
$identity === null) {
        
$this->createEmailIdentity([
            
'email' => $this->email,
            
'password' => '',
        ]);

        
$identity $this->getEmailIdentity();
    }

    if (!empty(
$this->email)) {
        
$identity->secret $this->email;
    }

    if (!empty(
$this->password)) {
        
$identity->secret2 service('passwords')->hash($this->password);
    }

    if (!empty(
$this->password_hash) && empty($this->password)) {
        
$identity->secret2 $this->password_hash;
    }

    
$identityModel model(UserIdentityModel::class);

    try {
        
$identityModel->save($identity);
    } catch (
DataException $e) {
        if (
in_array($e->getMessage(), [
            
lang('Database.emptyDataset', ['insert']),
            
lang('Database.emptyDataset', ['update']),
        ], 
true)) {
            return 
true;
        }

        throw 
$e;
    }

    return 
true;


Why is the password hashed after insertion and not before?

Running Codeigniter Queue

$
0
0
Hi @kenjis 
i tried running queue using this command 

Code:
php spark queue:work emails

then i got this error:

Code:
havelsan@computer playground % php spark queue:work emails

CodeIgniter v4.4.8 Command Line Tool - Server Time: 2024-05-20 13:20:49 UTC+07:00

Listening for the jobs with the queue: emails



[TypeError]

pg_ping(): Argument #1 ($connection) must be of type ?PgSql\Connection, false given

at SYSTEMPATH/Database/Postgre/Connection.php:139

Backtrace:
  1    SYSTEMPATH/Database/Postgre/Connection.php:139
      pg_ping(false)

  2    VENDORPATH/codeigniter4/queue/src/Models/QueueJobModel.php:56
      CodeIgniter\Database\Postgre\Connection()->reconnect()

  3    VENDORPATH/codeigniter4/queue/src/Handlers/DatabaseHandler.php:74
      CodeIgniter\Queue\Models\QueueJobModel()->getFromQueue('emails', [...])

  4    VENDORPATH/codeigniter4/queue/src/Commands/QueueWork.php:139
      CodeIgniter\Queue\Handlers\DatabaseHandler()->pop('emails', [...])

  5    SYSTEMPATH/CLI/Commands.php:65
      CodeIgniter\Queue\Commands\QueueWork()->run([])

  6    SYSTEMPATH/CLI/Console.php:46
      CodeIgniter\CLI\Commands()->run('queue:work', [...])

  7    ROOTPATH/spark:102
      CodeIgniter\CLI\Console()->run()

what's wrong?

Shield Not Displaying error messages on invalid username and password

$
0
0
I have the lastest versions of CI (4.5.1) and Sheild (1.0.3) installed.
When a user attempts to login with an invalid password no error messages are displayed. It simply reloads the login screen blank.
I have customised the view but this is the same if I use my customised view or the one that comes 'out of the box'.
Does anyone have any ideas? Am I missing something really simple (probable!)

Why Does CodeIgniter Shield Hash Passwords After User Data Insertion?

$
0
0
Hi everyone!

I'm studying the CodeIgniter Shield code and noticed that the password hash seems to be done after inserting the user's data into the database. Could someone confirm if this is correct and explain why this approach was chosen?Here is a part of the UserModel and User entity code showing this:UserModel.php

UserModel.php
PHP Code:
protected $afterInsert  = ['saveEmailIdentity'];
protected 
$afterUpdate  = ['saveEmailIdentity'];

protected function 
saveEmailIdentity(array $data): array
{
    if ($this->tempUser === null) {
        return $data;
    }

    if ($this->tempUser->id === null) {
        $user $this->find($this->db->insertID());
        $this->tempUser->id $user->id;

        $user->email $this->tempUser->email ?? '';
        $user->password $this->tempUser->password ?? '';
        $user->password_hash $this->tempUser->password_hash ?? '';

        $user->saveEmailIdentity();
        $this->tempUser null;

        return $data;
    }

    $this->tempUser->saveEmailIdentity();
    $this->tempUser null;

    return $data;



User.php
PHP Code:
public function saveEmailIdentity(): bool
{
    if (empty($this->email) && empty($this->password) && empty($this->password_hash)) {
        return true;
    }

    $identity $this->getEmailIdentity();
    if ($identity === null) {
        $this->createEmailIdentity([
            'email' => $this->email,
            'password' => '',
        ]);

        $identity $this->getEmailIdentity();
    }

    if (!empty($this->email)) {
        $identity->secret $this->email;
    }

    if (!empty($this->password)) {
        $identity->secret2 service('passwords')->hash($this->password);
    }

    if (!empty($this->password_hash) && empty($this->password)) {
        $identity->secret2 $this->password_hash;
    }

    $identityModel model(UserIdentityModel::class);

    try {
        $identityModel->save($identity);
    } catch (DataException $e) {
        if (in_array($e->getMessage(), [
            lang('Database.emptyDataset', ['insert']),
            lang('Database.emptyDataset', ['update']),
        ], true)) {
            return true;
        }

        throw $e;
    }

    return true;


Why is the password hashed after insertion and not before?

Disallowed characters in URI

$
0
0
I am working on a search bar. There is a form, on submit the text from the input gets encoded with the JavaScript encodeURIComponent function and redirected with

Code:
window.location.href = /search/yourtexthere

This is routed to a controller with

Code:
$routes->get('search/(:segment)', 'Search::word/$1');

If I search for special characters, for example: []{}, I get the "The URI you submitted has disallowed characters" error message.
If I copy the url from the address bar, the characters are properly encoded to %5B%5D%7B%7D. All of these characters match the default regular expression in the App.php at $permittedURIChars.
When I copy just the []{} characters from the browser address bar, they stay as is, not encoded.

I tested 

Code:
preg_match('/\A[a-z 0-9~%.:_\-]+\z/iu', '%5B%5D%7B%7D');
preg_match('/\A[a-z 0-9~%.:_\-]+\z/iu', '[]{}'); 
They return 1 and 0, as expected.


I tried type in the the full url with the encoded string, same result.
I made a link on a test page where the []{} was encoded with PHP's urlencode, rawurlencode and http_build_query, with the same result.
If I set $permittedURIChars = ''; it works but it is not recommended. With this setting, if I dd(site_url(uri_string())); the url, it is properly encoded.

I use 
CodeIgnire 4.5.1
MacOS 14.5
It was tested on Firefox 126, Firefox Developer Edition 127, Safari 17.5, Safari Technology Preview 17.4 with the same result.

I assumed, maybe it is an OS/browser thing, because when I copied only the []{} characters from the url, they stayed not encoded.
But when I used dd to print out the url, I saw that the characters are encoded as they should be.

My question is, am I doing something wrong or is this a bug in CodeIgniter? Big Grin

installation problem for v4.4.8

$
0
0
Im using composer to install previous version

Code:
composer create-project codeigniter4/appstarter:4.4.8 myproject

After that I'm running this command

Code:
php spark env development

and get this error

This "system/bootstrap.php" is no longer used. If you are seeing this error message,
the upgrade is not complete. Please refer to the upgrade guide and complete the upgrade.
See https://codeigniter4.github.io/userguide...e_450.html
PHP Fatal error: Uncaught Error: Undefined constant "ENVIRONMENT"

Then I manually created the .env file.

But the error is still there.

Please help

update sql table in phpmyadmin when the ckeditor updated.

$
0
0
Hi
Im new to codeigniter3 and blade. and i have some trubble to update my sql database when the ckeditor content updated.
here i have a view page which send report_id as hidden variable to controller.
then in controller i fetch related column values of sql database in phpmyadmin to ckeditor content.
thats ok and in page load the sql table content displayed on ckeditor content.
now, when i updated the ckeditor, i nead to sql database table be updated.
but i cant do that.
could you please provide any guid to solve that?
below is my code parts:
//--start view file: PROFIL_YONETIMI_BOS_DUZENLE.blade.php
PHP Code:
{!! form_open('#',array('class'=>'text-left mt-2','id'=>'BOS_FORM','onsubmit'=>"ajax(this,'".$user_base_url."/profil/profil_yonetimi_BOS_duzenle');return false;")) !!}
 <
input hidden type="hidden" name="AJAX_ISLEM" value="BOS_DUZENLE">
<
input hidden type="hidden" name="REPORT_D" value="{{$AKTIF_PROFIL->id}}">
<
div class="panel panel-primary tabs-style-1">
    <div class="panel-body tabs-menu-body main-content-body-right bg-white border">
    <div class="tab-content">
      {!! FORM_Create($BOS,$AKTIF_PROFIL) !!}
    </div>
    </div>
</
div>
<
div class="row">
  <div class="col-md-12 col-lg-3 offset-lg-9 mt-3">
    <button class="btn btn-primary btn-with-icon float-right btn-block"><class="typcn typcn-news"></i>{{ceviri('rapor_yonetimi_duzenle')}}</button>
  </div>
</
div>
{!! 
form_close() !!} 

//--end view file: PROFIL_YONETIMI_BOS_DUZENLE.blade.php
// start controller
PHP Code:
    public function profil_yonetimi_BOS_duzenle(){
        $this->user_oturum_yetki_kontrol();
        $REPORT_ID $this->input->post('REPORT_ID');
        $REPORT_DB=$this->user_model->GENEL_ICERIK($REPORT_ID$ISSUE='profil_yonetimi_BOS');
        $FORM_KURALLARI $this->FORM_KURALLARI_RAPOR('BOS',$REPORT_DB);  
        $this
->ICERIK_VERISI['REPORT_DB']=$REPORT_DB;
        $this->ICERIK_VERISI['BOS'] = $FORM_KURALLARI;
        $this->ICERIK_VERISI['sayfa'] = "profil_yonetimi_BOS_duzenle";
        $this->ICERIK_VERISI['kapsam'] = "user.PROFIL.kapsam.profil_yonetimi";
        $this->blade->display('user/PROFIL/PROFIL_YONETIMI_BOS_DUZENLE'$this->ICERIK_VERISI); // Load the new view

        if($this->input->is_ajax_request()){
            $AJAX_ISLEM=$this->input->post('AJAX_ISLEM');

            if($AJAX_ISLEM=="BOS_DUZENLE"){
                $FORM_KURALLARI $this->FORM_KURALLARI_RAPOR('BOS',$REPORT_DB);                  
                $FORM_VERISI
['profil_yonetimi_BOS']=$FORM_KURALLARI['BOS'];
                $BOS_DUZENLEME_SORGUSU=$this->user_model->BOS_DUZENLE($REPORT_ID,$FORM_VERISI);                
            
}
        }else{
            $this->ICERIK_VERISI['sayfa']="profil_yonetimi_BOS_duzenle";
            $this->ICERIK_VERISI['kapsam']="user.PROFIL.kapsam.profil_yonetimi";
            $this->ICERIK_VERISI['BOS']=$this->user_model->GENEL_ICERIK($REPORT_ID$ISSUE='profil_yonetimi_BOS');
            $this->blade->display('user/PROFIL/PROFIL_YONETIMI_BOS_DUZENLE',$this->ICERIK_VERISI);
        }    
    


//end controller
// start model
   
PHP Code:
public function BOS_DUZENLE($ID$FORM_VERISI) {
        $this->db->select('profil_yonetimi_BOS');
        $this->db->from('kullanici_profilleri');
        $this->db->where('id'$ID);
        $query $this->db->get();
        if ($query->num_rows() > 0) {
            return $query->row()->profil_yonetimi_BOS;
          } else {
                 return null;
             }
          }
            public function GENEL_ICERIK($ID$ISSUE) {
                // Make sure to escape the column name to prevent SQL injection
                if (!in_array($ISSUE, ['profil_yonetimi_BOS', ...])) {
                    return null// Return null if the column name is not allowed
                }
            
                $this
->db->select($ISSUE);
                $this->db->from('kullanici_profilleri');
                $this->db->where('id'$ID);
                $query $this->db->get();
            
                
if ($query->num_rows() > 0) {
                    $row $query->row();
                    return $row->$ISSUE;
                } else {
                    return null// Return null if no record is found
                }
            

//end model

Codeigniter 4 ajax post results in 404 error

$
0
0
I am trying to handle a form submit using the JQuery ajax function on localhost xampp. However, the following always results in a 404 page not found error:


Code:
$(document).on("click", ".iconsTop .iconst", function (e) {
    var idfilter = $(this).attr("id");;
    $.ajax({
      type: "POST",
      dataType: "text",
      url: "filter",
      data: { filter_id:idfilter },
      cache: false,
      success: function (data) {
        $('.maincontact').empty().append(data);
      }
    });
  });

Controller:


PHP Code:
class App_home extends BaseController
{
    public function filter()
    {
        echo 'ok';
    }


Router


PHP Code:
use CodeIgniter\Router\RouteCollection;
$routes->setAutoRoute(true);
$routes->get('filter''App_home::filter'); 

After submitting the form, I always get the following error in Google Chrome's page inspector:

Quote:jquery-3.7.1.min.js:2 POST http://localhost/app/public/filter 404 (Not Found)



Quote:404 Controller or its method is not found: Filter::index

Output pdf in other page

$
0
0
hi ,

hi have a pdf that work fine,it  open in browser  with tcpdf . there is a way to redirect to a page (base_url() f.e.) and show pdf in other page ? i try :

Code:
        //Close and output PDF document
        $pdf->Output('Doa Bloccato', 'I');

        $response = response();

        $response->setHeader('Content-Type', 'application/pdf');

        return redirect()->to(base_url());

but doesn't show pdf , if i comment return line pdf are show.

set exception 400 to 404

$
0
0
I have error BadRequest with code 400
how to handle it to force show as 404?

can you help?

CodeIgniter\HTTP\Exceptions\BadRequestException

How validate this rules

$
0
0
I have form, if checkbox in my form (print) is checked (has value 'yes') i need validate email, if not dont validate

My rules like that


Code:
'print' => [
'label' => ' ',
'rules' => 'permit_empty|in_list[yes]',
],

'email' => [
'label' => ' ',
'rules' => 'required_with[print]|max_length[30]|valid_email'
]


When i valudate without print i got error from valid_email

JPG or PNG to WebP converter simple class

$
0
0
Encountered an issue with converting JPG or PNG images to WebP format during upload. I tried using the Intervention Image library and other libraries but got stuck. Below is a simple CodeIgniter 4 library class that converts a JPG or PNG image to WebP during upload and deletes the original uploaded file. Here is the code:



PHP Code:
<?php
namespace Travo\Admin\Libraries;

class 
ToWebp
{
    private $fullPath;
    private $outPutQuality;
    private $deleteOriginal;
    private $extension;
    private $newFileFullPath;

    public function __construct()
    {
        // Initialize any necessary properties here
    }

    public function convert($fullPath$outPutQuality 100$deleteOriginal true)
    {
        $this->fullPath $fullPath;
        $this->outPutQuality $outPutQuality;
        $this->deleteOriginal $deleteOriginal;

        if (!file_exists($this->fullPath)) {
            throw new \InvalidArgumentException('File does not exist');
        }

        $this->extension pathinfo($this->fullPathPATHINFO_EXTENSION);
        $this->newFileFullPath str_replace('.' $this->extension'.webp'$this->fullPath);

        $sourceImage $this->createImageFromPath($this->fullPath);

        if ($sourceImage) {
            $this->convertToWebp($sourceImage);
            imagedestroy($sourceImage);

            if ($this->deleteOriginal) {
                unlink($this->fullPath);
            }

            $newPathInfo explode('/'$this->newFileFullPath);
            $finalImage end($newPathInfo);

            return (object) [
                'fullPath' => $this->newFileFullPath,
                'file' => $finalImage,
                'status' => 1,
            ];
        } else {
            throw new \RuntimeException('Given file cannot be converted to WebP');
        }
    }

    private function createImageFromPath($path)
    {
        switch (exif_imagetype($path)) {
            case IMAGETYPE_PNG:
                return imagecreatefrompng($path);
            case IMAGETYPE_JPEG:
                return imagecreatefromjpeg($path);
            case IMAGETYPE_GIF:
                return imagecreatefromgif($path);
            default:
                return false;
        }
    }

    private function convertToWebp($sourceImage)
    {
        imagepalettetotruecolor($sourceImage);
        imagealphablending($sourceImagetrue);
        imagesavealpha($sourceImagetrue);
        imagewebp($sourceImage$this->newFileFullPath$this->outPutQuality);
    }
}
?>

To init , $webp = new ToWebp(); 
$result = $webp->convert($orginal_file_path, 70, false);
I have implemented this in my Codeigniter Blog 

Problme with Curl request and CSRF protection

$
0
0
Good morning, afternoon or evening, sorry for my English in advance.


I am porting to CI4 an old web application, and I am having the following problem when calling the API using Curl from another web application, it is made with CI3.

From that other application, although with different domain is on the same server, at a given time I make a POST request through Curl, but the communication fails and in the log generated by Curl I see that the problem is by CSRF. (I change the IP and URL for security reasons)

Code:
*  Trying 127.0.01:443...
* Connected to subdomain.myweb.com (127.0.0.1) port 443 (#0)
* ALPN, offering h2
* ALPN, offering http/1.1
* SSL connection using TLSv1.3 / TLS_AES_256_GCM_SHA384
* ALPN, server accepted to use h2
* Server certificate:
*  subject: CN=OPNsense.localdomain; C=NL; ST=Zuid-Holland; L=Middelharnis; O=OPNsense self-signed web certificate
*  start date: Feb  5 21:12:35 2024 GMT
*  expire date: Mar  8 21:12:35 2025 GMT
*  issuer: CN=OPNsense.localdomain; C=NL; ST=Zuid-Holland; L=Middelharnis; O=OPNsense self-signed web certificate
*  SSL certificate verify result: self-signed certificate (18), continuing anyway.
* Using HTTP2, server supports multiplexing
* Connection state changed (HTTP/2 confirmed)
* Copying HTTP/2 data in stream buffer to connection buffer after upgrade: len=0
* Using Stream ID: 1 (easy handle 0x563eb1e89480)
> POST /index.php/api/koolpass.php HTTP/2
Host: ubdomain.myweb.com
accept: */*
keep-alive: timeout=100, max=100
connection: keep-alive
content-length: 2491
content-type: application/x-www-form-urlencoded

* old SSL session ID is stale, removing
* Connection state changed (MAX_CONCURRENT_STREAMS == 8)!
* We are completely uploaded and fine
< HTTP/2 403
* Added cookie PHPSESSID="70a3d8a88b2a1cf540d6eb984696275d" for domain ubdomain.myweb.com, path /, expire 0
< set-cookie: PHPSESSID=70a3d8a88b2a1cf540d6eb984696275d; path=/; secure; HttpOnly
< expires: Thu, 19 Nov 1981 08:52:00 GMT
< cache-control: no-store, no-cache, must-revalidate
< pragma: no-cache
< content-type: text/html; charset=UTF-8
< content-length: 563
< date: Wed, 22 May 2024 11:28:38 GMT
< server: OPNsense
<
<html><head><title>CSRF check failed</title>
            <script>
              $( document ).ready(function() {
                  $.ajaxSetup({
                  'beforeSend': function(xhr) {
                      xhr.setRequestHeader("X-CSRFToken", "WHdKODJaeEdpd3BlemFjQStXQmVVdz09" );
                  }
                });
              });
            </script>
            </head>
                  <body>
                  <p>CSRF check failed. Your form session may have expired, or you may not have cookies enabled.</p>
                  </body></html>* Connection #0 to host educafestival.koolfest.com left intact


I have tried different configurations of CSRF, the same with Curl, but nothing, it keeps on failing and the truth is that I am already desperate.

This is the Curl code from the platform that sends the request:

PHP Code:
$ch curl_init();
 
$params http_build_query($params);
 
curl_setopt($chCURLOPT_URL$url);
 
curl_setopt($chCURLOPT_RETURNTRANSFER1);
 
curl_setopt($chCURLOPT_POSTFIELDS$params);
 
curl_setopt($chCURLOPT_SSL_VERIFYHOSTfalse);
 
curl_setopt($chCURLOPT_SSL_VERIFYPEERfalse);
 if (
strtoupper($method) == 'POST'curl_setopt($chCURLOPT_POSTtrue);

 
curl_setopt($chCURLOPT_COOKIESESSIONtrue);
 
curl_setopt($chCURLOPT_COOKIEJAR'/tmp/cookie.txt');
  curl_setopt($chCURLOPT_COOKIEFILE'/tmp/cookie.txt');

 
$headers = [
 
'Keep-Alive: timeout=100, max=100',
 
'Connection: keep-alive'
 
];
 
curl_setopt($chCURLOPT_HTTPHEADER$headers);

 
// Verbose
 
$file fopen('curl.txt''w+');
 
curl_setopt($chCURLOPT_VERBOSEtrue);
 
curl_setopt($chCURLOPT_FILE$file);
 
curl_setopt($chCURLOPT_STDERR$file);

 if (
$apiKey)
 {
 
curl_setopt($chCURLOPT_HTTPHEADER, array(
 
'Authorization: ' $apiKey
 
));
 }

 
$resp curl_exec($ch);
 
curl_close($ch);
 return 
$resp


And this is how I have configured the filter for CSRF, I even tried commenting it out.

PHP Code:
public array $globals = [
        'before' => [
            // 'honeypot',
            'csrf' => ['except' => ['api/*''index.php/api/*']],
            // 'invalidchars',
        ],
        'after' => [
            //'toolbar',
            // 'honeypot',
            // 'secureheaders',
        ],
    ]; 


Thanks in advance

why the retrived hidden value in controller is null?

$
0
0
i have a codeigniter3 project with following view:


PHP Code:
{!! form_open('#',array('class'=>'text-left mt-2','id'=>'BOS_FORM','onsubmit'=>"ajax(this,'".$user_base_url."/profil/profil_yonetimi_bos_duzenle');return false;")) !!}
    <input hidden type="hidden" name="AJAX_ISLEM" value="BOS_DUZENLE">
    <input hidden type="hidden" name="ID" value="{{___ssl_encrypt(@$ID)}}">
    <div class="report-id-display">Report ID: {{ ___ssl_encrypt(@$ID) }}</div>
    <div class="panel panel-primary tabs-style-1">
        <div class="panel-body tabs-menu-body main-content-body-right bg-white border">
            <div class="tab-content">
                    {!! FORM_OLUSTUR($BOS,@$REPORT_DB) !!}
            </div>
        </div>
    </div>
    <div class="row">
        <div class="col-md-12 col-lg-3 offset-lg-9 mt-3">
            <button class="btn btn-primary btn-with-icon float-right btn-block"><class="typcn typcn-news"></i>{{ceviri('rapor_yonetimi_duzenle')}}</button>
        </div>
    </div>
{!! 
form_close() !!} 

i retrive the ID value in controller by


PHP Code:
$REPORT_ID=___ssl_decrypt($this->input->post('ID')); 
but thats null when i get a print of that .

whats the problem and how should i correct?

any guide could you provide?

Shared Hosting to VPS

$
0
0
Hey,

I'm quite new to using CodeIgniter (PHP frameworks in general) but so far I like it better than any other framework. In addition, the project is already becoming quite complex and that is great.

Now this application runs on Shared Hosting, but I also have a VPS that is not being used (6 Cores, 16GB RAM and 500GB Data) with a PLESK license. This is where I actually want to move my CodeIgniter project.

My question is actually how I can start working with version control. I've done some searching here and there, but I'm not really any wiser. I want to be able to continue working on the application in development mode without other users being bothered.

In addition, it is easy with cronjobs and SSH.

Is there anyone who is willing/able to provide a brief explanation of this or who can enlighten me?

Thank you in advance and it is much appreciated.

Custom error message for all rules

$
0
0
Hi there!
I was looking for a way to use a single error message in the validation class for all rules. I managed to do it with few changes in system/Validation/Validation.php

The following lines in function setRules can be modified like this:

 -- Original -- 
PHP Code:
                if (array_key_exists('errors'$rule)) {
                    $this->customErrors[$field] = $rule['errors'];
                    unset($rule['errors']);
                

-- Modified --
PHP Code:
                if (array_key_exists('errors'$rule) && is_array($rule['errors'])) {
                    $this->customErrors[$field] = $rule['errors'];
                    unset($rule['errors']);
                } elseif(array_key_exists('error'$rule) && is_string($rule['error'])) {
                    $this->customErrors[$field] = $rule['error'];
                    unset($rule['error']);
                

And also function getErrorMessage:

-- Original --

PHP Code:
        // Check if custom message has been defined by user
        if (isset($this->customErrors[$field][$rule])) {
            $message lang($this->customErrors[$field][$rule]);
        } elseif (null !== $originalField && isset($this->customErrors[$originalField][$rule])) {
            $message lang($this->customErrors[$originalField][$rule]);
        } else {
            // Try to grab a localized version of the message...
            // lang() will return the rule name back if not found,
            // so there will always be a string being returned.
            $message lang('Validation.' $rule);
        

-- Modified --

PHP Code:
        // Check if custom message has been defined by user
        if (isset($this->customErrors[$field][$rule])) {
            $message lang($this->customErrors[$field][$rule]);
        } elseif (null !== $originalField && isset($this->customErrors[$originalField][$rule])) {
            $message lang($this->customErrors[$originalField][$rule]);
        } elseif(is_string($this->customErrors[$field])) { 
            $message $this->customErrors[$field];
        } else {
            // Try to grab a localized version of the message...
            // lang() will return the rule name back if not found,
            // so there will always be a string being returned.
            $message lang('Validation.' $rule).'kur';
        

I hope you will find this useful and this future find its way to the official release.

ajax does not activated

$
0
0
i have following form submission in codeigniter3 view blade php code:


PHP Code:
{!! form_open('#',array('class'=>'text-left mt-2','id'=>'BOS_FORM','onsubmit'=>"ajax(this,'".$user_base_url."/profil/profil_yonetimi_bos_duzenle');return false;")) !!}
<
input  type="hidden" name="AJAX_ISLEM" value="BOS_DUZENLE">
<
input type="hidden" name="ID" value="{{@$AKTIF_PROFIL->id}}">

......
{!! 
form_close() !!} 


but onsubmit, the ajax does not activated to send the hidden value ID to controller.
why and how should i fix that?

HTML Tags You Might Not Know About

ci setup

$
0
0
I am new to codeigniter try to resetup a ci-4 project from live server(hostinger) to my local system on xampp server, faild to do the same getting an error like 
PHP Warning:  require_once(D:\Xampp\htdocs\scholaracad\application\public\index.php): Failed to open stream: No such file or directory in D:\Xampp\htdocs\scholaracad\application\system\Commands\Server\rewrite.php on line 43
[Fri May 24 17:31:53 2024] PHP Fatal error:  Uncaught Error: Failed opening required 'D:\Xampp\htdocs\scholaracad\application\public\index.php' (include_path='.;C:\php\pear') in D:\Xampp\htdocs\scholaracad\application\system\Commands\Server\rewrite.php:43
Stack trace:
#0 {main}
  thrown in D:\Xampp\htdocs\scholaracad\application\system\Commands\Server\rewrite.php on line 43

insted of opening default route, the project is trying to open index.php file every time.
Looking for help, thanks in advance.
Viewing all 14353 articles
Browse latest View live


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