Love Fuel?    Donate

FuelPHP Forums

Ask your question about FuelPHP in the appropriate forum, or help others by answering their questions.
Can't use Modules in app/classes/controller
  • Hi, Still loving this framework started diving into it a bit more... The Fuel documentation I have seen indicates that you can use Request::factory('blah/blah)->execute(); to get your partial view and hold it for later processing.
    // Oops no partial returned so can't hold for later processing
    $data['test'] = Request::factory('test/index')->execute(); 
    

    The output of the controller is added to $this->output in the request class so trying to assign the output to a variable for later use in coding logic or a view doesn't apply you have to call the request in your view. Or am I missing something which is quite possible with the week I've just had :-)
  • Are you getting an error or what is produced by this? We always need the real error you're getting, preferably with line nr, file path & backtrace. (or a screenshot)
  • Jelmer, No errors just echo's output where ir called in the app/classes/controller App/classes/controller/welcome.php
    <?php
    /**
     * An example Controller.  This shows the most basic usage of a Controller.
     */
    class Controller_Welcome extends Controller {
    
    	public function action_index()
    	{
            $data['test'] = Request::factory('test/index')->execute();
            //echo '<pre>';
            //print_r($data['test']);
            //echo '</pre>';
    		$this->render('welcome/index', $data);
    	}
    
    	public function action_404()
    	{
    		// Set a HTTP 404 output header
    		Output::$status = 404;
    		$this->render('welcome/404');
    	}
    }
    

    modules/test/controller/test.php
    <?php
    
    namespace Test;
    
    // Extending the calling controller also works if we wish to implement something specific.
    //class Controller_Test extends \Controller_Welcome {
    class Controller_Test extends \Controller {
        public function action_index()
        {
            // Echo the required output to be captured as a partial
            echo Model_Test::hello_world();
        }
    }
    

    modules/test/classes/model/test.php
    <?php
    
    namespace Test;
    
    class Model_Test extends \Model {
    
        public static function hello_world()
        {
            return 'hello world!<br />';
        }
    }
    

    The print_r gives:
    Fuel\Core\Request Object
    (
        [paths] => Array
            (
                [0] => C:\xampp\htdocs\Customer_Sites\fuel\fuel\app\modules\test\
                [1] => C:\xampp\htdocs\Customer_Sites\fuel\fuel\app\modules\test\classes\
            )
    
        [output] => 
        [uri] => Fuel\Core\Uri Object
            (
                [uri] => test/index
                [segments] => Array
                    (
                        [0] => test
                        [1] => index
                    )
    
            )
    
        [module] => test
        [directory] => 
        [controller] => test
        [action] => index
        [method_params] => Array
            (
                [0] => 
            )
    
        [named_params] => Array
            (
            )
    
    )
    
  • The problem is that for this to work you can't use echo in the controller (always a bad idea btw) and you have to assign the output to $this->output within the controller. If you do that this should work fine (the Request object is fully initialized the way it should, and I assume did execute).
  • Jelmer, No I don't use echo in controllers it was just a test. That works fine and I get it now having looked at the request class again and after getting a few hours sleep (these deadlines are killing me) :-) Finished the project I was working on so I will look at Fuel some more now. Thanks for your help Jelmer it's much appreciated.

Howdy, Stranger!

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

In this Discussion