Love Fuel?    Donate

FuelPHP Forums

Ask your question about FuelPHP in the appropriate forum, or help others by answering their questions.
Redirecting to a new page in a new link.
  • Does anyone knows how to redirect a <a> to a new page from a .tpl file.

    In my project i have a module and in that module there is a page that has a link at the bottom and i want that link to link to a page.

    Should i make another module or just a .tpl?
  • Links within the application always point to a controller method. A FuelPHP application has no "page" concept, that's more of a CMS or a static website thing.

    The code in the controller method determines what should happen, but thats entirely application specific and up to you.

    You generate HTML anchors using Html::anchor(), which will generate it taking your configuration into account. You should avoid hardcoding any links, as your application will break if you decide to move it, install it in a folder, or apply some rewriting.
  • oo what will i need to make? ahm do i need to make another html file?....in the controller folder there is an edit file where there are functions that uses smarty to open the .tpl...and in that .tpl file there is an <a> tag and i need to redirect it to a page....do you have some suggestions or ways how to do it? Thank you in advance sir.
  • HarroHarro
    Accepted Answer
    I think you need to understand the design concepts of a FuelPHP application.

    An application consists of Controllers, and each controller defines action methods. URI's map directly to controller actions, so a URI path like '/user/login' will map to the controller "Controller_User", and the method "action_login".

    So if you want to create a link to this action, you need to add something like

    echo Html::anchor('user/login', 'Please login');

    to your view file, so the correct link is generated. If you want to add the anchor manually, you'll need to use Uri::create() to generate the href.

    In your controller action, you create and return a View object which will generate the HTML for the page using a view template. If you want View objects to use smarty template, install the Parser package, enable Smarty, and configure the ".tpl" extension for it (by default it's assigned to the Twig library).

    In a FuelPHP application, you NEVER output anything directly in the code. No echo's, no prints, no anything. It will not work properly.
  • ok sir..the smarty is already integrated within the system. With regards with the Please login in the html::anchor is it the value like <a>Please login</a>? and about the Uri::create() am i going to put it within the function? how about the <a> inside the .tpl? how would i be able to use it? because in the code, a forge function was used to open the .tpl file, for example forge('edit.tpl', this->data); 
  • I'm afraid I can't help you further on this, as it is Smarty specific, not FuelPHP specific.

    My Smarty knowledge is very rusty, but I can recall you either have to allow PHP in your templates to be able to call framework methods, or create a Smarty plugin that will provide a smarty command for the designed Framework method.

    With functions you could hack them in by pretenting they are modifiers, but I don't think this will work with method calls.

    Consult your Smarty documentation, or perhaps someone on the Smarty forum can give you some pointers.
  • ok thank you for the help sir

Howdy, Stranger!

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

In this Discussion