Welcome Guest, Not a member yet? Register   Sign In
  How can I pass multiple queries from different tables to a single view in CodeIgniter
Posted by: Butted - 04-18-2025, 08:27 AM - No Replies

Hi everyone,
I'm very new to CodeIgniter. I'm trying to send queries from the controller to a single view. I have two different functions, each with a different query, and I want to style their results differently in the same view.
Here’s my controller code:

Code:
public function publications()
{
    $query = $this->db->query('SELECT P_ID, TITLE FROM publications WHERE SSN = 1');
    $data['name'] = 'publications';
    $data['section'] = 'Publication';
    $data['query'] = $query;
    $this->load->view('adel', $data);
}
public function teaching()
{
    $query = $this->db->query('SELECT C_ID, DEP_CODE, C_NAME, C_DESC FROM TEACHING WHERE SSN = 1');
    $data['name'] = 'teaching';
    $data['section'] = 'Teaching';
    $data['query'] = $query;
    $this->load->view('adel', $data);
}
And here’s the corrected view code:
Code:
<div class="col-lg-12">
    <h1><?= $section ?></h1>
    <?php if ($name == 'publications'): ?>
        <?php foreach ($query->result() as $row): ?>
            <?= $row->P_ID ?>: <?= $row->TITLE ?><br><br>
        <?php endforeach; ?>
       
    <?php elseif ($name == 'teaching'): ?>
        <?php foreach ($query->result() as $row): ?>
            <?= $row->DEP_CODE ?><?= $row->C_ID ?> <?= $row->C_NAME ?><br>
            Course Description:<br>
            <?= $row->C_DESC ?><br><br>
        <?php endforeach; ?>
    <?php endif; ?>
</div>

Main fixes:
  • Use == for comparison, not = .
  • Use cleaner PHP short syntax inside HTML.
  • Close PHP properly for loops and conditions.


  Web Design & Development
Posted by: reriy6647 - 04-18-2025, 04:31 AM - Replies (7)

Hello! My name is Reriya, and I am a professional PHP Developer with a strong passion for creating dynamic and user-friendly websites. Over the years, I have developed several web projects that have received excellent feedback. Two of my most notable works are Golden Bird Jewels and Ouros Jewels, both of which have been well-received in the jewelry industry. I would love to share these projects with you for your feedback or potential collaboration. Please let me know if you'd be interested in taking a look!


  Database connection problems during installation
Posted by: SamuelRMcNabb - 04-17-2025, 09:59 PM - Replies (2)

Hello everyone,
I am currently trying to setup CodeIgniter and am having some issues with the database connection. I followed the instructions and still can't connect and still get an error message saying the connection could not be established.

Is anyone else having this issue. Please help me fix it asap.

Thanks!


  Understanding JSON Web Tokens (JWT) in JavaScript
Posted by: InsiteFX - 04-15-2025, 07:39 AM - Replies (1)

Understanding JSON Web Tokens (JWT) in JavaScript


  Proper use of migrations in a production project
Posted by: brunoggdev - 04-15-2025, 04:45 AM - Replies (1)

Hello!

I've started working on a CI4 project that is already running for a while now and has a bunch of complex data and db structure but does not uses migrations.

As the documentation itself states: 

Quote:You could edit fragments of SQL by hand but you would then be responsible for telling other developers that they need to go and run them. You would also have to keep track of which changes need to be run against the production machines next time you deploy.

And those are exactly the problems we are having!

That being said, I wanted to know how exactly are you supposed to use migrations in production. Should I configure my deploys to run the command "php spark migrate" automatically? Is it safe? What do you recommend as the correct approach and steps to do it correctly and safely?


  Command Line Tool
Posted by: okatse - 04-14-2025, 10:25 AM - Replies (3)

Executing the php spark command causes the message CodeIgniter v4.5.7 Command Line Tool - Server Time: 2025-04-14 18:46:24 UTC+02:00 to be displayed. Is there a way to disable this?


  how to check if url exists
Posted by: cb21 - 04-12-2025, 11:58 PM - Replies (3)

how to check if URL exists with codeigniter ?

I didn't find and try to do it with simple php but it is not as easy as I read. Maybe because php change and what works 10 years ago does not work today in 2025 with php 8 (I forget the decimal)
I try
curl_init($url))
  $headers = get_headers($url);
and differents easy solution but when I really check it it accept that it should not or I got php error message 
Do codeigniter have already done solution ?

I even try  if ( file_get_contents($url, 'FILE_TEXT', NULL, 0, 1))

But I got this kind of error  file_get_contents(): php_network_getaddresses: getaddrinfo for aaaaaaa failed: Temporary failure in name resolution
instead of true false
I try catch but always have erors  impossible to say if I have any kind of error it is false


  CodeIgniter Sandbox
Posted by: grimpirate - 04-12-2025, 08:50 PM - No Replies

Thought this might be useful to someone looking to try out CodeIgniter or if they happened to need a default install to test some ideas out:
CodeIgniter4 on phpsandbox.io


  404 Controller or its method is not found
Posted by: marvineferrer - 04-11-2025, 08:57 AM - No Replies

CI4 is brand new to me. I came from CI2 and barely CI3. So, I just installed a fresh copy of WAMP and CI 4.6.0. I have already pointed the doc root to the public folder of my project (htdocs/ci46/public). Then, I opened "localhost" on my browser and it works. So far, so good.
When I try to follow the tutorials, that's when I started encountering issues.

Issue #1: I have gone up to the point where I first run Pages.php in the tutorial. Then I encounter a 404 error when I load "localhost/pages". I get the same error when I try to load any existing and non-existing page. Only the default Home.php page loads. 

Issue #2: When I try to open "localhost/index.php" just to test it, the PHP code is displayed, in plain text! Something is definitely wrong here. 

I tried changing $urlProtocol to PATH_INFO but the issue is the same. When I use QUERY_STRING, I don't get the 404 message but the default page loads on any existing/non-existing page.

I have also tried enabling auto routing but the problem persists.

Either I'm doing something very wrong or I'm missing a crucial config during the setup. I have never experienced these issues in setting up the older versions. Any help is appreciated. Let me know if you guys need any additional information.

Thanks you!

Marv


  Set session expiration time based on user role in CodeIgniter 4
Posted by: Beewez - 04-11-2025, 06:18 AM - Replies (4)

Hi everyone,

I'm working with CodeIgniter 4 and I need to configure the session expiration time dynamically based on the user role at login.

I understand that, by default, CodeIgniter loads session settings from app/Config/Session.php, where the 'expiration' value is defined. However, this configuration is static and applied globally.

What I want to achieve is something like this:

  • If the user has the admin role, their session should last longer.
  • If the user has a standard role, the session should expire sooner.

I’m wondering if there’s a recommended way to override the session expiration time at runtime based on the user role. Is it possible to change the expiration after login, or would I need to implement a custom logic to handle expiration manually?

Any advice or example would be greatly appreciated.
Thanks in advance!


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

Username
  

Password
  





Latest Threads
My Library cannot see ses...
by InsiteFX
4 hours ago
Any user guid or video o...
by InsiteFX
4 hours ago
update the framework to t...
by captain-sensible
Yesterday, 12:14 PM
my controller fails to fi...
by paulbalandan
Yesterday, 11:20 AM
CodeIgniter Shield 1.0.0 ...
by Ayatorvi
Yesterday, 06:06 AM
MVC vs MVCS vs CodeIgnite...
by FlavioSuar
05-07-2025, 01:58 PM
Update to 4.6.1
by serialkiller
05-07-2025, 11:58 AM
Can't create new database...
by paulbalandan
05-07-2025, 08:49 AM
Help parsing the log file...
by sophia2005
05-07-2025, 05:02 AM
systemDirectory conundrum
by FlavioSuar
05-07-2025, 04:28 AM

Forum Statistics
» Members: 144,828
» Latest member: nhacaiuytinbaby
» Forum threads: 78,381
» Forum posts: 379,416

Full Statistics

Search Forums

(Advanced Search)


Theme © iAndrew 2016 - Forum software by © MyBB