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

[eluser]sudinem[/eluser]
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 !!!!

Sudinem
#2

[eluser]danmontgomery[/eluser]
http://ellislab.com/codeigniter/user-gui...lpers.html
#3

[eluser]sudinem[/eluser]
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.

Sudinem
#4

[eluser]bretticus[/eluser]
[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...

However...

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.)
#5

[eluser]sudinem[/eluser]
thanx bretticus 4 ur reply

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

Sudinem
#6

[eluser]sudinem[/eluser]
How to call model's function inside the helper function???

Is it possible to call??
#7

[eluser]bretticus[/eluser]
[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.

Code:
function some_helper_func()
{
  $CI =& get_instance();
  $CI->load->model('your_model');
  $CI->your_model->some_model_func();
}
#8

[eluser]sudinem[/eluser]
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
#9

[eluser]bretticus[/eluser]
[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:

Code:
$this->your_model->db->count_all()

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




Theme © iAndrew 2016 - Forum software by © MyBB