Love Fuel?    Donate

FuelPHP Forums

Ask your question about FuelPHP in the appropriate forum, or help others by answering their questions.
Controller in package
  • Can I make controller in my package? I need it for captcha output.
  • If it's loadable by the autoloader it can be used as a controller. Thus must be in global namespace and registered in bootstrap.php. It is bad-practice though, packages are functional additions to Fuel - not front-end. If you need a controller it might be better for it to be a module.
  • Jelmer Schreuder wrote on 02/11/11 2:26 pm:
    If it's loadable by the autoloader it can be used as a controller. Thus must be in global namespace and registered in bootstrap.php. It is bad-practice though, packages are functional additions to Fuel - not front-end. If you need a controller it might be better for it to be a module.

    I have method \Captcha::generate() in my package, it outputs image.
      ... code of generation image captcha ...
      header('Expires: Mon, 26 Jul 1997 05:00:00 GMT'); 
      header('Cache-Control: no-store, no-cache, must-revalidate'); 
      header('Cache-Control: post-check=0, pre-check=0', false); 
      header('Pragma: no-cache');
      
      if(function_exists('imagejpeg'))
      {
       header('Content-Type: image/jpeg');
       imagejpeg($img2, null, static::$jpeg_quality);
      }
      else if(function_exists('imagegif'))
      {
       header('Content-Type: image/gif');
       imagegif($img2);
      }
      else if(function_exists('imagepng'))
      {
       header('Content-Type: image/x-png');
       imagepng($img2);
      }
    

    In my controller I need to insert this image. I can create /captcha controller and put in it \Captcha::generate(), but in every new project I must to copy this controller. I'm thinking now how to automotize this.
  • As I said, I think it should be a module instead of a package if you want it routable. But in this case I'd suggest to just create a function that one can put in any controller method and does all this. One other pointer, we have an output class with a method for using HTTP headers:
    \Output::set_header('Expires', 'Mon, 26 Jul 1997 05:00:00 GMT');
    // note that it's the name and value, no colon and 2 values
    

    Edit: nevermind what I said about core namespaces earlier, I forgot we optimized that long ago.
  • Jelmer Schreuder wrote on 02/11/11 2:47 pm:
    As I said, I think it should be a module instead of a package if you want it routable. But in this case I'd suggest to just create a function that one can put in any controller method and does all this. One other pointer, we have an output class with a method for using HTTP headers:
    \Output::set_header('Expires', 'Mon, 26 Jul 1997 05:00:00 GMT');
    // note that it's the name and value, no colon and 2 values
    

    Edit: nevermind what I said about core namespaces earlier, I forgot we optimized that long ago.

    I fix issue with headers. My dream is dynamic routing and package controllers:D
  • - Dynamic Routing
    Extend the Router class and make it work however you want - Package controllers
    Nothing is stopping you, it's just not what it's meant to do. Packages are non-application specific non-routable functional extensions of the core. What you want is a module, which we already implemented as such.
  • There is a problem with \Output::set_header(). I need second parameter of php header() function:
    void header ( string $string [, [b]bool $replace = true[/b] [, int $http_response_code ]] )
    
    In Fuel it always sets to true. In my code I use false to stop cache image in MSIE.
  • Good point, gotta think about this one...

Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

In this Discussion