Welcome Guest, Not a member yet? Register   Sign In
hook doesn't redirect me
#1

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');

class Maintenance extends CI_Controller {
 
   public function index ()
   {
       $this->CI =& get_instance();
       
       $this->CI->options_params = $this->CI->m_options->get_options();
       
       $off   = new DateTime($this->CI->options_params[0]->off_ligne);
       $today = date("Y-m-d H:i:s");
       $now   = new DateTime($today);
       $interval = $now->diff($off);
       $decal    = $interval->format('%a');
       $signe    = $interval->format('%R');
       
         if ($this->CI->options_params[0]->maintenance == 1 && $this->config->item('acces')[$_SERVER['mail']] === 'admin')
         {
             if ($signe === "-")
             {
                 
                 echo "<div> TOTO </div>";
             }
         }
     
   }
   
}

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
Reply
#2

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.
Reply
#3

(03-19-2018, 08:28 AM)Narf Wrote: 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.

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.
Reply
#4

(This post was last modified: 03-20-2018, 02:49 AM by Cognie.)

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()
   {
''
Reply
#5

Why not just use a MY_Controller?

That's the first Controller loaded after index.php
What did you Try? What did you Get? What did you Expect?

Joined CodeIgniter Community 2009.  ( Skype: insitfx )
Reply
#6

(03-20-2018, 04:18 AM)InsiteFX Wrote: Why not just use a MY_Controller?

That's the first Controller loaded after index.php

I didn't want to work in the core system  Sad
Reply




Theme © iAndrew 2016 - Forum software by © MyBB