![]() |
hook doesn't redirect me - Printable Version +- CodeIgniter Forums (https://forum.codeigniter.com) +-- Forum: Using CodeIgniter (https://forum.codeigniter.com/forumdisplay.php?fid=5) +--- Forum: General Help (https://forum.codeigniter.com/forumdisplay.php?fid=24) +--- Thread: hook doesn't redirect me (/showthread.php?tid=70282) |
hook doesn't redirect me - Cognie - 03-19-2018 Hi everyone, (Sorry for my english) I try to use hooks... It works but I've a small problem. I said to my hook: IF condition OK -> do... but I would like : IF condition not OK -> continue Code: <?php if ( ! defined('BASEPATH')) exit('No direct script access allowed'); When the condition is ok... it's good, the message is displayed and the application doen't continue... but when the condition is not ok... I've a blank page ... I would like that the application continue normaly. Someone to help me ? Thanks Marc RE: hook doesn't redirect me - Narf - 03-19-2018 Is that code your actual hook? If so, hooks are not controllers. You're not supposed to extend CI_Controller for a hook. Also, `get_instance()` means "get the controller instance", and you're doing that from inside a controller ... the same controller that would be returned by it. RE: hook doesn't redirect me - Cognie - 03-20-2018 (03-19-2018, 08:28 AM)Narf Wrote: Is that code your actual hook? Thanks ! I had to blend in with all the examples I found. My goal is to check if an entry in my database is at 1 and that we are a "user", to display an info ("site in maintenance") and otherwise continue normally. AND, if an entry in my database is at 1 and you are "admin" then you can navigate normally. Maybe my approach isn't optimal. I don't want to change a file to "hard" to do this but I want to go through an admin interface. Do you have a design tip? or, is the hook a good idea? Thanks a lot M. [RESOLVED] RE: hook doesn't redirect me - Cognie - 03-20-2018 Hey, I solved my problem (or problems). first (in my case), my hook had to be in'post_controller' and not in'pre_controller'. Then, I miscalled my config items in the case of a hook: $this->ci->config->item('access')' (here the right way) I put underneath a part of my hook '' class Maintenance { private $ci; public function __construct() { $this->ci =& get_instance(); $this->ci->options_params = $this->ci->m_options->get_options(); } public function go_maint() { '' RE: hook doesn't redirect me - InsiteFX - 03-20-2018 Why not just use a MY_Controller? That's the first Controller loaded after index.php RE: hook doesn't redirect me - Cognie - 03-20-2018 (03-20-2018, 04:18 AM)InsiteFX Wrote: Why not just use a MY_Controller? I didn't want to work in the core system ![]() |