• 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
An easy way to execute a method from the view ..

Wiredesignz, thanks for your reply as well. I can see your point. The reason I'm asking here is exactly that I'd like to explore the possibilities and to see what makes coding and not.

The thing is, that I want to offer several, easy to access functions to designers to display several elements in the template. The examples I mentioned above are just some I could think of right away. An example of a helper function, I'm experimenting with now:

top_menu(array('section'=>1, 'format'=>'list', 'id'=> 'menu', 'class'=>'my_menu'));

This way a designer can easily get the right menu structure printed on screen, with minimal coding. That's what I'm after. And it works perfectly, I must say.

The method you proposed I understand completely, and this is usually the the way I work with CI. However, if I have a collection of 100 different functions, and all of these functions are going to be executed, this will affect the loading times in the end. Or am I mis interpretating something in your code?

If you have any other suggestions, please share them!! I'm in no way stuck to this approach, so if there are better options, by all means!

Cheers, Michiel

Generally if you want designers to avoid code you need to use a template parser and give them a list of {substitutions} to use.

Where do you get 100 different methods to build a menu from?

I still cannot recommend using a library as a model, or generating HTML in a library, even loading the smallest view partial is better than this.

CI itself should even have a system/views directory rather than generate HTML in its libraries.

Off course you can use a complete template parsing method, but in this case I'd rather use something in the middle: easy to use and understand functions, that can save designers some work.

"Where do you get 100 different methods to build a menu from?"

I'm not just talking about building a simple menu. Look at some of the examples I posted in my first post. Things that come to mind:

- complete menu tree
- subpages of the current page
- next/ previous sibling page
- number of users online
- list of bread crumbs

And I'm sure that along the way I will add more. So you're right. At this point I might not have 100 methods. But I anticipate to be including more of these 'helper' functions. Then to me it seems wrong to be executing all of them, if most of them won't be used in a particular page.


So you are really after load-on-demand models rather than pre-loaded models.

This is something you can achieve with a bit of thought. Particularly if you are using PHP5.

"So you are really after load-on-demand models rather than pre-loaded models."


Right now the easiest way seemed to be using helper functions .. but if there are better options, I'd sure like to learn more about it. I'm running PHP5, btw.


Create a helper, named autoload_model_helper() use spl_autoload_register('autoload_model') somewhere after the helper is loaded.

This idea is untested but gives you a starting point.

Removed code because this method of loading models needs to be developed more thoroughly.

If you are still determined to use the library method then at least load a model in your library or helper instead of making db calls directly.

Imagine if you do have 100 helpers and need to alter the db structure, at least using a model for obtaining data means your db code is centralised.

Digg   Delicious   Reddit   Facebook   Twitter   StumbleUpon  

  Theme © 2014 iAndrew  
Powered By MyBB, © 2002-2020 MyBB Group.