Love Fuel?    Donate

FuelPHP Forums

Ask your question about FuelPHP in the appropriate forum, or help others by answering their questions.
How to call user find classes functions on fuelphp?
  • im new to frameworks and I would like to try this framework as my 1st one... would some1 tell me how to call user defined classes functions to either views and controllers.. for example:
    i have "Book" class in my directory "app/classses/my_classes/book.php"...
    how do i call it??
    should i just call it like this "Book::my_function()"?
  • Check docs : http://fuelphp.com/docs/general/controllers/base.html
    Only 1 level of subdirectories is currently supported.

    You can create Book class in "app/classes/book.php" and then you can call a function like \Book::my_function()
  • wow.. it works thanks.. so only 1 lvl subdirectory is allowed.. my mistake is I make a new folder "my_classes" . anyways thanks
  • Actually, that statement was always wrong and has been fixed in the docs in development:
    Only 1 level of subdirectories is auto-detected, if you want to go deeper you need to use routes to rewrite the subdirectory to a controller name (which uses underscores instead of slashes).

    If you want deeper controllers you need to understand autoloading in Fuel: underscores in classnames = directory separators in the filename. Thus a controller Controller_Some_Deeper_Dir is in app/classes/controller/some/deeper/dir.php. By default you can call it using domain.com/some/deeper_dir but if you register the following route you can also call it with full slashes:
    'some/deeper/dir(/:any)?' => 'some_deeper_dir$1'
    

    Thus it's supported, just not automaticly. Which is because it'd take way to many unnecessary filesystem check to allow this unlimited for everyone.

Howdy, Stranger!

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

In this Discussion