Love Fuel?    Donate

FuelPHP Forums

Ask your question about FuelPHP in the appropriate forum, or help others by answering their questions.
new to frameworks, some questions about structure and session control
  • Hey everybody. I was looking into re-building my site when a friend recommended fuelPhp. I've never used a framework before so it's been a little weird seeing how abstract everything is, but thats the point right! Anyways I'm pretty impressed so far. I was definitely re-inventing the wheel so to speak writing everything from scratch. I have two main questions. 1) Basically I'm wondering how you structure your code / document structure when you want to bring in outside resources (outside of the core lib). For example I have a class I use for generating hash tokens, encrypting pw's and stuff to that affect. Sure I can add those methods to each controller but that seems redundant. Or like using a recapatcha, or facebooks SDK, where would you import those libraries? In the views or something? 2)Kinda along the same lines but the site im building relies on session control. At the top of every page I create an instance of my session class that basically says if you're not logged in then back to login.php or whatever. How would I duplicate this functionality I get that you can set and get a user id and do something like $userid = Session::get('userid');
    if ( $userid === false )
    {
    Response::redirect('login/');
    } but wouldn't you have to put that line of code in every action in every controller? I must be missing something. thanks in advance.
  • As to your first question, create it as a static class, and store in in app/classes. You can then simply access it from any controller/model/view using a static call ( class::method(); ). Fuel will take care of loading it when needed. Sessions get initialized when the session class is loaded. This is either the first time you call one of it's methods, or during initalisation of the page request if you have configured the session class to be autoloaded in your app/config/config.php. For generic code that's applicable to multiple controllers, create a base controller that contains this functionality, and have your controllers extend that to incorporate it. Have a look at the template base controller included, in core/classes/controller/template.php for an example of such a base controller (it is also described in the docs).
  • This is how am doing it http://scrp.at/24 hope this helps.
  • Great thanks for the help

Howdy, Stranger!

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

In this Discussion