Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 1052291
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 16, 20262026-05-16T17:04:15+00:00 2026-05-16T17:04:15+00:00

I have recently started using the CodeIgniter framework for my PHP development. I was

  • 0

I have recently started using the CodeIgniter framework for my PHP development.

I was just curious as to correct usage.

Essentially I have the following situation.

I have a controller entitled ‘items’

I want it so if the user goes to items/index they get a list of caetgories, if they go to items/category-name they get a list of items.

To achieve this, I have the one controller with an if/elseif statement which loads different views. Is this the correct approach?

If i am on a items/category-name page, I load a view entitled ‘items-list’
I pass a variable entitled $type to this view.

In the view it detects this type (again with an if statement) and outputs the category title (also passed). Simple.

As well as this I have a completely different controller for a recently sold items list (dont ask :)). As the format of the list to display is essentially the same I utilize the same view, but pass a different $type var. The view detects this, outputs various ‘extra’ links, images etc and of course does not output a ‘categories’ title.

Essentially I have 2 controllers utilizing one view. With various if/elseif statements in both the controllers and the view to get the right output.

Is this the correct approach?

Thanks

  • 1 1 Answer
  • 2 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-16T17:04:16+00:00Added an answer on May 16, 2026 at 5:04 pm

    In short…

    there is no single right or wrong way to structure your controllers/views/models/libraries/helpers.

    I too use CI, and I’ve found that controllers with the smallest amount of code in each controller method are the easiest to go back to and edit/maintain/upgrade/read. If too much logic is placed in my controller methods, clarity and understanding gets lost. I try to place most of my ‘logic’ in library or helper methods, so my controller methods are simple and easy to read.

    I like to have the controller accept arguments/data, send it to models and/or library and helper methods, which return modified or new data. The returned data might get sent to other methods before finally being sent to a view.

    This technique does tend to send you chasing around multiple files when writing an app or site, but achieves a clear separation of views and logic. Hopefully, it helps you write re-usable code too, even if it is only re-usable in the single app.

    Whatever works for you and your team, is okay.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have recently started to learn using of Doctrine 2.0 framework for PHP. Now
I have recently started using Netbeans with following stack Liferay, icefaces with jBoss. Is
I have recently started using Zend Studio which has reported as warning the following
I have been using the encryption class of codeigniter (PHP framework) for a while
I recently started using android actionbars and contextual action bars (CAB). I have just
I have just recently started using ReSharper and am looking for a way of
I've just recently started using VS2008 for a new tools project, and have been
I recently started using WPF and the MVVM framework, one thing that I have
I have recently started testing for my android application using Instrumentation framework. I have
I have recently started using Zend Framework. I started developing on my local XAMPP

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.