Welcome Guest, Not a member yet? Register   Sign In
  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 (5)

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


  How to make nav-link active
Posted by: Tokioshy - 05-05-2024, 06:41 AM - Replies (3)

I was trying to make class="nav-link" active every time I clicked the navbar navigation. So, for example, I have 5 navbar navigation. Home, About, Contact, Comic, and People. When I click the Home, the class of class="nav-link" will be active. So, it will become class="nav-link active". Then, when I click another navbar navigation, for example About, the class="nav-link active" at Home navbar navigation, will disappear and will appear again in the About navbar navigation. So the class from the navbar navigation of About will be class="nav-link active" while Home become class="nav-link" again. It's kinda hard to explain but I hope I explain it correctly Smile) And sorry for the bad grammar lolll. But anyway, here is my current code, I tried it with flash data on the controller like in the screenshot. Then, I destroy the session and make a new one. Is there any alternative code to make it? Like, more simpler code? Or easier code??

Screenshots:
https://i.imgur.com/I16sK93.png
https://i.imgur.com/RvgJmqg.png


  auth() differs from my localapi and remote
Posted by: JohnUK - 05-04-2024, 04:14 AM - Replies (3)

Hello.
I am not very knowable on CodeIgniter or shield, but I was able to get my project going locally on my machine.
I created a API made in codeigniter4 and shield. It works nice locally.
Two days ago I place it on a server and I am running the frontend from my local machine. The online API behaves differently from my local API and believe me that I tested all that I could, so I request for help.
On the server I tried to debug and to provide information for this post.
On my Controllers/AuthController.php inside the userlogin() function, I made sure that the login is working using:

PHP Code:
                   
                    log_message
('info''auth()->loggedIn(): ' auth()->loggedIn()); 

this outputs for the log file:
                                    INFO - 2024-05-04 10:51:58 --> auth()->loggedIn(): 1

That looks ok, login information is also fetched (name, id, ...). All ok and equal to my localhost.
After the login, and after the user presses a button to go to a reserved area, a filter is applied and here the code:
PHP Code:
<?php

namespace App\Filters;

use 
CodeIgniter\Filters\FilterInterface;
use 
CodeIgniter\HTTP\RequestInterface;
use 
CodeIgniter\HTTP\ResponseInterface;

class 
GroupFilter implements FilterInterface
{
    /**
    * Do whatever processing this filter needs to do.
    * By default it should not return anything during
    * normal execution. However, when an abnormal state
    * is found, it should return an instance of
    * CodeIgniter\HTTP\Response. If it does, script
    * execution will end and that Response will be
    * sent back to the client, allowing for error pages,
    * redirects, etc.
    *
    * @param RequestInterface $request
    * @param array|null      $arguments
    *
    * @return mixed
    */
    public function before(RequestInterface $request$arguments null)
    {
        $user auth()->user();
        
        log_message
('info''Is user logged: ' auth()->loggedIn());

        if ($user == null) {
            $response service('response');
            $response->setStatusCode(401);
            $response->setBody("{\"error\": \"unauthorized - login must be previously made\"}"); 

outputs:
             INFO - 2024-05-04 10:51:58 --> Is user logged:

(note that it does not contain 0 or 1, it is simply empty). $user is also null.
On my localserver this contains the correct information. No other error is detected. It is like auth() is not working.
I checked and the auth service is loaded on the Autoload.php, though a helper.

Thank you for any advice.


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

Username
  

Password
  





Latest Threads
How to Find & Hire Codeig...
by Bosborne
19 minutes ago
Insert in joint table bef...
by kcs
2 hours ago
I built 30 startups in 20...
by InsiteFX
4 hours ago
6 hard truths about learn...
by InsiteFX
4 hours ago
4.4.1 to 4.4.8 base_url p...
by kenjis
11 hours ago
CI NEEDS A PROPER DOCUMEN...
by ALTITUDE_DEV
Yesterday, 06:45 AM
Optimize.php make a probl...
by ALTITUDE_DEV
Yesterday, 06:35 AM
CodeIgniter v4.5.0 Releas...
by LP_bnss
Yesterday, 05:16 AM
Gateway time out CI 4.4.1
by kenjis
Yesterday, 03:37 AM
Need PHP Developer
by Sid.M
05-08-2024, 11:21 PM

Forum Statistics
» Members: 87,070
» Latest member: pavanis
» Forum threads: 77,629
» Forum posts: 376,291

Full Statistics

Search Forums

(Advanced Search)


Theme © iAndrew 2016 - Forum software by © MyBB