Love Fuel?    Donate

FuelPHP Forums

Ask your question about FuelPHP in the appropriate forum, or help others by answering their questions.
using a model from another app in a package
  • REST

        app


            classes


                model


                    restmodel.php






    In restmodel.php




    namespace Rest;

    class Model_Restmodel extends Model

    {

    function duh(){

    return "duh";

    }

    }





    packages


        businessrules


            classes


                check.php






    In check.php



    namespace BusinessRules;

    use Rest;

    class check

    {

        function test($id)

        {

            echo “test ”.$id;

            $model = new \Rest\Model_Restmodel;

            echo $model->duh();



        }

    }

    ADMIN


        app


            classes


                controller  


                    xml.php




    In xml.php



    class Controller_Xml extends Controller_Template

    function action_check()
    {
        $check = new BusinessRules\check;
        $check->test(12);
        exit;
    }







    Output:




    admin.local/xml/check






    ErrorException [ Error ]: Class 'Rest\Model_Restmodel' not found




    Question: how to enable the use of Restmodel in check.php?




  • This is a bit unreadable, please use http://bin.fuelphp.com for a code paste next time.

    If with 'app' you mean two different FuelPHP installations, then direct access is never possible. They are not aware of each other.

    Within the same app, it should be possible (providing the packages/modules are loaded, namespaces are known, etc), but it is frowned upon, it creates tight coupling between two not-coupled application components, which should be avoided at all costs.

    Instead, do a REST call (if another application) or an HMVC call (if the same application), instead of calling the model class directly, to retrieve the information.
  • Thanks Harro, will call the REST 

Howdy, Stranger!

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

In this Discussion