Welcome Guest, Not a member yet? Register   Sign In
What are the features of codeigniter that you admire most?

Hi all I just started codeigniting here few weeks back.And I found the following code features and libraries most useful which will reduce the redundant code.

--Table generation from the database query results
--Automatic Form validation
--Division of model view controller
--Easy to use for those who are moving from procedural programming to Object oriented
--URL helper
--Pagination facility

But I think I need to know more features which will reduce my coding time. Can any one please tell me any features other than the above ones which will reduce the redundant code.
Or share any of the techniques you usually use to effectively utilise codeigniter.
Thanks in advance..

I usually recommend the user guide and these forums. I too recently made the switch from procedural PHP to OOP & MVC. I can say without a doubt that the value of my code has multiplied by a factor of at least 10 since stumbling on this beautiful framework. My projects went from 2000 lines of spaghetti code to wonderfully organized MVC PHP classes that I would no longer be ashamed to let someone else edit.

Features and libraries I like the best? All of them! Every time I need to do something and I become familiar with a new library, I think... "EllisLab has done it again, they REALLY thought this through". I absolutely love the class/method friendly URL structure and can't imagine going back to something nasty like the dispatch method (big nasty file full of functions, small files which include the big nasty and call necessary function). I also love the database class and ease of use of active record. I used to have this same nasty block of code at almost EVERY database call:
$query = "SELECT * FROM `something` WHERE `something` = 'something' LIMIT 1";
$results = mysql_query($query);
$output = '';

          ) = mysql_fetch_row($results)
     $output .= "<markup>$field1</markup>

echo $output;

You'd see something like this ALL OVER THE PLACE in my code. Not to mention having markup tied to the code because of the lack of MVC. Anyways, I could go on about this all day and still not answer your actual question which is "How can I reduce my redundant code". The answer is... I don't know.

CI is a bit like Ronseal. 'does exactly what it says on the tin'

Thank you slowgary. I just wanted to know if any of you are using any other class functions for doing some thing which we see in every other website designing project.Like the one table generation from sql query results with just 3 lines of code (loading table class,executing query, generating table from query results

$query = $this->db->query("SELECT * FROM my_table");

echo $this->table->generate($query);
Like this are there any other techniques which will reduce the code.

You are looking for something like a cookbook style response?

well there are several CRUD libraries available for CI that can make building admin forms much easier than using the default scaffolding.
Personally I have built my own CRUD library so that I only have to write code for the exceptions (not errors but code that is different from the default)
I have a few predefined methods that can be handled by the CRUD library
index - show the list of records for a model (the R in the CRUD - stand for Retrieve)
edit - add or edit of a record (C and U from CRUD, Create and Update)
delete - delete a record (D from CRUD for delete of course)

In the index the library gathers data from the model to determine what query to use to load the list of records
It then handles all filtering and pagination
Finally it passes the data to the view to be displayed.
Now the exceptions might be handling of specific filters (search on keyword is handled automatically based on properties of the model), or manipulation of the data to be viewed before it is sent to the view.
To handle the specific filters there is a method in the model called get_filter_values() where I can put model specific code to handle the filters that I need.
To handle the modification of the view data before the view processes the controller can have a _before_index_view() method which can process the data and then return it so that it can be modified before it is passed to the view.
The code is of course checking to see if the methods exist before they are called to make sure there are no errors if the methods do not exists. This means that the code is neater because I do not need to have expty methods in the controller when they are not needed.

These are only a couple of examples of the exception methods that I have in my CRUD library, but with them I have so far found that there is no admin data entry form I have not been able to create.

creating a new form is fairly straight forward with my CRUD library
first i create the model (i.e. post, always singular)
Then I add the properties to the model that describe how to retrieve the list of records, how to do keywords searching, ordering, and the language file to use, and field validation rules
Then I will add the exception methods to the model to process the filtering. one gets the filter results and adds the where clauses to the queries. the other gathers the data for the filter select lists, i.e. getting a list of users for display in a select list.
Next I create the Controller which is named as the pural version of the model (i.e. posts)
I add properties to the controller to indicate that it should use CRUD, and which layout template it should user and the user level required to view the controller (i.e. admin, user or some other custom values)
Then I create the _before_index_view() method to do anything required before the view is shown. This not only includes modification to data, but also is useful for loading extra helpers that might be necessary.
The I create the _before_validation() method if needed that allows me to sanitise the form data before validation, i.e. process any date fields to make them a real date rather then the 3 select lists that I use.
Next the _before_edit_save() and _after_edit_save() methods allow me to process the data before and after save. The Model also has these methods and both will be called if they exist. The controller version is better for saving related data in other models, while the model versions are best for further modification of the model data such as setting default values.
There is also a _before_edit_view() method which can be used to modify the view data, load any extra view data or load helpers etc.

Then I create the necessary index, and edit views. I have helpers that allow a lot of this to be automated as well doing things such as
- displaying filters
- displaying column headers with sort links if specified in the model
- displaying fields - this takes hints in the model to indicate the field type and some information about how it should be displayed, it then displays the field as indicated i.e. text, textarea, select list etc,. The field has a title which is shown automatically, with optional description text as title on the label so it shows on rollover, and also displayed any validation errors for the field.

Finally last thing is to create the language file which contains all of the text. This includes field titles and description text plus any incidental text that is displayed for the views.

While this might sound like a lot of work, for some models there is little to no effort involved because there is little to no modifications required to the default processing

I have tried to build CRUD systems like this previously before coming to CI but with CI it is just so much easier.
The one thing I do do that is probably frowned upon by some is that I do not extend the core libraries, but modify them direectly. this means my code only runs if the modified CI system code is used, default CI system files will not work with my projects.

So it is things like this that help me to reduce code

Things I really like in CI:
- Small and fast codebase
- Ease of use
- Sane conventions, very few restrictions
- Sane routing/dispatch model, which is easy altered (using either routes or _remap)
- AR class
- Doesn't get in the way, no weird automagic 'helping' functions I don't want
- KISS: everything not needed is not loaded by default. Extend functionality through libraries.

The most important one is:
- The ability to overwrite just about anything to your personal liking

Theme © iAndrew 2016 - Forum software by © MyBB