Welcome Guest, Not a member yet? Register   Sign In
  Undefined variable: request;
Posted by: lucasdemarco - 04-11-2024, 07:25 AM - Replies (5)

I recently migrated from CI 3 to 4 and I'm having a problem displaying $_POST values in my view. I have a filter in my view "listar.php" and when the form is sent the same view is loaded with new information based on the filter, but I cannot print the filter value when the page is loaded.
From what I noticed in CI 4 it is necessary to use
"echo $request->getGet('search');" to print the value sent by the form, but the problem happens because I'm not loading "Config\Services::request()", if I put " $request = \Config\Services::request(); " at the beginning of my view the error "Undefined variable: request" disappears, but it is very exhausting to always have to put this line in all views, I would like to know if anyone has a suggestion on how to always leave Request() loaded in all views by default, I would appreciate it.

Note: I haven't created the logic behind the filter yet, for now I just want to display what was sent in the filter itself
My controller: 


PHP Code:
namespace App\Controllers;
use 
App\Models\Modulo;

class 
Modulos extends My_Controller
{
    public function Getlistar()
    {
        $obj = new Modulo();
        $data['objetos'] = $obj->find();

        return view('estrutura/menu')
            view($this->controllerName.'/listar'$data)
            view('estrutura/rodape');
    }


Input I want to print the value: 
PHP Code:
<input type="text" name="busca" id="busca" value="<?php echo $request->getGet('busca'); ?>" class="form-control"


  Replace very large jS if/elseif/else to show/hide many divs?
Posted by: Madelineknight - 04-11-2024, 07:12 AM - No Replies

Hi Forum,

I've got a page that has a portion of it that displays, or hides, DIV's depending on what option was selected.

There will be around 25 different div's when done, and while developing this I realize that the JS if/else is going to be quite verbose.

For example:

vehicleYearSelect.addEventListener('change', function() {
    if (this.value === '1960') {
        vehicleYear_1960.style.display = 'flex';
        vehicleYear_1961.style.display = 'none';
        vehicleYear_1962.style.display = 'none';
        vehicleYear_1963.style.display = 'none';
        vehicleYear_1964.style.display = 'none';
        vehicleYear_1965.style.display = 'none';
        ...
        [many more years here]
    } else if (this.value === '1961') {
        vehicleYear_1960.style.display = 'none';
        vehicleYear_1961.style.display = 'flex';
        vehicleYear_1962.style.display = 'none';
        vehicleYear_1963.style.display = 'none';
        vehicleYear_1964.style.display = 'none';
        vehicleYear_1965.style.display = 'none';
                ...
        [many more years here]
    } else if (this.value === '1962') {
        vehicleYear_1960.style.display = 'none';
        vehicleYear_1961.style.display = 'none';
        vehicleYear_1962.style.display = 'flex';
        vehicleYear_1963.style.display = 'none';
        vehicleYear_1964.style.display = 'none';
        vehicleYear_1965.style.display = 'none';
                ...
        [many more years here]
    } else if (this.value === '1963') {
        vehicleYear_1960.style.display = 'none';
        vehicleYear_1961.style.display = 'none';
        vehicleYear_1962.style.display = 'none';
        vehicleYear_1963.style.display = 'flex';
        vehicleYear_1964.style.display = 'none';
        vehicleYear_1965.style.display = 'none';
                ...
        [many more years here]
    } else if (this.value === '1964') {
        vehicleYear_1960.style.display = 'none';
        vehicleYear_1961.style.display = 'none';
        vehicleYear_1962.style.display = 'none';
        vehicleYear_1963.style.display = 'none';
        vehicleYear_1964.style.display = 'flex';
        vehicleYear_1965.style.display = 'none';
                ...
        [many more years here]
    } else {
        vehicleYear_1960.style.display = 'none';
        vehicleYear_1961.style.display = 'none';
        vehicleYear_1962.style.display = 'none';
        vehicleYear_1963.style.display = 'none';
        vehicleYear_1964.style.display = 'none';
        vehicleYear_1965.style.display = 'none';
                ...
        [many more years here]
    }
});


Is there a way to make this more "efficient" in terms of maintainability and having to add new options selected to it?

Example, if I need to add else if (this.value === '1965') and else if (this.value === '1966') to this, I'll need to not only add two more else if's, but also add both of the respective tyle.display = 'none'; or tyle.display = 'flex'; to each of the other existing conditions. etc....

There wont' be very many people using this form as it's not public facing, so speed is not a huge concern here.

Just looking for a way to improve this.


  Pass custom variables to Shield custom layout
Posted by: Fred9176 - 04-11-2024, 03:11 AM - Replies (2)

Hi,

I'm trying to integrate Shield into my custom layout.

I copied the login.php view into app/Views/Shield and setup my layout in app/Config/Auth.php

My custom layout takes some custom variables as, for example, the title of the page.

PHP Code:
$view_data = [];
$view_data['pageTitle'] = 'My page title;
$view_data['
pageSubtitle'] = 'Page subtitle';

return view('
Modules\MyModule\Views\myview', $view_data); 

How can I pass these variables in the login View ?

Thanks for your help,

Fred


  Some data is not updating
Posted by: karimm - 04-11-2024, 01:50 AM - Replies (2)

Hi,
I'm on version 4.4.5 of Codeigniter and I have a problem with database fields being ignored with the save() function for Models. So with save(), the insert is done very well and the update too except for two fields "modifiedOn (datetime)" and 'modifiedBy (int) which do not fill up when I update the data. 
Here is my model

PHP Code:
namespace App\Models;

use 
CodeIgniter\Model;

class 
Tender_model extends Model
{
    protected $DBGroup          'default';
    protected $table            'tenders';
    protected $primaryKey      'id';
    protected $useAutoIncrement true;
    protected $insertID        0;
    protected $returnType      'array';
    protected $useSoftDeletes  true;
    protected $protectFields    true;
    protected $allowedFields    = ['id''title''typeId''serviceId''summaryMarket''isPublicMarket''estimatedDuration''estimatedAmount''executionPeriodFrom''executionPeriodTo''publicationDate''deliveryTenderDate''summaryExpectationsProviders''modalitySubmission''modifiedOn''modifiedBy''deletedOn''deletedBy''wp_id''owner''createdBy'];

    // Dates
    protected $useTimestamps false;
    protected $dateFormat    'datetime';
    protected $createdField  'createdOn';
    protected $updatedField  'modifiedOn';
    protected $deletedField  'deletedOn';

    // Validation
    protected $validationRules      = [];
    protected $validationMessages  = [];
    protected $skipValidation      false;
    protected $cleanValidationRules true;

    // Callbacks
    protected $allowCallbacks true;
    protected $beforeInsert  = [];
    protected $afterInsert    = [];
    protected $beforeUpdate  = [];
    protected $afterUpdate    = [];
    protected $beforeFind    = [];
    protected $afterFind      = [];
    protected $beforeDelete  = [];
    protected $afterDelete    = [];

Here is my controller, the useful functions
PHP Code:
public function create()
    {
        //print_r($this->request->getPost()); // check file PDF only
        if($this->request->getPost()){
            
            
if (!empty($this->request->getPost('tenderId'))) {
                $primaryKey 'id';
                $data['id'] = $this->request->getPost('tenderId');
                $data['modifiedBy'] = session('user')['peopleId'];
                $data['modifiedOn'] = date('Y-m-d H:i:s');
                if(! empty($this->request->getPost('contactPeopleId')))
                    $data['owner'] = $this->request->getPost('contactPeopleId');
            } else {
                $data['createdBy'] = session('user')['peopleId'];
                //$data['owner'] = (empty($this->request->getPost('contactPeopleId'))) ? $data['createdBy'] : $this->request->getPost('contactPeopleId');
            }
            $data['title'] = $this->request->getPost('title');
            $data['summaryMarket'] = $this->request->getPost('summaryMarket');
            $data['isPublicMarket'] = $this->request->getPost('isPublicMarket');
            $data['executionPeriodFrom'] = $this->request->getPost('executionPeriodFrom');
            $data['executionPeriodTo'] = $this->request->getPost('executionPeriodTo');
            $data['publicationDate'] = $this->request->getPost('publicationDate');
            $data['estimatedDuration'] = $this->request->getPost('estimatedDuration');
            $data['estimatedAmount'] = $this->request->getPost('estimatedAmount');
            $data['deliveryTenderDate'] = $this->request->getPost('deliveryTenderDate');
            $data['modalitySubmission'] = $this->request->getPost('depositMethod');
            $data['serviceId'] = $this->request->getPost('serviceId');
            $data['typeId'] = $this->request->getPost('typeId');
            $data['countryId'] = $this->request->getPost('countryId');
            $data['wp_id'] = (! empty($this->request->getPost('wp_id'))) ? $this->request->getPost('wp_id') : null;
        }
print_r($data);
 
$this->model->save($data);

the print_r of $data
PHP Code:
Array ( [id] => 587 [modifiedBy] => 8403 [modifiedOn] => 2024-04-09 20:35:11 [title] => Mission de consultance sur les consortiums/fusions [summaryMarket] =>

La mission de consultance a pour objectif de réaliser un état des lieux et d’accompagner ACODEV et ses membres afin de mieux comprendre les intentions du secteur et d’identifier les conditions et méthodes pour les appuyer dans d’éventuels processus de mise en place de consortium et/ou de mise en commun de services et/ou de fusions.Partie A 1. Disposer d’une revue documentaire de la question 2. Disposer d’un état des lieux approfondi des intentions des membres d’ACODEV concernant la mise en place de consortiums et de fusions d’organisations 3. Animer un débat et/ou des travaux de groupes soit lors de l’assemblée générale d’ACODEV (juinsoit lors d’un autre atelier/événement spécifique (même périodequi aboutissent à une note de positionnement sur la question et/ou un mandat pour le secrétariat de la fédération Partie B 4. Elaborer un rapport et un guide qui propose des méthode d’accompagnement des organisations souhaitant s’engager sur la voie d’un consortium ou d’une fusion 5. Mener éventuellement un coaching d’organisations souhaitant s’inscrire dans cette démarche
[isPublicMarket] => [executionPeriodFrom] => 2022-05-01 [executionPeriodTo] => 2022-10-31 [publicationDate] => 2022-04-01 [estimatedDuration] => 20 [estimatedAmount] => 199.99 [deliveryTenderDate] => 2022-04-26 [modalitySubmission] => [serviceId] => [typeId] => [countryId] => [wp_id] => 144 
As you can see, the 2 problematic fields are present in $data. I checked the spelling in the database and it's ok there too. What concerns me is even if I put $allowedFields = [], the insertion and modification (except the 2 fields) work. 
The debug gives me as query
PHP Code:
UPDATE `tendersSET `id` = '587', `title` = 'Mission de consultance sur les consortiums/fusions', `summaryMarket` = '<p>La mission de consultance a pour objectif de réaliser un état des lieux et d’accompagner ACODEV et ses membres afin de mieux comprendre les intentions du secteur et d’identifier les conditions et méthodes pour les appuyer dans d’éventuels processus de mise en place de consortium et/ou de mise en commun de services et/ou de fusions.Partie A : 1. Disposer d’une revue documentaire de la question 2. Disposer d’un état des lieux approfondi des intentions des membres d’ACODEV concernant la mise en place de consortiums et de fusions d’organisations ; 3. Animer un débat et/ou des travaux de groupes soit lors de l’assemblée générale d’ACODEV (juin) soit lors d’un autre atelier/événement spécifique (même période) qui aboutissent à une note de positionnement sur la question et/ou un mandat pour le secrétariat de la fédération Partie B : 4. Elaborer un rapport et un guide qui propose des méthode d’accompagnement des organisations souhaitant s’engager sur la voie d’un consortium ou d’une fusion 5. Mener éventuellement un coaching d’organisations souhaitant s’inscrire dans cette démarche</p>', `isPublicMarket` = '0', `executionPeriodFrom` = '2022-05-01', `executionPeriodTo` = '2022-10-31', `publicationDate` = '2022-04-01', `estimatedDuration` = '20', `estimatedAmount` = '199.99', `deliveryTenderDate` = '2022-04-26', `modalitySubmission` = '1', `serviceId` = '4', `typeId` = '6' WHERE `tenders`.`idIN ('587'

The 2 fields are not in the query. There you go, I don't know what lead anymore, I can investigate.
Thanks in advance


  $session->destroy() throws exception
Posted by: joho - 04-11-2024, 01:44 AM - Replies (5)

Why does this throw an exception?

PHP Code:
        $session = \Config\Services::session();
        $session_username $session->get'session_username' );
        $session_login_time $session->get'session_login_time' );
        $session_login_ip $session->get'session_login_ip' );
        if ( ! empty( $session_username) && ! empty( $session_login_time )  && ! empty( $session_login_ip ) ) {
            error_logbasename__FILE__ ) . ' (' __FUNCTION__ '): Session already active, re-directing to /' );
            return( $this->response->redirectbase_url() ) );
        }
        $ip_address $this->request->getIPAddress();
        if ( empty( $ip_address ) ) {
            error_logbasename__FILE__ ) . ' (' __FUNCTION__ '): Missing or invalid IP address "' $ip_address '", re-directing' );
            $session->destroy();
            return( $this->response->redirectbase_url() ) );
        }
        // .. code continues 

It throws an exception ("session_destroy(): Trying to destroy uninitialized session") when it gets to $session->destroy().

But if it's an uninitialized session, why doesn't it throw the exception sooner?

I honestly don't think the destroy() call should throw an exception. I have several blocks of code that do cleanup and then re-direct, so I add a destroy() call inside each of those blocks. I can't see anywhere in the PHP reference that session_destroy() in itself would ever throw an exception.


  VIRUS reported after Chrome update this morning!
Posted by: InsiteFX - 04-10-2024, 11:19 PM - Replies (3)

Ok, I do not usually ask questions on here but this morning I got an update to Google Chrome,
Now when I go to Download the CodeIgniter 4 Development from GitHub it is saying that it has a
VIRUS!

Trojan:Script/Wacatac.H!ml

[Image: VBf0cUa]

I think the Windows Update may be at play here.

This is the CodeIgniter 4 file path were it says the virus is in.

UPDATED:

CodeIgniter 4.5.0

C:\xampp\htdocs\admin\app\Views\errors\html\error_exception.php


  problem: unable to load static path of .css, .js, image files with codeigniter4
Posted by: nguyenhaitruong - 04-10-2024, 10:13 PM - Replies (4)

Hello everybody!

I installed Codeigniter 4 on an apache2 server, centos 7 operating system. When accessing the website, I had trouble loading static files such as .css, .js, images.
Please help me resolve this issue!
application path structure:
/var/www/top100mu.com/public_html/public/
                                                                         /index.php
                                                                       /.htaccess
                                                                     /templates/
                                                                                   /style.css
 When accessing the style.css file path https://top100mu.com/templates/style.css , I receive a 404 error message:                                                                                  
                               404
Can't find a route for 'GET: templates/style.css'.

Apache Configuration File:
<VirtualHost *:80>
    ServerName top100mu.com
    DocumentRoot /var/www/top100mu.com/public_html/public
    DirectoryIndex index.php
    SetHandler "proxy:fcgi://127.0.0.1:9082
    ScriptAlias /cgi-bin/ "/var/www/cgi-bin/"
    AddHandler php82-fcgi .php
    Action php82-fcgi /cgi-bin/php82.fcgi
    <Directory "/var/www/top100mu.com/public_html/public">
        AllowOverride All
        Require all granted
    </Directory>
    ErrorLog /var/log/httpd/top100mu.com_error.log
    CustomLog /var/log/httpd/top100mu.com_access.log combined
</VirtualHost>


  routing problems
Posted by: NathanNever - 04-10-2024, 03:32 AM - No Replies

Hello everyone
they put me on a half-completed project, done in codeIgniter 3.1.10
I'm not clear on the system's routing logic, and I would like some help understanding it
basically I have this link in a menu


PHP Code:
<?php if (in_array('consulting_shd'$this->modules)) { ?>
                                                    <li><a href="consulting_shd"><i class="fal fa-file-spreadsheet"></i>SHD</a></li>
<?php ?>




already exists, which works perfectly, call the module called consulting_shd in modules

I replicated the module, in another called consulting_shdprice and created the html part in the menu



PHP Code:
<?php if (in_array('consulting_shdprice'$this->modules)) { ?>
                                                    <li><a href="consulting_shdprice"><i class="fal fa-file-spreadsheet"></i>SHD price</a></li>
<?php ?>


but in $this-modules it doesn't find consulting_shdprice, and if I remove the control and click directly on the link it redirects me to the home page


what am I doing wrong? what can I check?
Thank you in advance, and sorry for my English


  Automating codeIgniter deployment on hostinger
Posted by: samsonwilliams - 04-10-2024, 03:08 AM - No Replies

Currently, I am hosting CodeIgniter on Hostinger using the Git webhook, which allows for continuous development. Hostinger listens to any git push and triggers its deployment script to host the site.

However, I encountered an issue where it does not run the "update" and "serve" commands automatically. As a result, I have to access SSH every time I make changes to the project and manually execute "composer update" and "php spark serve" to keep the site running.

I am looking for a solution that automates this process and eliminates the need for manual intervention every time I update the project. Is there any solution or workaround available to streamline this workflow and enable automatic execution of the necessary commands after each git push? Any guidance or suggestions would be highly appreciated.

Thank you in advance for your help.


  Codeigniter 3.x and MariaDB transactions rollback not working for all records
Posted by: dzhneodv - 04-10-2024, 02:36 AM - No Replies

This is driving me crazy for days.

When I build query and insert in some of the tables it is commiting automatically, while other times it doesnt.

Checked all threads but nothing works. I have this code:

$this->db->trans_begin();

        $q1 = $this->db->insert('log_query_actions', array('created_time' => '11:11:11'));
        $q2 = $this->db->insert("db_sales", array('store_id' => '1'));
        $q3 = $this->db->insert("db_sales", array('store_id' => '2'));
        $q4 = $this->db->insert('log_query_actions', array('created_time' => '22:22:22'));
        $q5 = $this->db->insert("db_sales", array('store_id' => '3'));
        $q6 = $this->db->insert('log_query_actions', array('created_time' => '33:33:33'));

        $this->db->trans_rollback();
After execution, in Database I can see the first 2 inserts for each table. The 3-rd insert in each table is successfully rolled back: 
NOT ROOLLEDBACK $q1 
NOT ROOLLEDBACK $q2 
NOT ROOLLEDBACK $q3 
NOT ROOLLEDBACK $q4 
ROOLLEDBACK $q5 
ROOLLEDBACK $q6

If I try something else, like:

                    $this->db->trans_begin();

        $q1 = $this->db->insert('log_query_actions', array('created_time' => '11:11:11'));
        $q4 = $this->db->insert('log_query_actions', array('created_time' => '22:22:22'));
        $q6 = $this->db->insert('log_query_actions', array('created_time' => '33:33:33'));
        $q2 = $this->db->insert("db_sales", array('store_id' => '1'));
        $q3 = $this->db->insert("db_sales", array('store_id' => '2'));
        $q5 = $this->db->insert("db_sales", array('store_id' => '3'));

        $this->db->trans_rollback();
Then ONLY $q5 IS ROLLEDBACK. Everything else is in the table.

AND HERE COMES THE INTERESTING PART:

                    $this->db->trans_begin();

        $q2 = $this->db->insert("db_sales", array('store_id' => '1'));
        $q3 = $this->db->insert("db_sales", array('store_id' => '2'));
        $q5 = $this->db->insert("db_sales", array('store_id' => '3'));
        $q1 = $this->db->insert('log_query_actions', array('created_time' => '11:11:11'));
        $q4 = $this->db->insert('log_query_actions', array('created_time' => '22:22:22'));
        $q6 = $this->db->insert('log_query_actions', array('created_time' => '33:33:33'));

        $this->db->trans_rollback();
In this case EVERYTHING IS ROLLEDBACK except $q2 and $q3.
What is happening with db_sales table that is commiting the changes? There are no internal relations, and Engine is INNODB not MyISAM


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

Username
  

Password
  





Latest Threads
v4.5.1 Bug Fix Released
by lokman
5 minutes ago
problem with textarea
by Nitin Arora
9 hours ago
Showing pdf on browser
by aarefi
9 hours ago
[4.5.1] Disabling the deb...
by keto
11 hours ago
directory structure
by badger
Today, 01:49 AM
Redirect with error vali...
by pippuccio76
Today, 01:41 AM
Pass custom variables to ...
by InsiteFX
Yesterday, 11:17 PM
How to run a single seede...
by kenjis
Yesterday, 05:41 PM
Codeigniter 4 extend core...
by kenjis
Yesterday, 05:26 PM
blocked by CORS policy
by kenjis
Yesterday, 05:17 PM

Forum Statistics
» Members: 84,332
» Latest member: gamebancaclick
» Forum threads: 77,553
» Forum posts: 375,876

Full Statistics

Search Forums

(Advanced Search)


Theme © iAndrew 2016 - Forum software by © MyBB