Hello Everyone,
I am new to Laminas, I am following tutorial , at the moment I am at navigation menu part.
Yesterday I was unable to set Bootstrap-class to list-item, with partial-vew-script i am able to set class to li but the next problem is it not setting the class to anchor tag a.
I got an idea it should set with additional parameter thing,
could anyone help me to set class to tag a.
Thank You
Hello and welcome to our forums!
Unfortunately, we can not see anything from your code, so we can only guess what you were trying to do.
I think you mean this:
echo $this->navigation()->menu()->htmlify($page);
But you can create custom HTML in a partial script, also for the anchor element:
<li class="nav-item">
<a href="<?= $page->getHref() ?>"
class="nav-link<?= $page->isActive(): ' active' : '' ?>">
<?= $this->escapeHtml($page->getLabel()) ?>
</a>
</li>
Thank You for Your response exactly I was looking for it. this worked like a charm.
Thank You
You can activate the IDE auto-completion in your partial script:
<?php
/**
* @var Laminas\View\Renderer\PhpRenderer $this
* @var Laminas\Navigation\Navigation $container
*/
/** @var Laminas\Navigation\Page\Mvc $page */
foreach ($container as $page) {
// …
}
?>
And if you want to use a sub-menu then $page->isActive(true)
for a recursive check is helpful.
That’s really nice of You.
Thank You.
I have one more Question. I have seen IDE auto-completion is working really good with your scriipt for Navigation.
I would like to know do I need to Activate IDE auto-completion for each component. if Yes then how could I know where this autocompletion can be found , for examp if I am using Pagination I couldn’t find Auto-Completion for that I have to remember or copy every
for example if i need to call these two Funtion in controller
I was not getting Auto-completion
SetCurrentPageNumber($page)
SetItemCountPerPage($page)
Thank you
You have to separate templates from the rest of the code. In templates there is no relation to any class or everything else therefore the DocBlock is needed here.
Example for a template:
<?php
/**
* @var Laminas\View\Renderer\PhpRenderer $this
* @var Laminas\Paginator\Paginator $paginator
*/
In a controller there you have a relation:
use Laminas\Mvc\Controller\AbstractActionController;
use Laminas\Paginator\Paginator;
class IndexController extends AbstractActionController
{
public function indexAction()
{
$paginator = new Paginator($adapter);
$paginator->setCurrentPageNumber($pageNumber); // auto-completion works here
return [
'paginator' => $paginator,
];
}
}
Or a more real world example:
namespace Album\Repository;
use Laminas\Paginator\Paginator;
interface AlbumRepositoryInterface
{
public function fetchPaginated(): Paginator;
}
namespace Album\Controller;
use Album\Repository;
use Laminas\Mvc\Controller\AbstractActionController;
use Laminas\Paginator\Paginator;
class IndexController extends AbstractActionController
{
private AlbumRepositoryInterface $repository;
public function __construct(AlbumRepositoryInterface $repository)
{
$this->repository = $repository;
}
public function indexAction(): array
{
$paginator = $this->repository->fetchPaginated();
$paginator->setCurrentPageNumber($pageNumber); // auto-completion works here
return [
'paginator' => $paginator,
];
}
}
Hey,
thank You for your really helping response,
Furthur I would like to ask you about Autocompletion may be with this example i would get better idea.
I am following the Blog-Module tutorial.
here is my Controller. ( WriteController )
<?php
namespace Blog\Controller;
use Blog\Form\PostForm;
use Blog\Model\PostCommandInterface;
use Laminas\Mvc\Controller\AbstractActionController;
use Laminas\View\Model\ViewModel;
class WriteController extends AbstractActionController{
/**
* @var PostCommandInterface
*/
private $command;
/**
* @var PostForm
*/
private $form;
public function __construct(PostCommandInterface $command, PostForm $form)
{
$this->command = $command;
$this->form = $form;
}
public function AddAction(){
return new ViewModel([
'form' => $this->form,
]);
}
}
in the view as it is written.
<!-- Filename: module/Blog/view/blog/write/add.phtml -->
<h1>Add a blog post</h1>
<?php
$form = $this->form;
$form->setAttribute('action', $this->url());
$form->prepare();
echo $this->form()->openTag($form);
echo $this->formCollection($form);
echo $this->form()->closeTag();
this is how we create form in view.
But I could not get aut completion for this form. that was my question how could i inialize for autcomplete as controller is not connected to View.
for example $form->
here autcomplete should come.
Please follow the introduction in the documentation:
https://docs.laminas.dev/laminas-form/helper/intro/
The controller does not matter here. The view script is isolated therefore the DocBlocks are needed.
Btw. this post was marked as solved therefore please open a new post, especially if the question is not on topic. Thanks!