Re: [PHPTAL] PHPTAL 1.2.0 alpha

2009-04-29 Thread Tjerk Meesters
Guess the __DIR__ constant came a bit too late then ;-)

On 4/29/09, Kornel Lesiński  wrote:
> On 29-04-2009 at 00:53:41 romtek  wrote:
>
>>> OK, I've given up on require() and changed it all to require_once().
>>
>> Is there ever a reason to use require() to include code (not text)?
>
> I hoped it would be faster than require_once, but it turned out that with
> relative paths the difference is insignificant.
>
> --
> regards, Kornel
>
>
>
> ___
> PHPTAL mailing list
> PHPTAL@lists.motion-twin.com
> http://lists.motion-twin.com/mailman/listinfo/phptal
>


-- 
--
Tjerk

___
PHPTAL mailing list
PHPTAL@lists.motion-twin.com
http://lists.motion-twin.com/mailman/listinfo/phptal


Re: [PHPTAL] Selected attribute in select list

2009-04-29 Thread Matt Marron
That's how I got it to work, but without the Tales-Keyword. I just added a 
IF statement to my SQL
statement that retrieved the categories. Kind of hackish, if you ask me, but 
it works! Thanks for all your replies!


- Original Message - 

Date: Tue, 28 Apr 2009 12:45:43 +0200
From: Julian Haupt 
Subject: Re: [PHPTAL] Selected attribute in select list
To: phptal@lists.motion-twin.com
Message-ID: <1240915543.9147.27.ca...@superwash-2000>
Content-Type: text/plain

Hi,


The way you USA should work, but try this:


 



In general it might be a bad idea to use php code and explicit
comparisons in the templates. This is a bad practice which entangles the
view with the underlying business logic.

I've added a new TALES-Keyword for this purpose: condition

It works like mysql's IF statement. If the expression in the first block
is true, execute the next block, otherwise the last block.

function phptal_tales_condition($expression, $nothrow) {
   // split OR expressions
   $exps = preg_split('/\s*\|\s*/sm', $expression);

   if (!isset($exps[1])) {
   $exps[1] = 'nothing';
   }

   if (!isset($exps[2])) {
   $exps[2] = 'nothing';
   }

   return '(' . phptal_tales($exps[0], $nothrow) . ') ? ' .
phptal_tales($exps[1], $nothrow) . ' : '. phptal_tales($exps[2],
$nothrow);
}


It might not be perfect, because it uses TALES' "|" operator for a
completely different operation.

Please note: as you cannot do explicit comparisons with this keyword,
you must define the result of the comparison in your model.

With the help of the condition keyword you can write the above template
like this:


   


The "active" property might be determined like this:

$id = (int)$_REQUEST["id"]; // get the id in the url query

$formSQL = "SELECT i.id, categoryid, category, title, publication,
DATE_FORMAT(date, '%Y/%m/%d') AS fDate, author, summary, filename,
IF(i.id=$id,1,NULL) AS active FROM `resources-items` AS i LEFT JOIN
`resources-categories` AS c ON i.categoryid=c.id WHERE i.id=$id"; // get
the row to be edited

$t = new PHPTAL("test.html");
$t->categories = getRows("SELECT id, category FROM
`resources-categories` ORDER BY category"); // get all categories
$t->form = getRows($formSQL);


Greetings,

Julian Haupt 




___
PHPTAL mailing list
PHPTAL@lists.motion-twin.com
http://lists.motion-twin.com/mailman/listinfo/phptal


Re: [PHPTAL] PHPTAL 1.2.0 alpha

2009-04-29 Thread Kornel Lesiński

On 29-04-2009 at 00:53:41 romtek  wrote:


OK, I've given up on require() and changed it all to require_once().


Is there ever a reason to use require() to include code (not text)?


I hoped it would be faster than require_once, but it turned out that with 
relative paths the difference is insignificant.

--
regards, Kornel



___
PHPTAL mailing list
PHPTAL@lists.motion-twin.com
http://lists.motion-twin.com/mailman/listinfo/phptal