• 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
What's the right place to put this? Writing a CMS in CI.


I've been busy starting up a CMS project in CI, but I'm sort of stuck where I should put the every-page-has-this code.

I'm talking about the dynamic header menu, breadcrumbs, page keywords/description/author tags, dynamic footer and that sort of stuff.

I tried the MY_Controller way, but this results in copy-paste coding since i still have to call it in every_single_method_call.

Now I'm trying to use a hook, but the problem with that is that I need the data that the hook holds (all the needed data for the specific request), to get in my views.

I then came across the application flow page, and figured I'd give config items a shot. This worked wonders weren't it for the following:

In each method i have a
array that holds the view data. Then i render that data. But this would require me to have the same line of code (assigning the config item array to the current data array) in every method that's in a controller (public ones ofcourse). Not very DRY.

Then I figured I could use multiple hooks of the type post_controller_constructor by multi-dimantionalising it.
$hooks[]['post_controller_constructor'] = ..
And since the second one (that is supposed to assign the current page-specific data to the view data array in the controller method is an index later, it'd grab everything and stuff would be awesome.

Problem with that? I haven't gotten the slightest clue how to assign the current array of page data to the view array.

Then i figured i'd skip the hook and try giving a data parameter to each function call in the controllers. the data parameter would be the page data and in the function call it'd do its magic, but this again, would be the same effect as the config item. A repetitive single line of code in each function.

How should I go about this? Is there a way to automate this? ;x

I should probably note, that to grab the current page-meta data (And for everything else database related) I'm using Doctrine, so I can't use pre_controller hooks as the libraries aren't loaded yet. (And I'm loving the autoload libraries array.)

Any help is greatly appreciated.

Is the topic start not clear enough? Sad

Aren't you not patient enough?

Don't know about you, but over here it's a public holiday weekend. And with temperatures of 30C I can imagine people have other things to do then answering your questions.

But I can give you a tip: you're taking the wrong approach by trying to build up everything in your methods.

Look for a template library, use the MY_Controller constructor to setup the page template, use the controller constructor to setup the recurring partials for that controller (like menu's, sidebars, etc) and only deal with the body partial in your method.

Yeah sorry, (Love your avatar btw =p ), I'll keep that in mind next time.

And that sounds pretty good, but how can MY_Controller access the view data? Right now, as im implementing stuff, the MY_Controller has a $data attribute that holds the page-meta data / menus and so forth, and per-page im calling
$this->data = ..
to add stuff, and then render it calling that same

Is this the best way? ;O

Digg   Delicious   Reddit   Facebook   Twitter   StumbleUpon  

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