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

CodeIgniter Tasks - Register Task from Module

$
0
0
Hi,
Is it possible to add a scheduled task from a Module. 
I looked at the Modules Config Registrar class but this seems to only allow returning arrays of values.
Any guidance would be appreciated.
Thanks,
Luke

Set a $_GET value

$
0
0
PHP Code:
localhost?foo=bar
$_GET
['foo'] = 'baar'
echo 
$_GET['foo']; // 'baar'

localhost?foo=bar
$_GET
['foo'] = 'baar'
echo 
$this->request->getGet('foo'); // 'bar' 


I encountered a loop because I couldn't update the $_GET parameters during the same request.

PHP Code:
# Solution? 
$this->request->setGet('foo''bar');  
$this
->request->setPost('foo''bar');  

Is this possible?

Validation messages displaying differently between local environment & server

$
0
0
I am using Docker. 
When I run the project on local environment(windows 11), it gives validation error messages as 
The username field is required.
The password field is required.
But the same project on server(Linux) shows error messages as 
validation.required
validation.required
Both are running on PHP 8.3 and this is CI4 project
This is the part of the code that use for form validation.
$rules = [
                'username' => [
                    'rules' => 'required|string|min_length[5]|max_length[30]',
                    'errors' => [
                        'required' => lang('validation.required', ['field' => lang('users.usersInputUsername')]),
                    ],
                ],
                'password' => [
                    'rules' => 'required|min_length[6]',
                    'errors' => [
                        'required' => lang('validation.required', ['field' => lang('users.usersInputPassword')]),
                    ],
                ]

      ];
if($this->validate($rules){
}
Is there anyone who knows why is this occur?
          

CLI Apps with Codeigniter?

$
0
0
Hi there!
I love CodeIgniter and it is often my first choice of framework.
But here is the thing: I want to create a powerful PHP-based static Site Generator.

I have a few options including Laravel Zero (Not the Laravel framework), Symfony Console component (not the framework), MiniCLI framework, or start from scratch.

But I have been wondering, CodeIgniter comes with the spark file and lets you generate commands that can be executed in the command line.

While that will serve the purpose, the issue is that I can't seem to find the way to set the application name/desc or the commands to show when running "php spark" in the command line.

Is there any way around it or should I skip the idea of using codeigniter for this one?

Issue with credit card validation

$
0
0
Hi! I have this validation rule:

Code:
'cardNumber' => [
        'label' => lang('App.label_credit_card_number'),
        'rules' => 'required|valid_cc_number[amex, unionpay, carteblanche, dinersclub, discover, interpayment, jcb, maestro, dankort, mir, troy, mastercard, visa, uatp, verve, cibc, rbc, tdtrust, scotia, bmoabm, hsbc]'
      ],

and I have this error:

Code:
Validation.valid_cc_number

Why?

Thanks for help me.

Need help with $uri->addQuery

$
0
0
Hi,

I have a view that shows a list of bookings. By default that list shows the bookings to come in a future date. I want to offer the possibility to filter that list so a user can see all the bookings (including the ones in the past) and can filter on those who are still open to registration. I am using a get route to pass the search query. Things are working well, my controller gets the search query and I get the results that are filtered properly. 

I am now at the stage where I want to add the filters on the view. I am using links to add a parameter / or to remove one. I thought I'd use the $uri->addQuery to create the links. And I created a little helper that should return the modified url to each links. But It looks like the returns 'are cumulative' and I am not making sense of what's happening.

Here's my helper:
PHP Code:
function addParamQuery($param,$value) {
    $uri current_url(true);
    $uri->addQuery($param$value);
    return $uri;

    
And in my view, my filter links using the helper:
PHP Code:
    <a href="<?= addParamQuery('registration', 'open') ?>">show open bookings</a>
    <a href="<?= addParamQuery('date', 'all') ?>">show also past dates</a

But here's the html I am getting when I am viewing /agenda :
Code:
<a href="http://localhost:8080/en/agenda?registration=open">show open bookings</a>
<a href="http://localhost:8080/en/agenda?registration=open&amp;date=all">show also past dates</a>

I was expecting to get for the second link only agenda?date=all . Why is registration=open part of the url returned?

It looks like each call 'builds' on the previous rather than starting from the current url (without any parameter). I am not understanding why... and what I need to do to fix it.  Huh

Can anyone help?

New Install

$
0
0
Hello,

I am new to Code Igniter. I'm developing a Content Management System. My question, is there a way to do a custom configuration.php file so that I don't have to share the ENV files or anything to make it easier for users to update their Database credentials? Also -- i'd like to build a custom index.php that goes into the app. I'm going to be using Ioncube to encrypt my files, so I want to make it rather easy to accomplish all this. The script I'll be using for Licensing actually is found here.

I'm new to the MVC type framework. Any guidance would be well appreciated!

Thank you Smile

Codeigniter 4 V 4.5.1 $this->db problem

$
0
0
I updated to version 4.5.1 and now $this->db is protected, how can I query tables other than the one set in the model in $table?
Until previous versions it was sufficient to do:
PHP Code:
$this->db->table('mytable')...  
and it was possible, now what should I do to maintain the same functionality?
Am I forced to change the value of $table before each query in different tables?

What is the correct direction?

update sql database based on edited content of ckeditor in codeigniter3

$
0
0
hi everyone
in codeigniter3 i develop such a project:

in view page i have a ckeditor that displays some content from database in phpmyadmin
now, suppose user change its content on web page.
now i want the new changes applyed to related sql table in phpmyadmin and new content and displayed when the page is re-loaded
how should i define new content of ckeditor as a variable to use for update in sql database

in fact i cannot read the current edited content of ckeditor truely
can any one help me to solve?
thanks in advance

sql sorgu farklılıkları

$
0
0
When I examine the logs on mssql, some queries
Some queries come in dynamic variable structure while some queries are forwarded in plain tsql.

Plain structure:
SELECT * FROM test_table where id='1' and status='OPEN'

Variable structure :
(@1 tinyint,@2 varchar(8000))SELECT * FROM [test_table] WHERE [id]=@1 AND [status]=@2

How do I ensure that queries are always sent in a variable structure when using activated record?

How does codeigniter manage this variable?



If I send where to the id column, which is the primary and identy column in the table, it produces a parameterized result. But if I send where to the service column
logging a straight sql query.;




PHP Code:
$this->db->select('*');
$this->db->where('service','55');
$this->db->order_by('id','asc');
$this->db->get('test_table')->row();

echo 
$this->db->last_query();

echo 
"-----<br>-----";

$this->db->select('*');
$this->db->where('service','55');
$this->db->order_by('id','asc');
$this->db->get('test_table')->row();

echo 
$this->db->last_query();


//Active Record Get Last Query:
SELECT FROM "test_table" WHERE "id" '55' ORDER BY "id" ASC
----------
SELECT FROM "test_table" WHERE "service" '55' ORDER BY "id" ASC 

//Mssql Query History Log
(@1 varchar(8000))SELECT FROM [test_tableWHERE [id]=@1 ORDER BY [idASC
SELECT 
FROM "test_table" WHERE "servis" '55' ORDER BY "id" ASC 

CLI Error

$
0
0
Hi,

I just installed a fresh copy of CI4 using the Composer App Starter package.

I then attempted to install CI Shield via composer which works fine up to running the command

Code:
php spark shield:setup

I then get the following error:

Code:
CodeIgniter v4.5.1 Command Line Tool - Server Time: 2024-05-17 17:15:38 UTC+01:00

PHP Fatal error:  Declaration of CodeIgniter\Log\Logger::emergency(Stringable|string $message, array $context = []): void must be compatible with PsrExt\Log\LoggerInterface::emergency($message, array $context = []) in /home/development/vendor/codeigniter4/framework/system/Log/Logger.php on line 162

I tried deleting the vendor folder and composer.lock file and installing again but the problem persists.

Not had this issue before and I have installed the App Starter and Shield lots of time.

Luke

C4 Latest version shield manage users

$
0
0
So i have been playing around with the newest version of shield and really be running in a circle with the manage users, so shield creates a user model default I have made a create user and delete user and update user, create users was a bit tricky using just the code example here the update user has me just stumped, if i edit user then it says username taken, or password required.

My question is how to validate when info has changed so if I edit user name John profile but dont change his username it shouldn't say username taken same for email



public function update($id)
{

    $users = auth()->getProvider();
    $user = $users->findById($id);

    $validation = \Config\Services::validation();
    $validation->setRules([
        'username' => 'required|is_unique[users.username]',
        'email' => 'required|is_unique[auth_identities.secret]'
    ]);

    $data = [
        'username' => $this->request->getPost('username'),
        'email' => $this->request->getPost('email')
    ];

    if (!$user->hasChanged()) {
        return redirect()->back()
            ->with("message", "Nothing to update.");
    }

    if ($validation->run($data)) {

        $user->fill([
            'username' => $data['username'],
            'email' => $data['email']
        ]);

        $users->update($user);

        return redirect()->to("admin/dashboard/manage-users")
                ->with("message", "User updated.");

    }
    return redirect()->back()
            ->with('errors', $validation->getErrors())
            ->withInput();
}

$this->responseCreated() method not found

$
0
0
I was listening this to tutorial about shield and api: https://www.youtube.com/watch?v=0sdbsbOW...G&index=31

At 10:05 the author uses $this->respondCreated(). I am using CI 4.5.1 I cannot see that method. I also do not see it in the documentation. Was that some previous version of am I missing something?

Thank you for your help!

Codeignighter not resonding

$
0
0
hi all, i must have put something in incorrectly. Please help there a smiley where i ensure the issue.

PHP Code:
if ($possibleResponse instanceof ResponseInterface) {
            
$this->response $possibleResponse;
        } else {
            try {
                    if (
$possibleResponse instanceof ResponseInterface) {
            
$this->response $possibleResponse;
        } else {
            try {
                :)  
$this->response $this->handleRequest($routesconfig(Cache::class), $returnResponse);
            } catch (
ResponsableInterface|DeprecatedRedirectException $e) {
                
$this->outputBufferingEnd();
                if (
$e instanceof DeprecatedRedirectException) {
                    
$e = new RedirectException($e->getMessage(), $e->getCode(), $e);
                }

                
$this->response $e->getResponse();
            } catch (
PageNotFoundException $e) {
                
$this->response $this->display404errors($e);
            } catch (
Throwable $e) {
                
$this->outputBufferingEnd();

                throw 
$e;
            }
        }
$this->response $this->handleRequest($routesconfig(Cache::class), $returnResponse);
            } catch (
ResponsableInterface|DeprecatedRedirectException $e) {
                
$this->outputBufferingEnd();
                if (
$e instanceof DeprecatedRedirectException) {
                    
$e = new RedirectException($e->getMessage(), $e->getCode(), $e);
                }

                
$this->response $e->getResponse();
            } catch (
PageNotFoundException $e) {
                
$this->response $this->display404errors($e);
            } catch (
Throwable $e) {
                
$this->outputBufferingEnd();

                throw 
$e;
            }
        } 

Get folder path instead of url path

$
0
0
i i want download file from server , i create a link:

Code:
<a href="<?=WRITEPATH.'uploads/report/'.$doa->id.'/'. $doa->numero ?>" class="btn btn-info ms-3" download>DOWNLOAD FILE</a>



But if i see the link i have  :

[CODE]

https://my_site/home/uz2lnhpx/domains/my_subdomain/public_html/codeigniter/writable/uploads/report/32/1003_General.xlsx
[/CODE]
instead of :

Code:
/home/uz2lnhpx/domains/my_subdomain/public_html/codeigniter/writable/uploads/report/32/1003_General.xlsx
And chrome show that file there isn't...

Entity Insert Issue

$
0
0
Greetings to all. I’m working on optimizing my code and have opted to implement the Entity class. However, I’m dealing with a ‘genres’ table and a ‘books_genres’ table. Below is the code I’m currently using:


PHP Code:
namespace Library\Entities;

use 
CodeIgniter\Entity\Entity;

class 
BookEntity extends Entity
{
    protected $datamap = [];
    protected $dates  = ['publication_date''created_at''updated_at''deleted_at'];
    protected $casts  = [
        'genres' => '?array'
    ];

    public function getGenres()
    {
        $bookGenresMdl = new \Library\Models\BooksGenresModel();
        $genres $bookGenresMdl->where('book_id'$this->id)->findAll();
        $genresList = [];
        foreach ($genres as $genre) {
            $genresList[] = $genre['genre_id'];
        }
        return $genresList;
    }

    public function setGenres($genres)
    {
        if ($this->id) {
            $genres unserialize($genres);
            $bookGenresMdl = new \Library\Models\BooksGenresModel();

            $bookGenresMdl->where('book_id'$this->id)->delete();

            foreach ($genres as $genre) {
                $bookGenresMdl->insert([
                    'book_id' => $this->id,
                    'genre_id' => $genre
                
]);
            }
        }
        return $this;
    }



When updating existing records, the process works fine. However, when attempting to add a new record, although the task completes, the ID is not generated in time, leading to a failure. Is there a solution to this issue, or must I generate the ID within the model or controller?

Codeignighter not resonding

$
0
0
Good day,

I am new to the codeigniter forum, I am trying to create a new topic but don't know where.

My question is, I am having a 400 error "Bad Request" from XAMPP, when I am trying to access my codeiginiter project.
The home controller works: https://localhost/project/
But, every other directory shows a 400 Error: https://localhost/project/*

I have set the proper the routing and config file.
PHP 8.2
CODEIGNITER 4

Where can I find a reliable service to convert PDFs to other formats?

$
0
0
I frequently work with PDF documents and need to convert them into different formats like Word, Excel, or JPG. I’m looking for a dependable online tool that offers high-quality and efficient conversions. Can you recommend a suitable website?

Caching Question

$
0
0
I'm using file caching to cache some of my pages, and it's working well - I'm simply using a line like this in each relevant controller. 
PHP Code:
$this->cachePage(DAY); 

I want to implement an Admin panel that lets me delete the cache for a specific page, but I can't work out what CI4 is using as the key. I've tried the md5 hash of the full URL of the page (e.g. https://www.example.org/blog/a-specific-blog-post) and also just the path (/blog/a-specific-blog-post), but neither seems to be the value being hashed.
How do I generate the key for a specific cached page so that I can then use the delete($key) method of the Caching Driver to delete the cache for that page?

Myth Auth register a new user

$
0
0
hello

I am using Myth Auth library and i have created a new register form  since i dont want to use the default one , and i was wondering which method i can use to register the new user , basically in the authcontroller there is attemptRegister() function but im not sure if there is another way around
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>