2
I have a table as shown below, I need it to update every 1s, but I have no idea how to do.
I used an html 5 tag, but it updates everything, I just want to update only the table. My View
<?php
$datenull = '01/01/0001 00:01';
$linha = 1;
?>
<meta HTTP-EQUIV="refresh" content="2">
<h1>Lista de Chamados em Abertos</h1>
<br/>
<div class="myTable table-responsive">
<table class="table table-hover">
<tr>
<th></th>
<th class="text-center">N. Chamado</th>
<th class="text-center">Computador</th>
<th class="text-center">Sala de Aula</th>
<th class="text-center">Criado em</th>
</tr>
<?php foreach ($this->data as $entity) :?>
<tr onclick="location.href ='<?php echo $this->url('Caos-admin-interna',
array(
'controller' => 'calls',
'action' => 'examined',
'id' => $entity->getId()
)
);?>';" style="cursor: pointer">
<td class="text-center"><strong><?php echo $linha;?></strong></td>
<td class="text-center"><?php echo $entity->getId();?></td>
<td class="text-center"><?php echo $entity->getComputer();?></td>
<td class="text-center"><?php echo $entity->getClassroom();?></td>
<td class="text-center"><?php echo $entity->getCreated();?></td>
</tr>
<?php
$linha = $linha + 1;
endforeach; ?>
</table>
</div>
<?php
namespace CaosAdmin\Controller;
use Zend\View\Model\ViewModel,
Zend\Authentication\Storage\Session as SessionStorage,
Zend\Authentication\AuthenticationService;
use Zend\Paginator\Paginator,
Zend\Paginator\Adapter\ArrayAdapter;
class CallsController extends CRUDController
{
private $user;
private $numberPerPage;
public function __construct()
{
$this->entity = 'Caos\Entity\Call';
$this->form = 'CaosAdmin\Form\Call';
$this->service = 'Caos\Service\Call';
$this->controller = 'calls';
$this->route = 'Caos-admin';
$auth = new AuthenticationService();
$sessionStorage = new SessionStorage('CaosAdmin');
$auth->setStorage($sessionStorage);
$this->user = $sessionStorage->read();
$this->numberPerPage = 20;
}
/**
* @return ViewModel
*/
public function indexAction()
{
$list = $this->getEm()->getRepository($this->entity)->findCallBySchool($this->user->getId());
$viewModel = new ViewModel(array('data' => $list));
return $viewModel;
}
}
The return of my research comes in this format:
Array(
[0] => Caos\Entity\Call Object
(
[id:protected] => 27
[examined:protected] => DateTime Object
(
[date] => 0001-01-01 00:00:00
[timezone_type] => 3
[timezone] => America/Sao_Paulo
)
[closed:protected] => DateTime Object
(
[date] => 0001-01-01 00:00:00
[timezone_type] => 3
[timezone] => America/Sao_Paulo
)
[modified:protected] => DateTime Object
(
[date] => 2017-01-20 16:21:39
[timezone_type] => 3
[timezone] => America/Sao_Paulo
)
[created:protected] => DateTime Object
(
[date] => 2017-01-20 16:21:39
[timezone_type] => 3
[timezone] => America/Sao_Paulo
)
[obs:protected] =>
[computer:protected] => DoctrineORMModule\Proxy\__CG__\Caos\Entity\Computer Object
(
[__initializer__] => Closure Object
(
[static] => Array
(
[entityPersister] => Doctrine\ORM\Persisters\Entity\BasicEntityPersister Object
(
[class:protected] => Doctrine\ORM\Mapping\ClassMetadata Object
(
[name] => Caos\Entity\Computer
[namespace] => Caos\Entity
[rootEntityName] => Caos\Entity\Computer
[customGeneratorDefinition] =>
[customRepositoryClassName] => Caos\Entity\ComputerRepository
[isMappedSuperclass] =>
[isEmbeddedClass] =>
[parentClasses] => Array
(
)
[subClasses] => Array
(
)
[embeddedClasses] => Array
(
)
[namedQueries] => Array
(
)
[namedNativeQueries] => Array
(
)
[sqlResultSetMappings] => Array
(
)
leo_ap the return of my research comes in this format:
Array(
[0] => Caos\Entity\Call Object
(
[id:protected] => 27
[examined:protected] => DateTime Object
(
[date] => 0001-01-01 00:00:00
[timezone_type] => 3
[timezone] => America/Sao_Paulo
)
[closed:protected] => DateTime Object
(
[date] => 0001-01-01 00:00:00
[timezone_type] => 3
[timezone] => America/Sao_Paulo
)
[modified:protected] => DateTime Object
(
[date] => 2017-01-20 16:21:39
[timezone_type] => 3
[timezone] => America/Sao_Paulo
)
[created:protected] => DateTime Object
(
[date] => 2017-01-20 16:21:39
[timezone_type] => 3
[timezone] => America/Sao_Paulo
)
[obs:protected] =>
[computer:protected] => DoctrineORMModule\Proxy\__CG__\Caos\Entity\Computer Object
(
[__initializer__] => Closure Object
(
[static] => Array
(
[entityPersister] => Doctrine\ORM\Persisters\Entity\BasicEntityPersister Object
(
[class:protected] => Doctrine\ORM\Mapping\ClassMetadata Object
(
[name] => Caos\Entity\Computer
[namespace] => Caos\Entity
[rootEntityName] => Caos\Entity\Computer
[customGeneratorDefinition] =>
[customRepositoryClassName] => Caos\Entity\ComputerRepository
[isMappedSuperclass] =>
[isEmbeddedClass] =>
[parentClasses] => Array
(
)
[subClasses] => Array
(
)
[embeddedClasses] => Array
(
)
[namedQueries] => Array
(
)
[namedNativeQueries] => Array
(
)
[sqlResultSetMappings] => Array
(
)
In my View I put this code to print the data:
$entity->getId()
In javascript how do I do? i have a method in my entity that transforms an array, how do I use.
Thank you
Why not make the action return a populated view and then only write the HTML of this view in the return of ajax ? thus removing the foreach of jquery $('#tbl-called tbody'). html("") facilitating maintenance. taking out the part that
– Marco Vinicius Soares Dalalba
@Marcoviniciussoaresdalalba I prefer to return only data with ajax, to treat them in the view itself. This favors interoperability and flexibility. I do not see how your suggestion can facilitate maintenance, since if it is not the
foreach
of jquery, creating thetr
, would be theforeach
php. In my opinion, building html elements with javascript is more appropriate than with php. In this way, it can be said that maintenance is well ensured by my approach.– leoap