Love Fuel?    Donate

FuelPHP Forums

Ask your question about FuelPHP in the appropriate forum, or help others by answering their questions.
no layout class
  • Hi I want to send some datas (json data) on a form so I don't want to display any layout with it. How can I display a page with no layout? here is my method public function action_upload($id = null)
    {
    /**/
    $photo = '';
    // Custom configuration for this upload
    $config = array(
    'path' => DOCROOT.'assets'.DS.'photo',
    'ext_whitelist' => array('jpg','gif','png'),
    ); // process the uploaded files in $_FILES
    Upload::process($config);
    //var_dump($_FILES);
    // if there are any valid files
    if (Upload::is_valid())
    {
    // save them according to the config
    Upload::save();
    // call a model method to update the database
    $addfile =Upload::get_files();
    //var_dump($addfile);
    $i= 0;
    foreach($addfile as $file)
    {
    $relidQuery = Model_Phototheque::find('last');
    $relid = $relidQuery->id + 1 ;
    $upload = Model_Upload::forge();
    $upload->relid = $relid;
    $upload->document = $addfile[$i];
    $result = $upload->save();
    $i++;
    } header('Vary: Accept');
    $json = json_encode($addfile); if (isset($_SERVER) &&
    (strpos($_SERVER, 'application/json') !== false)) {
    header('Content-type: application/json');
    } else {
    header('Content-type: text/plain');
    } echo $json;
    } when the code send me the array $json, the html code of my page is included, I just want to display my array $json, I'm looking for a "no layout" class... can't find it in the doc.
    Can someone help me. thank you
  • You don't have to do all that, Fuel will take care of that for you. If you have a controller that only contains REST methods (that in your example return json), extend Controller_Rest instead of Controller_Template. If you want to mix interactive actions and REST responses, extend Controller_Hybrid. Both are available in 1.1/develop, and documented in the devdocs.
  • thank you, I'm trying to use the Controller_Hybrid, I have fuelphp 1.1 so it doesn't recognize this controller, can you please tell me where I can't find the 1.1/develop version? moreover the controller I 'll change for Controller_Hybrid is a Controller_Admin, is it possible? I need to keep my admin features. Thank you
  • You can install 1.1/develop directly from github, either through cloning the repositories using the procedure in the docs or the instructions in the readme, or by downloading the zip files. Note that both app, core and all packages have to be the same version. You can also wait a few days, we're busy preparing for the release of 1.2, if you don't want to work with a development version. You should keep using Controller_Admin if you need that. But I assume Controller_Admin at the moment extends Controller_Template, and you should swap that by Controller_Hybrid.
  • I tried to change version but it cause me a lot of errors, so I it would easier to add the hybrid class to my current version I tried to add 'core/classes/controller/hybrid.php' and modify the bootstrap.php, but it still doesn't work, is there any other file I need to modify to make the hybrid class work on fuel v1.1? Or is there an other way to only display my json result? no view... or layout? or can I have 2 controller in one file like
    photos.php
    class Controller_Admin_Photos extends Controller_Admin
    {
    }
    class Controller_Upload extends Controller_Rest
    {
    }
    if yes, how can I each my controller Controller_Upload ? thank you
  • I don't think it's easy to get it to work on 1.1/release, too much has changed. In the 1.1/release template controller you can disable auto rendering of the template by setting the class property "$auto_render" to false.

Howdy, Stranger!

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

In this Discussion