Love Fuel?    Donate

FuelPHP Forums

Ask your question about FuelPHP in the appropriate forum, or help others by answering their questions.
[HELP] my module's controller cannot use $this->output
  • I hope the title already tell about my problem clearly.
    In my module's controller `echo Model_Core::hello();` works, while `$this->output = Model_Core::hello();` doesn't work But to make it clear, here is my controller:
    namespace Nox;
    class Controller_Nox extends \Controller{
        //put your code here
        public function action_index(){
            $this->output = Model_Core::hello(); //this isn't work
            //echo Model_Core::hello(); //this is work
        }
    }
    

    and here is my model
    namespace nox;
    class Model_Core {
        //put your code here
        
        public static function hello(){
            return "Hello World";
        }
    }
    

    I make my module based on http://scrp.at/py
    Any body has such a problem?
  • First of all: this has nothing to do with the Controller being inside a module. I don't think that ever worked in an official stable release, if my memory is correct this may have worked an the 1.0-beta1 release. The $this->output property does nothing and has no meaning beyond what you might give it. The controller actions must return whatever you want to output or return a Response object with whatever you want to output. The following will work:
    namespace Nox;
    
    class Controller_Nox extends \Controller
    {
        public function action_index()
        {
            return Model_Core::hello();
        }
    }
    

    As a sidenote: you're using different casing for your namespace in the Model than in the Controller. While this will probably work fine it is considered very bad practice to do so.
  • Hi, Jelmer, thanks for your quick response. Also thanks for your (and FuelPHP team) hardwork. I can see that FuelPHP has a very good architecture compared with CodeIgniter, and I plan to migrate from CI to FuelPHP As you suggested, it's now work. I even just realize that I've use different case for namespace, good spot :D BTW, is it also the case when we work with template controller? I try to use oil for automatic controller generation purpose
    php oil generate controller coba
    

    And as expected, it created a set of file, including a view and a controller. Here is the controller.
    <?php
    
    class Controller_Coba extends Controller_Template
    {
    
     public function action_index()
     {
      $this->template->title = 'Coba &raquo; Index';
      $this->template->content = View::forge('coba/index');
                    //return $this->template; //I add this and believe it will work, but not
     }
    
    }
    
    ?>
    

    and I don't get anything, neither if I add `return $this->template` or not.
    So what's wrong this time? EDIT : BTW, how could I change the title of this topic, I want to change `help` into `partially solved`, so that everyone else will know that this issue was partially solved and not ask the same question :D EDIT AGAIN (Really Solved) : Damn, my template (fuel/app/views/template.php) is empty. After I add
    <!DOCTYPE html>
        <html>
        <head>
            <meta charset="utf-8">
            <title><?php echo $title; ?></title>
        
            <?php //echo Asset::css('main.css'); ?>
        </head>
        <body>
            <div id="wrapper">
                <h1><?php echo $title; ?></h1>
        
                <div id="content">
                    <?php echo $content; ?>
                </div>
            </div>
        </body>
        </html>
    
    to the template, everything work as expected. I think the documentation about controller should also be updated to avoid confussion
    ;)

Howdy, Stranger!

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

In this Discussion