Welcome Guest, Not a member yet? Register   Sign In
What to do???

I have created a dynamic drop down menu which I need to show it through out whole site. But, the problem is that I need to copy paste the code in each an every functions of the controller.

How can I reuse the code????
What to do ??
Plz help !!!!



I'm not asking about how to create a dropdown menu.

I'm asking instead of pasting the same code several times how can I manage to put it as the form of global variable.

I've tried to create a library but inside library I can't load the model so as to generate the result from database.


[quote author="sudinem" date="1268733025"]I'm not asking about how to create a dropdown menu.[/quote]

Not sure how you thought the suggestion of using a helper was explaining how to build a dropdown function...


A helper is a standard way of reusing code that performs a repetitive task (because an helper is just a collection of related functions.)

Your example, however, is a perfect candidate for a model (especially since you are using the database class.)

thanx bretticus 4 ur reply

I'm gonna try it and reply if sth goes wrong.


How to call model's function inside the helper function???

Is it possible to call??

[quote author="sudinem" date="1268779382"]How to call model's function inside the helper function???[/quote]

Why do you need to call it from a helper function? Why not call it directly?

the answer is, of course, to get an instance of the CI super object.

function some_helper_func()
  $CI =& get_instance();

A PHP Error was encountered

Severity: Notice

Message: Undefined property: Maker_Model::$db

Filename: models/maker_model.php

Line Number: 13

Fatal error: Call to a member function count_all() on a non-object in C:\Program Files\xampp\htdocs\CodeIgniter\system\application\models\maker_model.php on line 13

I got this error following ur instruction

[quote author="sudinem" date="1268783156"]
I got this error following ur instruction[/quote]

I haven't actually given you any instructions. I have never seen your code. Thus, I have done nothing more that make suggestions. That being said...

This notice (not an error) is generated from what seems to be you trying to access db as a property of your model. Yes, since models extend the Model class, you can access the db object via $this->db INSIDE your model class. You cannot access via:


Which I can only guess at because you haven't actually posted any code.

Theme © iAndrew 2016 - Forum software by © MyBB