Session Data vs. Config Variables |
11-09-2018, 02:52 AM
(This post was last modified: 11-09-2018, 06:40 PM by marwin. Edit Reason: Optimised the code ) (11-09-2018, 02:07 AM)Pertti Wrote: $custom_config_data = '<\?php ';It was incase me beeing stupid. I echoed the result and didnt write it - so that is why the code didnt show. I appologise! All working fine now. I think I format it with some linebreaks though. I also missed an array in the build code. If anyone wants to use the code, this is the final and working version. I just run a cronjob on the function in my heartbeat controller to update this regularly. I think once daily in the night will be best. // Load model $this->load->model('Page_m'); // Prepare custom config file $custom_config_data = '<?php'.PHP_EOL; $custom_config_data = $custom_config_data . 'defined(\'BASEPATH\') OR exit(\'No direct script access allowed\');'.PHP_EOL; // overviews $category = $this->Page_m->get(array('hidden' => 0, 'released' => TRUE), 'category'); foreach ($category as $key_fow => $value_fow) { // Get number of contents within origin $subentries = $this->Page_m->count_subnavigation($value_fow['id']); $custom_config_data = $custom_config_data . '$config[\'sub_navigation_entries_' . $value_fow['id'] . '\'] = '.var_export($subentries, true).';'.PHP_EOL; } // Write config file @file_put_contents('./application/config/sub_navigation_entries.php', $custom_config_data); } (11-09-2018, 07:20 AM)php_rocs Wrote: @marwin, Hi, yes MySQL and I am making extensive use of views but the menu is standard across all views with dynamic alterations. Actually I think in design one could have placed the information inside the settings table of the database (which is called anyway) and update the count whenever a new content is inserted. Honestly I would have preferred that but it would require a lot of recoding for every add-view and is rather messy because the project is already live. Thus I hope my approach provided a quick and easy solution even if it's a bit hacky. It's already implemented and updates through a cronjob now. |
Welcome Guest, Not a member yet? Register Sign In |