After a little digging I discovered that fuel php's parser is looking for a class Twig_Autoloader which used to be located inside ..../lib/Twig/Autoloader.php and that has been deprecated in Twig's version 2.x which I was using.
After removing 2.x and installing 1.x no more errors.
The parser needs to be worked on to make it compatible with twig 2.x.
1. In php I can call Asset::img and pass it attributes e.t.c how can I do the same thing in Twig? I saw asset_img() on a website but I don't know how to pass it attributes and it's not in the documentation.
2. Is there a way to get an image asset without knowing the extension? i.e I know it must be named logo but it can be logo.jpg, logo.png, logo.svg e.t.c
The code defaults to 2.x, but has a fallback to 1.x, so it shouldn't break anything.
If you want to test it, just change the composer.json to load
"fuel/parser": "dev-1.9/develop"
and run a composer update. After testing, put the old line back again, and run another update to go back to the 1.8 release code.
The functions are defined in the parser package, in Twig_Fuel_Extension. These are the only Fuel internal functions that are available in your templates.
In twig, you call a function like you would do in PHP, so in this case something like:
{{ asset_img('myimages.png') }}
No, there is no way to "guess" an extension. If you want to do that, you need to do that in your controller (or preferrable, your presenter as it is not really controller code):
// untested, from the top of my head $logo = ''; foreach (array('jpg', 'png', 'svg' as $ext) { if ($logo = Asset::find_file('logo.'.$ext, 'img')) { break; } }
and pass $logo as a variable to your template. Or extend the parser class, and add your own custom extensions so you can do this using a template function.
Under app/classes I created twig/fuel/extension.php (how it was created in the parser package) then I created a class Twig_Fuel_Extension
class Twig_Fuel_Extension extends \Parser\Twig_Fuel_Extension {
public function getFunctions() {
return array();
}
}
Then I created a config/parser.php which contains
return array(
'View_Twig' => array(
'extensions' => array(
'Twig_Fuel_Extension'
)
)
);
But this doesn't work as I'm still able to use all functions defined. How can I easily override any part of the parser class without having to modify the core code?
It's a different controller. I have Controller_Admin_Country which extends Controller_Admin. It includes every thing necessary to interact with countries. Since states will also have more than one methods I decided to split it into it's own controller (Controller_Admin_State) instead of creating action_state inside Controller_Admin_Country.
I'll still have urls like admin/country/1/state/delete/1, /admin/country/1/state/edit/1 e.t.c. I wish routing can be as flexible as in django and express js. Probably you can consider having that sort of option in future versions.
Fuel has dynamic routing to controllers for URL's like /controller/method or /namespace/controller/method.
If you don't want that, you need to block dynamic routes to those controllers, either by using specific routes like:
'admin' => 'welcome/404'
or
'admin/state' => 'welcome/404'
or even as catch-all
'.*' => 'welcome/404'
(or whatever your 404 handler is). Note that routes are processed in sequence, so make sure that if you use these routes, you add them BELOW the more specific routes you have, and if you use the catch-all, make sure it is the last route defined.
If I change the method to action_fetch_sub_category($category_id), when I navigate from browser I get a json response with a text at the beginning saying 'This REST page returned array or object.' But with ajax call I keep getting Internal Server Error.