Welcome, Guest |
You have to register before you can post on our site.
|
|
|
URL translation, is it possible? |
Posted by: superior - 02-27-2021, 02:49 AM - Forum: CodeIgniter 4 Support
- No Replies
|
 |
Hello,
I've been trying to translate one of my URL's in example '/nl/wachtwoord-vergeten/' in English it should be '/en/forgot-password/'. The translation switch is working correctly, i'm able to change the App\defaultLocale.
In my baseController i've setup the following:
PHP Code: $language = \Config\Services::language(); $language->setLocale( $lang };
This is working correctly, i've checked this by calling getLocale() in my view to be shure it's loaded. Next up is routing the URL, i've been reading about route_to(); and absolutly love it! Makes it so much easier to manage.
My routes looks like this:
PHP Code: $routes->add("{locale}/" . lang('Auth.forgotPasswordUri'), 'Accounts::resetPassword', ['as' => 'forgot_password']);
Now i must admit, don't know if you can use the lang() helper in the routes, but we can always change this if needed.
Did anyone had the same issue and resolved this, would love to get this working
Kind Regards
|
|
|
Using the new Encryption library throws "MySQL server has gone away" error |
Posted by: asantoli - 02-26-2021, 09:04 AM - Forum: Libraries & Helpers
- Replies (1)
|
 |
I have code that currently runs without error. When I introduce the "Encryption" library and call the encrypt or decrypt functions, the MySQL call to update the ci_sessions table fail with the error "MySQL has gone away". Note: MySQL ssl is being used. Its seems like the openssl used in Encryption library is overwriting the mysqli key or chiper?
Does anyone have an history with this or ideas? Thanks
The Code is currently running on:
PHP 5.6
CI 3.1.6
MySQL 5.6
Here is the database.php setup
'dbdriver' => 'mysqli',
'dbprefix' => '',
'pconnect' => FALSE,
'db_debug' =>FALSE,
'cache_on' => FALSE,
'cachedir' => '',
'char_set' => 'utf8',
'dbcollat' => 'utf8_general_ci',
'swap_pre' => '',
'encrypt' => array(
'ssl_key' => $db_ssl_key,
'ssl_cert' => $db_ssl_cert,
'ssl_ca' => $db_ssl_ca,
),
'compress' => FALSE,
'stricton' =>FALSE,
|
|
|
Thousands of files with __ci_last_regenerate|i:1614347926; |
Posted by: sswarnkar - 02-26-2021, 07:56 AM - Forum: General Help
- Replies (3)
|
 |
We would appreciate any help/advice to solve this problem.
Problem: Every second 2-5 session files are created.
Each file is about 34 bytes and has an entry like this: __ci_last_regenerate|i:1614347926;
Background: We are developing an Android app that connects to MySQL in the CentOS server. Only a couple of engineers are testing it now.
We have spent countless hours trying to figure out why these session files are created non-stop. We are not able to figure out how to stop it or slow down the file creation. We are not sure if there is something wrong with our Native App or the backend PHP files or with our configuration.
Details here -
CI_VERSION: 3.1.0
PHP Version: 7.0.33
Apache Version: 2.4.46
Our Config.php looks like this:
$config['sess_driver'] = 'files';
$config['sess_cookie_name'] = 'Del_ci_session';
$config['sess_expiration'] = 7200;
$config['sess_save_path'] = APPPATH.'session/';
$config['sess_match_ip'] = FALSE;
$config['sess_time_to_update'] = 300; /* We changed to to 0, and onlything it did was started creating empty files */
$config['sess_regenerate_destroy'] = TRUE; /* Tried FALSE and TRUE - but no difference */
php.ini has the following entries:
session.gc_probability = 1
session.gc_divisor = 1000 /* We tried with number as low as 10 */
session.gc_maxlifetime = 1440 /* We tried with 60 seconds also */
/* But the files are never deleted */
autoload.php has this entry: /* we tried to remove sessions from this list - but did not help */
$autoload['libraries'] = array('database','Template','QueryGenerator','FormGenerator','upload','email','Generate_uid','form_validation','SearchLib','Auth','Crontab');
|
|
|
how to implement custom exception management in CodeIgniter 4? |
Posted by: yuma2020 - 02-25-2021, 07:03 PM - Forum: CodeIgniter 4 Support
- Replies (1)
|
 |
how to implement custom exception management in CodeIgniter 4?
Function in the 200 is working all ok,
PHP Code: public function hx2getData($data) { if ($data->link_id) { $id = (string) $data->link_id; $url = 'https://www.hx2.xyz/api/v1/links/'.((string)$id); $client = \Config\Services::curlrequest();
$response = $client->request('GET', $url, [ 'headers' => [ 'Accept' => 'application/json', 'Authorization' => 'Bearer ZDEcp8bptOz3Hi6RFXGry0JnUmbqvNC316IRbUOrwXH7Z85PVXEhnGTutcps' ], 'timeout' => 5, ]); // $code = $response->getStatusCode(); // Code result : 200, 403 $reason = $response->getReason(); // if OK or Error try { if (strpos($response->getHeader('content-type'), 'application/json') !== false) { $result = json_decode($response->getBody()); } } catch (\Exception $e) { die($e->getMessage()); } return (object) $result ? (object) $result : 0; }
}
Calling:
Code: $this->getapi->hx2getData((object) $data);
but in HTTP status 404 gives me the following error is result:
PHP Code: { "title": "CodeIgniter\\HTTP\\Exceptions\\HTTPException", "type": "CodeIgniter\\HTTP\\Exceptions\\HTTPException", "code": 500, "message": "22 : The requested URL returned error: 404 ", "file": "D:\\laragon\\www\\marketineros\\V3\\system\\HTTP\\Exceptions\\HTTPException.php", "line": 100, "trace": [ { "file": "D:\\laragon\\www\\marketineros\\V3\\system\\HTTP\\CURLRequest.php", "line": 823, "function": "forCurlError", "class": "CodeIgniter\\HTTP\\Exceptions\\HTTPException", "type": "::", "args": [ "22", "The requested URL returned error: 404 " ] }, { "file": "D:\\laragon\\www\\marketineros\\V3\\system\\HTTP\\CURLRequest.php", "line": 449, "function": "sendRequest", "class": "CodeIgniter\\HTTP\\CURLRequest", "type": "->", "args": [ { "10002": "https://www.hx2.xyz/api/v1/links/110", "19913": true, "42": true, "74": true, "-1": true, "64": true, "155": 5000, "156": 150000, "45": true, "10036": "GET", "10023": [ "Accept: application/json", "Authorization: Bearer ZDEcp8bptOz3Hi6RFXGry0JnUmbqvNC316IRbUOrwXH7Z85PVXEhnGTutcps" ] } ] }, { "file": "D:\\laragon\\www\\marketineros\\V3\\system\\HTTP\\CURLRequest.php", "line": 158, "function": "send", "class": "CodeIgniter\\HTTP\\CURLRequest", "type": "->", "args": [ "GET", "https://www.hx2.xyz/api/v1/links/110" ] }, { "file": "D:\\laragon\\www\\marketineros\\V3\\app\\Libraries\\GetLocateLibrary.php", "line": 40, "function": "request", "class": "CodeIgniter\\HTTP\\CURLRequest", "type": "->", "args": [ "GET", "https://www.hx2.xyz/api/v1/links/110", { "headers": { "Accept": "application/json", "Authorization": "Bearer ZDEcp8bptOz3Hi6RFXGry0JnUmbqvNC316IRbUOrwXH7Z85PVXEhnGTutcps" }, "timeout": 5 } ] }
(02-25-2021, 07:03 PM)yuma2020 Wrote: how to implement custom exception management in CodeIgniter 4?
Function in the 200 is working all ok,
PHP Code: public function hx2getData($data) { if ($data->link_id) { $id = (string) $data->link_id; $url = 'https://www.hx2.xyz/api/v1/links/'.((string)$id); $client = \Config\Services::curlrequest();
$response = $client->request('GET', $url, [ 'headers' => [ 'Accept' => 'application/json', 'Authorization' => 'Bearer ZDEcp8bptOz3Hi6RFXGry0JnUmbqvNC316IRbUOrwXH7Z85PVXEhnGTutcps' ], 'timeout' => 5, ]); // $code = $response->getStatusCode(); // Code result : 200, 403 $reason = $response->getReason(); // if OK or Error try { if (strpos($response->getHeader('content-type'), 'application/json') !== false) { $result = json_decode($response->getBody()); } } catch (\Exception $e) { die($e->getMessage()); } return (object) $result ? (object) $result : 0; }
}
Calling:
Code: $this->getapi->hx2getData((object) $data);
but in HTTP status 404 gives me the following error is result:
PHP Code: { "title": "CodeIgniter\\HTTP\\Exceptions\\HTTPException", "type": "CodeIgniter\\HTTP\\Exceptions\\HTTPException", "code": 500, "message": "22 : The requested URL returned error: 404 ", "file": "D:\\laragon\\www\\marketineros\\V3\\system\\HTTP\\Exceptions\\HTTPException.php", "line": 100, "trace": [ { "file": "D:\\laragon\\www\\marketineros\\V3\\system\\HTTP\\CURLRequest.php", "line": 823, "function": "forCurlError", "class": "CodeIgniter\\HTTP\\Exceptions\\HTTPException", "type": "::", "args": [ "22", "The requested URL returned error: 404 " ] }, { "file": "D:\\laragon\\www\\marketineros\\V3\\system\\HTTP\\CURLRequest.php", "line": 449, "function": "sendRequest", "class": "CodeIgniter\\HTTP\\CURLRequest", "type": "->", "args": [ { "10002": "https://www.hx2.xyz/api/v1/links/110", "19913": true, "42": true, "74": true, "-1": true, "64": true, "155": 5000, "156": 150000, "45": true, "10036": "GET", "10023": [ "Accept: application/json", "Authorization: Bearer ZDEcp8bptOz3Hi6RFXGry0JnUmbqvNC316IRbUOrwXH7Z85PVXEhnGTutcps" ] } ] }, { "file": "D:\\laragon\\www\\marketineros\\V3\\system\\HTTP\\CURLRequest.php", "line": 158, "function": "send", "class": "CodeIgniter\\HTTP\\CURLRequest", "type": "->", "args": [ "GET", "https://www.hx2.xyz/api/v1/links/110" ] }, { "file": "D:\\laragon\\www\\marketineros\\V3\\app\\Libraries\\GetLocateLibrary.php", "line": 40, "function": "request", "class": "CodeIgniter\\HTTP\\CURLRequest", "type": "->", "args": [ "GET", "https://www.hx2.xyz/api/v1/links/110", { "headers": { "Accept": "application/json", "Authorization": "Bearer ZDEcp8bptOz3Hi6RFXGry0JnUmbqvNC316IRbUOrwXH7Z85PVXEhnGTutcps" }, "timeout": 5 } ] }
Sorry stupid error is solved with move of line try
PHP Code: public function hx2getData($data) { if ($data->link_id) { try { $id = (string) $data->link_id; $url = 'https://www.hx2.xyz/api/v1/links/'.((string)$id); $client = \Config\Services::curlrequest();
$response = $client->request('GET', $url, [ 'headers' => [ 'Accept' => 'application/json', 'Authorization' => 'Bearer ZDEcp8bptOz3Hi6RFXGry0JnUmbqvNC316IRbUOrwXH7Z85PVXEhnGTutcps' ], 'timeout' => 5, ]); // $code = $response->getStatusCode(); // Code result : 200, 403 $reason = $response->getReason(); // if OK or Error
if (strpos($response->getHeader('content-type'), 'application/json') !== false) { $result = json_decode($response->getBody()); } } catch (\Exception $e) { die($e->getMessage()); } return (object) $result ? (object) $result : 0; }
}
|
|
|
source code says Request::getMethod() is deprecated, what to use? |
Posted by: sneakyimp - 02-25-2021, 05:42 PM - Forum: CodeIgniter 4 Support
- Replies (2)
|
 |
The source code says Request::getMethod() is deprecated. What should we use instead?
PHP Code: /** * Get the request method. * * @param boolean $upper Whether to return in upper or lower case. * * @return string * * @deprecated The $upper functionality will be removed and this will revert to its PSR-7 equivalent */ public function getMethod(bool $upper = false): string { return ($upper) ? strtoupper($this->method) : strtolower($this->method); }
|
|
|
passing variable in model |
Posted by: eleumas - 02-25-2021, 02:54 AM - Forum: CodeIgniter 4 Support
- Replies (1)
|
 |
PHP Code: function get_articles() { $articles = $this->db->query("SELECT * FROM tbl_articles WHERE status = '1' AND lang = '$this->locale' ORDER BY id DESC"); foreach($articles->getResult('array') as $a) { $articleId = $a['id']; // I would like pass this variable to get_ip function } return $articles; }
function get_ip() { $test = $this->db->query("SELECT * FROM tbl_images_preview WHERE article_id = ".$articleId.""); return $test; }
I have this snippet in my model. How can I pass the variable $articleId to get_ip function?
Thanks.
|
|
|
what does fourth parameter ($escape) actually do for $builder->like? |
Posted by: sneakyimp - 02-24-2021, 05:31 PM - Forum: CodeIgniter 4 Support
- Replies (1)
|
 |
I was expecting that the fourth parameter for the Builder::like function would cause special characters in the $match parameter to be escaped. I was quite surprised to see that supplying FALSE for this parameter results in no quotation marks for the $match parameter. Is this a bug?
An example. I would expect the % in 'H%' to be escaped:
PHP Code: function test2() { $db = \Config\Database::connect("tests"); $builder = $db->table("my_table"); $builder->like('col1', '20%', 'none', false); die($builder->testMode()->getCompiledSelect()); }
The output of this function is:
Code: SELECT * FROM `db_my_table` WHERE col1 LIKE 20%
whereas I was expecting an $escape of false to suppress escaping of special characters, perhaps yielding something like this:
Code: SELECT * FROM `db_my_table` WHERE col1 LIKE '20%'
whereas an $escape value of true
PHP Code: $builder->like('col1', '20%', 'none', true);
yields this:
Code: SELECT * FROM `db_my_table` WHERE `col1` LIKE '20%' ESCAPE '!'
when I thought it would escape the special wildcard char % like so:
Code: SELECT * FROM `db_my_table` WHERE col1 LIKE '20!%' ESCAPE '!'
NOTE that in every case the table is surrounded by backticks, and the $escape parameter turns on/off the backticks around the column name and the quotes around the pattern to be matched.
Can someone explain to me what the $escape parameter is really doing? The documentation is not very clear at all:
Quote:$escape (bool) – Whether to escape values and identifiers
|
|
|
|