Routing in PHP - Fat free framework gets strange results - php

For some reason, when I run this code, when adding an ID (the second block), my template doesn't seem to find my CSS/image files anymore.
But the code is exactly the same (apart from using an #id to request the parameter). Code framework that's been used is Fat-free framework.
This is my code:
$f3->route('GET /detail',
function($f3, $params) {
$test = new renderEngine;
$test->detail($f3, $params['id']);
}
);
$f3->route('GET /detail/#id',
function($f3, $params) {
$test = new renderEngine;
$test->detail($f3, $params['id']);
}
);
When checking in Chrome developer (or however you call the window) in the Sources tab I can see that in the first case it's:
>localhost
>
>--Audiodelight (name of my rootfolder)
>
>----css (with in that map my css files)
In the second case I get
>localhost
>
>--Audiodelight/detail (Which seems to be the problem)
>
>----css (with in that map my css files)
Does anyone have an idea why it's searching in a subdirectory? The directory it's looking for doesn't even exist.. Or know how to fix it?

Check your routing syntax http://fatfreeframework.com/base#Routing
Are you getting any PHP errors from this?

Related

Template not found error - Fat Free Framework

I have worked through the examples in the documentation for the Fat Free Framework, and there is one example that I cannot get to work. It is the following:
$f3=require('lib/base.php');
$f3->route('GET /',
function($f3) {
$f3->set('name','world');
$template=new Template;
echo $template->render('template.htm');
// Above lines can be written as:
// echo Template::instance()->render('template.htm');
}
);
$f3->run();
I receive an error that the Template is not found. The error points to the line in which the template.htm file is being rendered and complains of Preview->render (i.e. its superclass, instead of Template->render). I don't even see a file for a Preview class in the codebase.
Interestingly, if I use the same file for the View example (below), it works just fine.
$f3=require('lib/base.php');
$f3->route('GET /',
function($f3) {
$f3->set('name','world');
$view=new View;
echo $view->render('template.htm');
// Previous two lines can be shortened to:
// echo View::instance()->render('template.htm');
}
);
$f3->run();
However, if I am going to use this framework, I would like to be able to utilize its templating feature as well.
Does anyone with experience with this framework have any idea what could be the problem? I downloaded the code from Github (https://github.com/bcosca/fatfree).
By default F3 uses the same folder where is located your main file (where you start the framework instance). You can change this behavior by setting a new path for the UI parameter. In short:
$f3 = \Base::instance();
$f3->set('UI', path_to_your_templates);
let's say you have the following structure:
- app
-- views
--- template.htm (your template)
- public
-- index.php (where your init the framework)
-- (template files are expected here by default)
public/index.php looks like:
$f3 = \Base::instance();
$f3->set('UI', __DIR__.'/../app/views/');
$f3->route('GET /',
function($f3) {
echo Template::instance()->render('template.htm');
}
Hope it helps.
Use .html instead of .htm. Yep, it really matters.
I have no experience using fat free framework, but a general pointer on how to debug this issue.
Apparently the file not found exception is being thrown by some code inside fat free framework. Try debugging that using XDebug
I ran across this issue with version Fat Free Framework 3.5.1
The issue appears since the framework OOB (in at least this version) is wired with a sample such that the templates are looked for in the 'ui/' subfolder of the root fat free framework folder.
What tells me that? Well... the OOB config.ini has the following contents:
[globals]
DEBUG=3
UI=ui/
To easily solve the problem either:
Put the file 'template.htm' in the 'ui/' subfolder
OR
Rename the 'ui/' subfolder to whatever you like in the config.ini and put the 'template.htm' file in that location
TIP: Make sure whatever UI path you specify ends in a / and if you need to specify multiple paths you can use the | or , or ; separators (making sure each path ends in a /)

Include PHP file into TemplaVoilà template through TypoScript

I need to include a PHP file (containing some database-checks 'n' stuff) into a very bad programmed TYPO3 website. They used TemplaVoilà for templating purposes. This is the definition in the master TypoScript template:
[...]
page = PAGE
page {
[...]
10 = USER
10.userFunc = tx_templavoila_pi1->main_page
[...]
}
[...]
Within the used TemplaVoilà template they mapped the main content div (where I'd like to insert my PHP script) with the attribute „field_content“. Don't know if this helps to answer my question.
I tried nearly everything I know to somehow overwrite/fill the „Main Content Area“ through TypoScript, as it is completly empty () on the page I created for my PHP file.
Is it possible to fill a specific mapped tag with my PHP file through TypoScript?
(TYPO3 Version 4.5.32)
I figured out a solution for my problem: With the hint in the answer by Urs (using _INT) I altered an already included DS object to be extended through additional sub-objects (as the markup allows my code to be placed there with some modifications to the stylesheet):
lib.social.20 = PHP_SCRIPT_INT
lib.social.20.file = fileadmin/path_to_my_file
Now it works like a charm althrough it's a bit hacky...
What about
lib.myscript= USER
lib.myscript {
userFunc =user_myScript->main
}
and in the DS
<TypoScript><![CDATA[
10 < lib.myscript
]]></TypoScript>
I'm no TemplaVoilà expert, I just pulled the second snippet from http://typo3-beispiel.net/index.php?id=10
PS: if its's USER, it will be cached, if it's USER_INT, it will prevent static file caching. So you may be better off running those checks in the background via AJAX?

Typo3 getTypoLink_URL creates wrong link after language change

I hope I can manage to explain this problem...
I have an T3-extension that handles shared content.
In this shared content, we have links (page-ids) that are defined and converted into something like /en/clients/contact, using
$cObj = t3lib_div::makeInstance('tslib_cObj');
$href = $cObj->getTypoLink_URL($linkValue); // $linkValue is an integer (e.g. 153)
This works fine - until I change the language on the page. Then, the last used URL kinda «sticks» and the language indicator isn't present in the URL anymore.
Means:
call the german page -> works
change to english -> works
change back to german -> the english link is presented.
So the above link turns out like clients/contact (the leading slash is gone as well).
Oddly enough, I have a local installation of the same page where the problem doesn't occur. It's just on the page that's online.
I tried to find differences in the configuration, but there aren't any.
The only difference I could find so far is, that I use Typo3 v4.5.35 for the local installation and v4.7.17 for the online installation.
Any ideas???
This was very odd... but, I found a solution.
Instead of using $cObj->getTypoLink_URL($linkValue); I'm using this:
$configurations['additionalParams'] = "&L=".(int)t3lib_div::_GP('L');
$configurations['returnLast'] = 'url'; // get it as URL
$configurations['parameter'] = $linkValue;
$href = $cObject->typolink(NULL, $configurations);
It seems that when I created the $cObj, the L-Parameter got lost somewhere, somewhen. By adding it manually, the Link works as expected.

How can I split a HAML template into different partials/includes in PHP?

I am a PHP dev trying to start using HAML, using this implementation:
http://phphaml.sourceforge.net/
HAML looks awesome, but I don't understand if/how it supports partials (or includes, as they are called in the PHP world).
I would like to have a master template HAML file that then goes and loads up a bunch of partials for all the little pieces. (Then I can reuse those pieces in other templates too.)
In PHP or Ruby this would be really easy, is there any way to do this with HAML? thanks!
dylan
You could create a global render_haml_partial method by analogy with phpHaml's existing display_haml method that might look something like:
function render_haml_partial($sFilename, $aVariables = array(), $sTmp = true, $bGPSSC = false)
{
$sPath = realpath($sFilename);
$haml = new HamlParser(dirname($sPath), $sTmp);
$haml->append($GLOBALS);
if ($bGPSSC)
{
$haml->append($_GET);
$haml->append($_POST);
$haml->append($_SESSION);
$haml->append($_SERVER);
$haml->append($_COOKIE);
}
$haml->append($aVariables);
return $haml->fetch($sFilename);
}
This method could be placed in phpHaml's HamlParser.class.php file so it is available to all your templates.
The only difference between this and display_haml is that it invokes fetch instead of display at the end and returns the result so you can then insert it in-place into the invoking template.
You would then use it in your PHP/HAML templates as follows:
= render_haml_template("path to partial")
This would then be very similar to the Rails/HAML syntax:
= render :partial => 'path to partial'
Note that using display_haml directly does not have quite the same effect since it renders the template directly to the output instead of returning the result to the caller. Thus you could do the following:
- display_haml("path to partial")
But this doesn't capture the result of the render.
I'm guessing that somebody who cares enough about phpHaml might add such a render_haml_partial or something similar eventually - I might suggest it to the author some time.
Quite an old question, but I've updated the source code of phpHaml to reflect this new functionality!
Check out the commit #github
https://github.com/endorama/phphaml/commit/8d95d5ebff06275db8b14438e566c6e41ec91b7f

Problem with prototype framework in cake php

This question is somewhat related to my previous question (not necessary to go through it)
link text
, although this one is more of an Ajax problem.
I tested my page in firebug and I am getting the following error
Event.Observe is not a function
Event.observe('form908983160', 'submit', function(event) { new Ajax.Updater('comments','/blog/posts/comments/add', {asynchronous:true, evalScripts:true, parameters:Form.serialize('form908983160'), requestHeaders:['X-Update', 'comments']}) }, false);
I am using the prototype framework for developing my cake php application.
How should I fix this problem?
Guys, I really need your help in this one. I am really stuck at this one. [:(]
prototype.js has to be :
loaded in the page (verify it's not in 404, for instance)
loaded in the page before the execution of your script
Which generally means you need to include prototype.js first, and, only after that, you can include your scripts.
As a sidenote : you are not using any other JS Framework in that page, of course...
Remember that any Event.observers need to be used in global
Event.observe(window,'loaded',f);
// or
Event.observe(document,'dom:loaded',f)
otherwise they will not work.
For me it looks like there's problem with linking to Prototype. Open firebug and try to see the contents of your script files - if you see html, that means something went terribly wrong :-)

Categories