Love Fuel?    Donate

FuelPHP Forums

Ask your question about FuelPHP in the appropriate forum, or help others by answering their questions.
Module class in view
  • Hey,

    When i want to use: 

    (...)
    <?php foreach (\Tasks\Tasks::get_all_tasks() as $val){ ?>
                      <tr>
                      <td class="primary"><?php echo Lang::get('tasks.possible_tasks.'.$val["alias"].'.translation'); ?></td>
                      <td><?php echo $val["user"]; ?></td>
                      <td><?php echo date('Y-m-d', $val["date"]); ?></td>
                          <td><?php echo date('H:i:s', $val["date"]); ?></td>
                          <td><span class="label label-<?php if ($val["running"] == 1){ echo 'success">'.Lang::get('tasks.status.'.$val["running"]); }else{ echo 'important">'.Lang::get('tasks.status.'.$val["running"]);} ?> </span></td>
                      <td>hi</td>
                      </tr>
                      <?php } ?>
    (...)

    The class tasks in modules/tasks/classes/tasks.php is availible.

    But I get the following error: 

    ErrorException [ Error ]: Class 'Tasks\Tasks' not found

    hope you can help me! <3

    greez
  • SyntaxlbSyntaxlb
    Accepted Answer
    Hi,

    Your module is loaded ? ( \Module::load('tasks'); )

    Or specify it in your config.php (always_load => module)
  • I have loaded the class from the modules config php always_load...

    greez
  • SyntaxlbSyntaxlb
    Accepted Answer
    It's work great on my project.

    U can access to your module function in a controller ?
  • <?php
    namespace Tasks;
    use Response;
    use View;
    use Uri;
    use Logged_in;
    class Controller_Tasks extends \Controller
    {
    public function before()
    {
    Logged_in::check();
    }
    public function action_overview()
    {
    $data['custom'] = FALSE;
    $data['page'] = 'tasks_overview';
    return Response::forge(View::forge('parts/main', $data, false));
    }

    }

    modules/tasks/classes/tasks.php

    When I want to use the Tasks-class from the view it fails with: 
    ErrorException [ Error ]: Class 'Tasks\Tasks' not found
  • SyntaxlbSyntaxlb
    Accepted Answer
    Can we see the content of your tasks.php file ?

    You have "namespace Tasks;" at the top of your tasks.php file ?
  • This class is called "Controller_Tasks", so a direct call would be \Tasks\Controller_Tasks ...

    And calling a controller directly is a bad idea, so I would suggest looking at your architecture again.
  • Forgot the Namespace, thank you!!! :) 

    greez
  • Forgot the Namespace! <3 Thank you!! 

Howdy, Stranger!

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

In this Discussion