Welcome Guest, Not a member yet? Register   Sign In
  Issue with Model Validation
Posted by: osawayn - 05-07-2024, 07:18 PM - Replies (1)

When using the Model validation features in CodeIgniter 4, I'm finding that some of the validation rules aren't working as expected. For instance, the "required" rule doesn't seem to be triggering the expected validation error when the field is left empty. Additionally, the "valid_email" rule also doesn't appear to be validating the email format correctly.

Steps Taken:
1. I've verified that the validation rules are correctly defined in the model.
2. I've confirmed that the fields being validated are present in the form submission data.
3. I've reviewed the official documentation and compared my implementation with the examples provided.

Code:
// Sample validation rules in the model
protected $validationRules = [
    'email' => 'required|valid_email',
    'username' => 'required|min_length[5]'
];
I'd appreciate any guidance or advice on how to troubleshoot and resolve this issue. Has anyone else encountered similar problems with model validation in CodeIgniter 4? Any pointers on best practices or potential pitfalls to watch out for would be immensely helpful.

Thanks in advance!


  Gateway time out CI 4.4.1
Posted by: adleon73 - 05-07-2024, 01:35 PM - Replies (5)

I have a project made on Codeigniter 4.4.1 + MySQL

The setup is:

Routes.php

PHP Code:
$routes->get('admin_start',  'Admin::index');
$routes->get('admin_ejercicios',  'Admin::admin_ejercicios');
$routes->get('admin_rutinas',  'Admin::admin_rutinas'); 

Controller: Admin.php

PHP Code:
<?php

namespace App\Controllers;
use 
App\Models\Admin_model;
use 
App\Models\Admin_users_model;

use 
App\Controllers\BaseController;


class 
Admin extends BaseController
{

    protected $helpers = ['form','url','html'];

    public function index()
    {
        $data['content_view']="admin/admin_users_view";
        return view('admin/admin_main_view',$data);
    }

    public function admin_ejercicios()
    {
        $data['content_view']="admin/admin_ejercicios_view";
        return view('admin/admin_main_view',$data);
    }

    public function admin_rutinas()
    {
        $user_id    =$this->request->getGet('id');

        $admin_model= new Admin_users_model();
        $user_name=$admin_model->get_username($user_id);

        $data['user_name']=$user_name;
        $data['user_id']=$user_id;
        $data['content_view']="admin/admin_rutinas_view";
      
        
return view('admin/admin_main_view',$data);
    }



.htaccess

Code:
<IfModule mod_rewrite.c>
    RewriteEngine On
    RewriteRule ^(.*)$ public/$1 [L]
</IfModule>


Switching between these controllers:

http://192.168.1.167/gym/admin_rutinas?id=70

or

http://192.168.1.167/gym/admin_ejercicios

or

http://192.168.1.167/gym/admin_start

I get a 504 Gateway timeout error after 5min waiting for response

On the browser console the call is shown as pending, and never throws an error.

I tried to change max_execution_time on PHP to 0 or -1 and I have the same behaivour

The database has only a few records, so I don't think it is due to a long response from the server.

I'm also having the same behaivour on my hosting.

Could it be something related with the framework?, or it is just my code?


Thanks.


  Background image does not appear in some views.
Posted by: Clarasandri - 05-07-2024, 01:04 PM - Replies (1)

I am new to Codeigniter and php and web development so this could have a really simple solution.

I have set a background image in a main_layout that is called in every view (I had the code for the background on each page instead of on the main_layout and it made no difference). The image works just fine in the majority of my views. The problem is that the image does not appear on any view that has a route with a variable (I don't know the correct name for it but something like: " $routes->get('/edit/(:alphanum)', 'Main::edit/$1') ").  

Code:
  <div class="bg-image overflow-hidden " style="
    background-image: url('../public/assets/images/aspersor_fundo_joao_vertical.jpg');
    background-size: cover;
    height: 100vh;">

        <div class="mask" style="background-color: rgba(0, 0, 0, 0.3); height:100vh;">


If I change the class from "bg-image" to "bg-success" the background turns green, so the problem is probably in the loading of the image but I have no idea why it works in every other view but does not work on the views with variable url.

I had a similar problem with filters until I finally figured out that I had to put a "*" on the end of the route in order for the filter to access every possible combination of '/edit/(:alphanum)' but now I just can't find a solution. 

Any help is welcome.


  Implement DDD in Codeigniter 4
Posted by: Bary - 05-07-2024, 11:17 AM - Replies (1)

Hello ,
I would like to implement Domain-Driven Design on CI 4 , can i get you help if someone has already done it?

Thank you


  error is logged. but it does not throw an exception.
Posted by: mywebmanavgat - 05-07-2024, 11:09 AM - Replies (1)

writes the following error to the codeigniter log file.

However, it does not throw an error in the output even though the project is in developer mode.

I am aware of the cause and the solution, but you won't notice it if you don't review the logs during the development process. Why can't we see it on the screen?

WARNING - 2024-05-07 21:05:38 --> [DEPRECATED] Creation of dynamic property App\Libraries\Template::$__version is deprecated in APPPATH/Libraries/Template.php on line 30.
1 APPPATH/Controllers/BaseController.php(41): App\Libraries\Template->setData('version', '2.0.0.1a1')
2 APPPATH/Controllers/Approval.php(10): App\Controllers\BaseController->__construct()
3 SYSTEMPATH/CodeIgniter.php(903): App\Controllers\Approval->__construct()
4 SYSTEMPATH/CodeIgniter.php(500): CodeIgniter\CodeIgniter->createController()
5 SYSTEMPATH/CodeIgniter.php(355): CodeIgniter\CodeIgniter->handleRequest(null, Object(Config\Cache), false)
6 SYSTEMPATH/Boot.php(312): CodeIgniter\CodeIgniter->run()
7 SYSTEMPATH/Boot.php(67): CodeIgniter\Boot::runCodeIgniter(Object(CodeIgniter\CodeIgniter))
8 FCPATH/index.php(57): CodeIgniter\Boot::bootWeb(Object(Config\Paths))


  Support JOIN in UPDATE
Posted by: objecttothis - 05-07-2024, 12:41 AM - No Replies

PHP 8.2
MySQL 8.2
Apache 2.4
CI 4.5.1

With the code

PHP Code:
$builder $this->db->table('attribute_links');
$builder->join('attribute_values''attribute_values.attribute_id = attribute_links.attribute_id''inner');
$builder->set('attribute_links.attribute_id'"IF((attribute_values.attribute_value IN('false','0','') OR (attribute_values.attribute_value IS NULL)), $checkbox_attribute_values[0]$checkbox_attribute_values[1])"false);
$builder->where('attribute_links.definition_id'$definition_id);
log_message('error'$builder->getCompiledUpdate(false)); 

I expect the generated SQL to be
Code:
UPDATE `ospos_attribute_links`
JOIN `ospos_attribute_values` ON `ospos_attribute_values`.`attribute_id` = `ospos_attribute_links`.`attribute_id`
SET `ospos_attribute_links`.`attribute_id` = IF((`ospos_attribute_values`.`attribute_value` IN('false','0','') OR (`ospos_attribute_values`.`attribute_value` IS NULL)), 45873, 25595)
WHERE `ospos_attribute_links`.`definition_id` = 6

What I get is
Code:
UPDATE `ospos_attribute_links`
SET `ospos_attribute_links`.`attribute_id` = IF((attribute_values.attribute_value IN('false','0','') OR (attribute_values.attribute_value IS NULL)), 45873, 25595)
WHERE `ospos_attribute_links`.`definition_id` = 6

This is completely missing the join. Your batch update (https://codeigniter.com/user_guide/datab...-from-data) examples shows joins being generated in an update, so I know it's possible, but doesn't seem to be implemented.


  Optimize.php make a problem cached
Posted by: ALTITUDE_DEV - 05-06-2024, 01:06 PM - Replies (4)

Hello CI Team,
I recently discovered an issue or something to clarify in the CI 4.5.1 documentation. If the options in the Optimize.php file are set to "TRUE," then the changes made in the Email.php file (SMTP server, etc.) are no longer taken into account. Therefore, the factory caches need to be regenerated. Hope this helps Wink


  4.4.1 to 4.4.8 base_url php spark closes..
Posted by: xsPurX - 05-06-2024, 11:31 AM - Replies (6)

Hi,
I'm working on updating to 4.4.8 and my base url is defined like below.

Code:
public string $baseURL = BASE_URL;

in config/Constants.php I have

Code:
$base_url = (isset($_SERVER['HTTPS']) && $_SERVER['HTTPS'] == 'on' ? 'https://' : 'http://') . $_SERVER['HTTP_HOST'] . dirname($_SERVER['SCRIPT_NAME']) . (substr(dirname($_SERVER['SCRIPT_NAME']), -1) == '/' ? '' : '/');

defined('BASE_URL') || define('BASE_URL', $base_url);

when I run php spark on 4.4.1 it works fine, but on 4.4.8 it just exits out, and doesn't run the localhost server.

if i replace the $baseURL with http://localhost:8080/ it works, but I need the dynamic url. So why is 4.4.8 exiting out when 4.4.1 doesn't? I don't get any error, it just goes back the typing commands in command prompt, and doesn't run the local server.

Any help would be appreicated.


  QueryBuilder inside
Posted by: objecttothis - 05-06-2024, 03:31 AM - Replies (5)

Any time QueryBuilder where() and select() functions contain SQL functions (e.g., DATE(), ISNULL(), etc.) table prefix is not prepended and tables/columns are not escaped. What is the correct way to get $sale_total and $sale_subtotal to be

PHP Code:
$decimals totals_decimals();
 
$db_prefix $this->db->getPrefix();

 if(
$this->config['tax_included'])
 {
 
$sale_total '(CASE WHEN ' $db_prefix 'sales_items.discount_type = ' PERCENT
 
" THEN " $db_prefix "sales_items.quantity_purchased * " $db_prefix "sales_items.item_unit_price - ROUND(" $db_prefix "sales_items.quantity_purchased * " $db_prefix "sales_items.item_unit_price * " $db_prefix "sales_items.discount / 100, $decimals)"
 
' ELSE ' $db_prefix 'sales_items.quantity_purchased * (' $db_prefix 'sales_items.item_unit_price - ' $db_prefix 'sales_items.discount) END)';

 
$sale_subtotal '(CASE WHEN ' $db_prefix 'sales_items.discount_type = ' PERCENT
 
" THEN " $db_prefix "sales_items.quantity_purchased * " $db_prefix "sales_items.item_unit_price - ROUND(" $db_prefix "sales_items.quantity_purchased * " $db_prefix "sales_items.item_unit_price * " $db_prefix "sales_items.discount / 100, $decimals) "
 
'ELSE ' $db_prefix 'sales_items.quantity_purchased * ' $db_prefix 'sales_items.item_unit_price - ' $db_prefix 'sales_items.discount END * (100 / (100 + ' $db_prefix 'sales_items_taxes.percent)))';
 }
 else
 {
 
$sale_total '(CASE WHEN ' $db_prefix 'sales_items.discount_type = ' PERCENT
 
" THEN " $db_prefix "sales_items.quantity_purchased * " $db_prefix "sales_items.item_unit_price - ROUND(" $db_prefix "sales_items.quantity_purchased * " $db_prefix "sales_items.item_unit_price * " $db_prefix "sales_items.discount / 100, $decimals)"
 
' ELSE ' $db_prefix 'sales_items.quantity_purchased * ' $db_prefix 'sales_items.item_unit_price - ' $db_prefix 'sales_items.discount END * (1 + (' $db_prefix 'sales_items_taxes.percent / 100)))';

 
$sale_subtotal '(CASE WHEN ' $db_prefix 'sales_items.discount_type = ' PERCENT
 
" THEN " $db_prefix "sales_items.quantity_purchased * " $db_prefix "sales_items.item_unit_price - ROUND(" $db_prefix "sales_items.quantity_purchased * " $db_prefix "sales_items.item_unit_price * " $db_prefix "sales_items.discount / 100, $decimals)"
 
' ELSE ' $db_prefix 'sales_items.quantity_purchased * (' $db_prefix 'sales_items.item_unit_price - ' $db_prefix 'sales_items.discount) END)';
 }

 
$subquery_builder $this->db->table('sales_items');
 
$subquery_builder->select("name AS name, CONCAT(IFNULL(ROUND(percent, $decimals), 0), '%') AS percent, sales.sale_id AS sale_id, $sale_subtotal AS subtotal, IFNULL($db_prefix"."sales_items_taxes.item_tax_amount, 0) AS tax, IFNULL($sale_total$sale_subtotal) AS total");

 
$subquery_builder->join('sales''sales_items.sale_id = sales.sale_id''inner');
 
$subquery_builder->join('sales_items_taxes''sales_items.sale_id = sales_items_taxes.sale_id AND sales_items.item_id = sales_items_taxes.item_id AND sales_items.line = sales_items_taxes.line''left outer');

 
$subquery_builder->where('sale_status'COMPLETED);

 if(empty(
$this->config['date_or_time_format']))
 {
 
$subquery_builder->where('DATE(' $db_prefix 'sales.sale_time) BETWEEN ' $this->db->escape($inputs['start_date']) . ' AND ' $this->db->escape($inputs['end_date']));
 }
 else
 {
 
$subquery_builder->where('sales.sale_time BETWEEN ' $this->db->escape(rawurldecode($inputs['start_date'])) . ' AND ' $this->db->escape(rawurldecode($inputs['end_date'])));
 }

 
$builder $this->db->newQuery()->fromSubquery($subquery_builder'temp_taxes');
 
$builder->select("name, percent, COUNT(DISTINCT sale_id) AS count, ROUND(SUM(subtotal), $decimals) AS subtotal, ROUND(SUM(tax), $decimals) AS tax, ROUND(SUM(total), $decimals) total");
 
$builder->groupBy('percent, name');

 return 
$builder->get()->getResultArray(); 

There are three problems that I can see.
  • I have to add $this->db->escape() around the $inputs['start_date'] and $inputs['end_date'] variables in order to get the single quotes around them
  • I have to add $db_prefix programmatically to anything that appears inside a function or parenthesis (see results below).
  • Anything appearing inside an SQL function does not get escaped with backticks.

Code:
SELECT
  `name`,
  `percent`,
  COUNT(DISTINCT sale_id) AS count,
  ROUND(
    SUM(subtotal),
    2
  ) AS subtotal,
  ROUND(
    SUM(tax),
    2
  ) AS tax,
  ROUND(
    SUM(total),
    2
  ) total
FROM
  (
    SELECT
      `name` AS `name`,
      CONCAT(
        IFNULL(
          ROUND(percent, 2),
          0
        ),
        '%'
      ) AS percent,
      `ospos_sales`.`sale_id` AS `sale_id`,
      (
        CASE WHEN ospos_sales_items.discount_type = 0 THEN ospos_sales_items.quantity_purchased * ospos_sales_items.item_unit_price - ROUND(
          ospos_sales_items.quantity_purchased * ospos_sales_items.item_unit_price * ospos_sales_items.discount / 100,
          2
        ) ELSE ospos_sales_items.quantity_purchased * ospos_sales_items.item_unit_price - ospos_sales_items.discount END * (
          100 / (
            100 + ospos_sales_items_taxes.percent
          )
        )
      ) AS subtotal,
      IFNULL(
        ospos_sales_items_taxes.item_tax_amount,
        0
      ) AS tax,
      IFNULL(
        (
          CASE WHEN ospos_sales_items.discount_type = 0 THEN ospos_sales_items.quantity_purchased * ospos_sales_items.item_unit_price - ROUND(
            ospos_sales_items.quantity_purchased * ospos_sales_items.item_unit_price * ospos_sales_items.discount / 100,
            2
          ) ELSE ospos_sales_items.quantity_purchased * (
            ospos_sales_items.item_unit_price - ospos_sales_items.discount
          ) END
        ),
        (
          CASE WHEN ospos_sales_items.discount_type = 0 THEN ospos_sales_items.quantity_purchased * ospos_sales_items.item_unit_price - ROUND(
            ospos_sales_items.quantity_purchased * ospos_sales_items.item_unit_price * ospos_sales_items.discount / 100,
            2
          ) ELSE ospos_sales_items.quantity_purchased * ospos_sales_items.item_unit_price - ospos_sales_items.discount END * (
            100 / (
              100 + ospos_sales_items_taxes.percent
            )
          )
        )
      ) AS total
    FROM
      `ospos_sales_items`
      INNER JOIN `ospos_sales` ON `ospos_sales_items`.`sale_id` = `ospos_sales`.`sale_id`
      LEFT OUTER JOIN `ospos_sales_items_taxes` ON `ospos_sales_items`.`sale_id` = `ospos_sales_items_taxes`.`sale_id`
      AND `ospos_sales_items`.`item_id` = `ospos_sales_items_taxes`.`item_id`
      AND `ospos_sales_items`.`line` = `ospos_sales_items_taxes`.`line`
    WHERE
      `sale_status` = 0
      AND DATE(ospos_sales.sale_time) BETWEEN '2010-01-01'
      AND '2023-12-31'
  ) `temp_taxes`
GROUP BY
  `percent`,
  `name`


  DataCaster not working
Posted by: ozornick - 05-05-2024, 07:14 AM - Replies (5)

Hi. There is an error when converting DataСaster types for an Entity, the set() method is not specified. Because of this, type casting does not work. 
Look at this https://github.com/codeigniter4/CodeIgni...st.php#L24
My code Entity: 

PHP Code:
// Step 1, fill properties
$entity->fill($data);
// Step 2 run Entity->__set($value)

// See https://github.com/codeigniter4/CodeIgniter4/blob/fd9cb65c23c047d2a65203d9f602fe34902d48f0/system/Entity/Entity.php#L165

// Step 3 call Cast
// https://github.com/codeigniter4/CodeIgniter4/blob/fd9cb65c23c047d2a65203d9f602fe34902d48f0/system/Entity/Entity.php#L434
$value $this->castAs($value$dbColumn'set'); 

But some Casts (IntegerCast, FloatCast, ...) don't have a set (only get) method and everything breaks


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

Username
  

Password
  





Latest Threads
Myth Auth register a new ...
by Newbie_Mark998
18 minutes ago
Why Does CodeIgniter Shie...
by tarcisiodev1
1 hour ago
CLI Error
by ozornick
2 hours ago
Get folder path instead o...
by ozornick
2 hours ago
Shield Not Displaying err...
by ollieonline
5 hours ago
Running Codeigniter Queue
by warcooft
7 hours ago
Codeignighter not resondi...
by mikehoague
10 hours ago
Where can I find a reliab...
by InsiteFX
Yesterday, 10:24 PM
Caching Question
by ozornick
Yesterday, 08:26 AM
Codeigniter and ReactJS
by murugappan
Yesterday, 01:18 AM

Forum Statistics
» Members: 88,304
» Latest member: muratdutluu
» Forum threads: 77,671
» Forum posts: 376,487

Full Statistics

Search Forums

(Advanced Search)


Theme © iAndrew 2016 - Forum software by © MyBB