Welcome Guest, Not a member yet? Register   Sign In
Hey i need some suggestions
#1

[eluser]halwaraj[/eluser]
This is more of design based question.

I have to insert data into the DB. Data comes from a single page. The data needs to go to different tables.

The flow is as follows:
I have a controller from where I would call a function in a helper class to insert data into database. This class has to instantiate the model class that would then actually insert the data into DB.

Now, I tried to use the $this->load in the helper class but it is not allowed. Now, I loaded the Model class in controller and passed it as an argument to the function in helper class. This worked fine.

Now, I need to insert data to diff tables. So this does not look good to instantiate number of model class and pass them to helper class. The flow comes to the controller many times. So instantiating the classes and not using them does not look good.

Any suggestion?
#2

[eluser]halwaraj[/eluser]
Hey, no replies?

Ok I have a alternate way to instantiate the libraries.

Wht i intend to do is, I'll instantiate the classin the function in the controller and pass it to the helper class. Does that sound ok? or is there any issue wid ths aproch? May be somthn lik security issue? Please suggest.
#3

[eluser]jedd[/eluser]
Howdi. It does sound quite complex, no matter which approach you use. How big would your code be were it contained entirely within the controller. The logic aspect, I mean - obviously database interactions head out to the model(s).

I find helpers are good for things that are pretty standalone, not reliant upon context etc.
#4

[eluser]Vicente Russo[/eluser]
[quote author="halwaraj" date="1236944934"]Now, I tried to use the $this->load in the helper class but it is not allowed. Now, I loaded the Model class in controller and passed it as an argument to the function in helper class. This worked fine.[/quote]

Hi,

Try this on your helper, before $this->load

Code:
$CI =& get_instance();

Then, instead of $this-> you'll use $CI->load




Theme © iAndrew 2016 - Forum software by © MyBB