[TYPO3-mvc] extbase_pager usage.
Nils Blattner
nb at cabag.ch
Fri Aug 6 10:05:43 CEST 2010
Hi all
Sorry for beeing a bit inactive on the newsgroup lately, had a rather
busy last few weeks.
I will soon update the pager extension with some bugfixes/documentation.
Anyway, step by step usage is as follows:
In the repository you need the following:
/**
* Finds the questions with a category
*
* @var Tx_CabagQuestions_Domain_Model_Category $category The category
to search for.
* @var int $page The active page.
* @var int $itemsPerPage The items per page.
* @var int $pageCount The pagecount, will be set by the function.
* @return array The result array.
*/
public function findByCategory($category, &$page = 1, $itemsPerPage =
10, &$pageCount = 1) {
if($category === null) {
return array();
}
$query = $this->createQuery();
$query->matching(
$query->equals('category', $category)
)
->setOrderings(
array(
'date' => Tx_Extbase_Persistence_QueryInterface::ORDER_DESCENDING
)
);
$pageCount = Tx_ExtbasePager_Utility_Pager::prepareQuery($query,
$page, $itemsPerPage);
return $query->execute();
}
Attention: The &'s before $page and $pageCount are important as they
allow the function to overrule those variables from within. The function
prepareQuery() must be run after any matching etc but before execute().
It will do a limit (based on the $itemsPerPage) so do NOT limit the
query yourself.
In the Controller:
public function questionsAction(Tx_CabagQuestions_Domain_Model_Category
$activeCategory = null, $page = 1) {
/* ... */
$pageCount = 0;
$this->questions =
$this->questionsRepository->findByCategory($this->activeCategory, $page,
10, $pageCount);
/* ... */
$this->view->assign('questions', $this->questions);
$this->view->assign('page', $page);
$this->view->assign('pageCount', $pageCount);
}
-> The returned Objects are already limited to 10 in this case.
Typoscript:
lib.extbasepager {
order = current,previous,items,next,jumpto
active {
}
item {
separator = <li class="separator">|</li>
}
more {
doNotDisplay = 1
}
first {
doNotDisplay = 1
}
last {
doNotDisplay = 1
}
previous {
}
next {
}
jumpto {
}
current {
value = {field:title} <span
class="actPage">{field:activePage}</span> | {field:lastPage}
value.insertData = 1
}
}
And finally in fluid:
{namespace pager=Tx_ExtbasePager_ViewHelpers}
......
<pager:pager typoscript="lib.extbasepager" page="{page}"
lastPage="{pageCount}" />
Attention: typoscript="{someArray}" does not work at this point. However
I already have a bugfix for it and will put that on forge when I get
some time.
I hope this helped you.
As I wrote earlier, once I get some more spare time for it, I will
certainly update the documentation.
Regards, Nils
Am 05.08.10 07:33, schrieb Jonas Dübi:
> Hi
>
> sorry, that we didn't find the time to answer you.
>
> Please add questions and issues to
> http://forge.typo3.org/projects/extension-extbase_pager/issues
>
> That's very important for the project!
>
> I'll ask Nils if he finds the time to help you.
>
> Best regards,
> Jonas
>
> Bastian Waidelich schrieb:
>> Braulio J. Solano-Rojas wrote:
>>
>> Hi Braulio,
>>
>>>>> I have installed extbase_pager extension and I have added this in my
>>>>> layout:
>>>>>
>>>>> {namespace m=Tx_ExtbasePager_ViewHelpers}
>>
>> You will have to add this namespace declaration in every template file
>> that uses the namespace. That might seem cumbersome, but it has some
>> important advantages:
>> - the template/partial is more explicit and easier to comprehend
>> - the template/partial is re-usable
>> - auto completion will (once) work even for custom ViewHelpers
>>
>> Only the "f" namespace is pre-defined and can't be overridden.
>>
>>
>>> IMHO, I think I rushed into using extbase. IHMO too, extbase is not
>>> feature complete despite the version is greater than 1.0.0.
>>
>> The version number doesn't say anything about feature completeness
>> (Windows 3.1 wasn't feature complete and I'm sure it still isn't with
>> version 7 ;)
>>
>>
>>> I've been having troubles with simple things...
>>
>> That's a pity.. But I'm sure, thats mostly the case when you start
>> working with a new framework. We're trying to lower the barriers and
>> we know, that we're not there yet. That's why it's so important to get
>> feedback and constructive criticism from the community.
>>
>>
>>> [...] as a MVC framework it does not follow the convention over
>>> configuration
>>> philosophy
>>
>> Could you give an example where exactly you're missing this?
>> If you're talking about the fact, that you have to configure the
>> extension in so many different ways and places (Annotations, TCA,
>> TypoScript) I agree with you.. The reason for this is, that we had to
>> embed this framework in the world of TYPO3 without breaking the
>> existing conventions too much.
>>
>>
>>> (too much code bureaucracy for my taste).
>>
>> An example would be great.
>> If you're thinking about the need to properly annotate your methods
>> and properties - I think, this is rather a feature of Extbase & Fluid.
>>
>>
>>> If I get the pager to work I'll send an email.
>>
>> I didn't test the pager and I don't want to judge it at all. But be
>> aware, that this is a community extension thus it might not be in sync
>> with the current Extbase / Fluid versions.
>> BTW: We're working on a nice approach for these "extended ViewHelpers"
>> aka Widgets (see http://forge.typo3.org/issues/8773)
>>
>> Best,
>> Bastian
More information about the TYPO3-project-typo3v4mvc
mailing list