-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Los bloques contienen la parte lógica que se emplea en las plantillas Haremos uso de la vista previamente creada en el modulo de Pfay_Contacts Mas información --> 45789fd 1.- Creamos nuestro bloque: app/code/Pfay/Contacts/Block/Contactslist.php 2.- Enlazamos nuestro bloque con nuestro template, para eso modificamos nuestro LAYOUT 3.- Modificamos nuestro template para hacer uso de los métodos de nuestro bloque. 4.- recompilamos y asignamos permisos php bin/magento setup:upgrade php bin/magento setup:di:compile chmod -R 777 var/ pub/ 5.- verificamos resultados en el navegador WEB: http://magento240.local/contacts/test/index
- Loading branch information
1 parent
45789fd
commit c221740
Showing
3 changed files
with
68 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
<?php | ||
namespace Pfay\Contacts\Block; | ||
use Magento\Framework\View\Element\Template; | ||
|
||
class Contactslist extends \Magento\Framework\View\Element\Template | ||
{ | ||
public function __construct(Template\Context $context, array $data = array()) | ||
{ | ||
parent::__construct($context, $data); | ||
$this->setData('contacts',array()); | ||
} | ||
|
||
public function addContacts($count) | ||
{ | ||
$_contacts = $this->getData('contacts'); | ||
$actualNumber = count($_contacts); | ||
$names = array(); | ||
for($i=$actualNumber;$i<($actualNumber+$count);$i++) { | ||
$_contacts[] = 'nom '.($i+1); | ||
} | ||
$this->setData('contacts',$_contacts); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
45 changes: 44 additions & 1 deletion
45
code/Pfay/Contacts/view/frontend/templates/test_index.phtml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,46 @@ | ||
<div id="contactslist"> | ||
my contact list | ||
<h2>empty</h2> | ||
<table> | ||
<tr> | ||
<th>Name</th> | ||
</tr> | ||
<?php $contacts = $this->getData('contacts'); ?> | ||
<?php foreach ($contacts as $contact): ?> | ||
<tr> | ||
<td><?php echo $contact ?></td> | ||
</tr> | ||
<?php endforeach; ?> | ||
<tr> | ||
<td>there is no contact in this list</td> | ||
</tr> | ||
</table> | ||
|
||
|
||
<h2>10 éléments</h2> | ||
<table> | ||
<tr> | ||
<th>Name</th> | ||
</tr> | ||
<?php $this->addContacts(10); ?> | ||
<?php $contacts = $this->getData('contacts'); ?> | ||
<?php foreach ($contacts as $contact): ?> | ||
<tr> | ||
<td><?php echo $contact ?></td> | ||
</tr> | ||
<?php endforeach; ?> | ||
</table> | ||
|
||
<h2>20 éléments</h2> | ||
<table> | ||
<tr> | ||
<th>Name</th> | ||
</tr> | ||
<?php $this->addContacts(10); ?> | ||
<?php $contacts = $this->getData('contacts'); ?> | ||
<?php foreach ($contacts as $contact): ?> | ||
<tr> | ||
<td><?php echo $contact ?></td> | ||
</tr> | ||
<?php endforeach; ?> | ||
</table> | ||
</div> |