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

Should relationships be set in the DB or rely on code?

$
0
0
I am using mysql.  I can optionally add hard coded relationships between tables in mysql by use of foreign key and make it cascade or restrictive for example.  My question is, design wise, would it be bad to rely on the code only without setting the relationships in mysql?  For example, below code doesn't necessarily need hard relationships in mysql to work.

PHP Code:
$post $this->join('post_files''post_files.post_id = posts.id AND post_files.primary = `Y`''inner')
                ->join('post_images''post_images.post_id = posts.id  AND post_images.primary = `Y`''inner')
                ->join('post_descriptions''post_descriptions.post_id = posts.id  AND post_descriptions.primary = `Y`''inner')
                ->find($id); 

Malicious VSCode extensions with millions of installs discovered

Response API asynchronous notification

$
0
0
Masters, I need your help for my API Integration.

This is details step by step of my Web App :
- I will sending all of parameters (like amount billing, code bank, username, email etc) for payment to the API
This is the sample request : 
$params = [              
  'merchantCode' => $merchantCode,              
  'orderType' => $orderType,              
  'orderNum' => $orderNum,              
  'pay' => $pay,              
  'name' => $name,              
  'email' => $email,              
  'phone' => $phone,              
  'notif' => $notifyUrl,              
  'date' => $dateTime,              
  'expired' => $expiryPeriod,              
  'sign' => $sign        
];

- API will sending asynchronous response with detail is it my request is Success or not.

This is the sample of response from API : 

RespCode :SUCCESS RespMessage :Request Transaction Success OrderNum :QWOIJDDJ orderNum :2024061123981 payMoney :10000 platSign :HayKQWNzo2vlKcEZ

- After receiving asynchronous notification, I need to respond to SUCCES the string to check is it my customer already paid the billing or not.

This is the sample of code : 

$res = json_decode(file_get_contents('php://input'), true);$platSign = $res['platSign'];unset($res['platSign']);
Because I need to check my customers already paid the billing or not. So, My question is :
 
How to sending all of API response before, using json_decode(file_get_contents('php://input), true);
I'm so sorry if my English is bad, if you confused with my question please let me know.

The Problem with Using a UUID Primary Key in MySQL

initializeKint() undefined

$
0
0
I copied a CodeIgniter project running on another server into XAMPP to verify the operation, and the following error was displayed:
PHP Code:
Call to undefined method CodeIgniter\Autoloader\Autoloader::initializeKint() 

The backtrace is here:

PHP Code:
SYSTEMPATH\Boot.php 56  —  CodeIgniter\Boot::initializeKint ()
FCPATH\index.php 56  —  CodeIgniter\Boot::bootWeb arguments 
CI_VERSION is 4.1.1、and php version is 8.1.
Let me know if you need any other info.
thanks.

Create A Sidebar Menu using HTML and CSS only

Potential Bug Report: Presenter::show(id) Overwrites Custom Functions

$
0
0
When using CodeIgniter 4, the Presenter show(id) method appears to overwrite custom functions that I have added. This results in a 404 error when trying to access these functions, with the message:

Code:
{
    "status": 404,
    "error": 404,
    "messages": {
        "error": "Nothing found for customFunction1."
    }
}

However, if I configure the routes in Routes.php to exclude the show method using ['except' => 'show'], the custom functions work correctly.

PHP Code:
$routes->presenter('example', ['except' => 'show''filter'=> 'jwt''namespace' => '\App\Controllers\Api']);

$routes->group('example', ['filter'=>'jwt''namespace'=>'\App\Controllers\Api'], static function($routes) {
    $routes->get('customFunction1''Example::customFunction1');
    $routes->get('customFunction2''Example::customFunction2');

}); 

How to exclude only example/(;segment). So additional functions will not be overwritten. Any suggestions?

Code:
+--------+-------------------------+--------------------+--------------------------------------------------------------------+----------------+---------------+
| Method | Route                  | Name              | Handler                                                            | Before Filters | After Filters |
+--------+-------------------------+--------------------+--------------------------------------------------------------------+----------------+---------------+
| GET    | example/(.*)           | »                 | \App\Controllers\Api\Example::show/$1                              | jwt            | jwt           |



https://codeigniter.com/user_guide/incom...comparison

Call to undefined method Config\Autoload::__set_state()

$
0
0
[Image: 18P5uZ.jpg]

[Image: MpzJnC.jpg]

Where this file comes from? this causes the app break.

This happens on all pages, when i try clear cache using php spark cache:clear that files is deleted and then i try to open the app page the file again appears in the cache folder and caused error.

Let me know how to fix it, thanks for advance.

PHP: 8.3.7 — CodeIgniter: 4.5.2 

what does codeigniter 4.6 change in the future

$
0
0
I'm seeing that the developers are working very hard to bring us the 4.6 code, so today I want to ask if there are any changes in 4.6 and what features to expect.

thank you for reading

PSR-4 warning when installing CI4 via Composer

Sessions not playing nice with homerolled PHP site

$
0
0
Hi  y'all,

I have an existing site that was written without using codeigniter using php5.  Yes, we know that we have to upgrade, hence the new codeigniter site.  The current site is huge, and will take months (if not years) to port over to the new codeigniter site.  So, in the meantime, we need to use sessions to maintain a user's status between the two sites, but it is not working.
The sessions are being saved to the same location on the server (for the purposes of this discussion - localhost).  The sites are subdomains, so there should be no issue sharing the session, however I must have an incorrect setting somewhere in codeigniter.  I have verified the non-codeigniter sites by making two different subdomains and sharing sessions between them, so that's not the issue.
In the actual folder where the sessions are stored, the standard php sites save the session as sess_xxx (where xxx is the session id).  The session name is the default PHPSESSID.
When I run codeigniter, it creates a new/separate session using the same session id but as PHPSESSID_xxx (where xxx is the same as the original session id).

in app/config/Cookie
public string $prefix = '';
public bool $secure = false;

in app/config/Session
public string $cookieName = 'PHPSESSID';

Any help?

Date comparison - Less than 24 Hours in Models

$
0
0
I have the following queries in CodeIgniter to find any data in which the date_created field is less than 24 hours. 
Here is my code in Models


Code:
public function checkDeposit($preOrder)
    {
        return $this->db->table('deposit')
        ->where('preorder_code', $preOrder)
        ->where('status', 0)
        ->where('date_created <', strtotime(date('YmdHis'), INTERVAL 1 DAY))
        ->get()
        ->getRowArray();
    }


But the above query is not working.
What I want in short is, return all rows which the date_created is less than 24 hours.
My date_created format is Unix TimeStamp (1718204380)
How to get data less than 24 hours in Models ?

What is the best practice for querying a DB with 2 or 3 tables

$
0
0
I have 3 tables:

BlogTable
BlogTagTable - Record one row for each tag in a blog post. Eg. if 3 tags, will be three lines in the db with reference to the tagId and BlogId.
TagTable - master list of possible tags with names.

When I querybuild to get all blog posts I could make one large join. This will produce a large result though. For instance, if a blog post has 10 tags, I would get 10 lines back. I would assume that all query code would go in the BlogModel even if querying tags, right?

Alternatively, I could query the Blog table first, get all blog posts and then for each blog post, query the tags used. Would both query code go in BlogModel or just the blog query in BlogModel and tag query in TagModel?

I also thought of method chaining like getBlog()->withTags()->paginate() etc; I would pass the blog object to tags and then add an array of used tags in the blog post. What are your thoughts?

I appreciate all of your comments or suggestions!

session_write_close() AND MySQL server has gone away ERROR

$
0
0
My project is on the shared hosting. And provider set limit for mysql server timeout for 60 sec. (parameter [mysqld] wait_timeout=60)
And I use database to store session data
If my script runs more then 60 sec I got error mysqli_sql_exception: MySQL server has gone away

1 Stack trace:
2 system\Database\MySQLi\Connection.php(331): mysqli->query('UPDATE `p_ses...', 0)
3 system\Database\BaseConnection.php(735): CodeIgniter\Database\MySQLi\Connection->execute('UPDATE `p_ses...')
4 system\Database\BaseConnection.php(649): CodeIgniter\Database\BaseConnection->simpleQuery('UPDATE `p_ses...')
5 system\Database\BaseBuilder.php(2509): CodeIgniter\Database\BaseConnection->query('UPDATE `p_ses...', Array, false)
6 system\Session\Handlers\DatabaseHandler.php(228): CodeIgniter\Database\BaseBuilder->update(Array)
7 #5 [internal function]: CodeIgniter\Session\Handlers\DatabaseHandler->write('1pr4kn1qnrslngb...', '__ci_last_regen...')
8 #6 [internal function]: session_write_close()
9 #7 {main}

$db->reconnect() in the script do not solve the problem.
The core cant connect to mysqlserver to update session data.

Can you help me?

PS  CI  4.5.2, 4.3.1  php 8.1 apache

Shield 1.1.0


Recommendation .htaccess customization

$
0
0
I would avoid a static specification of protocols (www) redirection and recommend using the trailing slash as standard for SEO purposes. Officially they say it doesn't make a difference (as long as it's consistent), but in my experience and if you look at the biggest websites, they use a trailing slash. %{REQUEST_SCHEME} was introduced in Apache 2.4.


Code:
# Redirect Trailing Slashes...
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_URI} !.*/$
RewriteRule ^(.*)$ %{REQUEST_SCHEME}://%{HTTP_HOST}/$1/ [L,R=301]

# Rewrite "www.example.com -> example.com"
RewriteCond %{HTTP_HOST} ^www\.(.+)$ [NC]
RewriteRule ^%{REQUEST_SCHEME}://%1%{REQUEST_URI} [R=301,L]

No direct output from $this->renderSection

$
0
0
In the help itself, <?= is used already. Nevertheless, the function renderSection outputs the content directly via echo. It would be helpful if the value was only returned or if it could at least be controlled via a parameter.

This would have the advantage that, for example, if a page title is not set, you could maintain a standard for example with ?: parameter.

Code:
<title><?= $this->renderSection('title') ?></title>


Code:
<title><?= $this->renderSection('title') ?: 'Fallback title' ?></title>

validation_errors

$
0
0
Why the function validation_errors() in form helper does not work with In-Model Validation?
I must enter this in any controller to work: $this->session->setFlashdata('_ci_validation_errors', $model->errors());
Kind regards

How to add variables from a second custom env file to the default one

$
0
0
I would need to load an additional env file in addition to the default env file.

It is possible to load an env file with dedicated values and merge them with the default env file values, e.g. .env.myenv?

Latest version of Codeigniter 4.5.2

mysql: getting a grip on dates, times, and timezones

Viewing all 14343 articles
Browse latest View live


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