PHP interesse |
|
ok, ik het mapjes AJAX > controller stond de volgende code:
public function __construct($application = null, $view = null)
{
parent::__construct($application, $view);
switch ($this->getRequest()->getParam('data-trigger'))
{
case "buttons":
$this->getButtons();
break;
public function __construct($application = null, $view = null) { parent::__construct($application, $view); switch ($this->getRequest()->getParam('data-trigger')) { case "buttons": $this->getButtons(); break;
De functie getButtons
private function getButtons()
{
$view = new Zend_View();
$view->setBasePath(COMPLETE_PLATFORM_PATH . '/Ajax');
$view->setScriptPath(COMPLETE_PLATFORM_PATH . '/Ajax/Views');
$this->setView($view);
if ('category' === $this->getRequest()->getParam('type'))
{
$buttons = $this->getDb()
->select()
->from('products')
->where('product_category_id = ?', $this->getRequest()->getParam('id'))
->query(Complete_Platform::FETCH_TYPE)
->fetchAll();
foreach ($buttons as $key => $button)
{
$button->data_type = 'product';
$button->data_id = $button->product_id;
$button->button_name = $button->product_name;
$buttons[$key] = $button;
}
$this->getView()->assign('type', 'products');
$this->getView()->assign('buttons', $buttons);
die($this->getView()->render('Buttons.phtml'));
}
if ('product' === $this->getRequest()->getParam('type'))
{
$product = $this->getDb()
->select()
->from('products')
->where('product_id = ?', $this->getRequest()->getParam('id'))
->query(Complete_Platform::FETCH_TYPE)
->fetch();
foreach ($product as $key => $value)
{
$this->getView()->assign($key, $value);
}
die($this->getView()->render('TicketRow.phtml'));
}
}
private function getButtons() { $view = new Zend_View(); $view->setBasePath(COMPLETE_PLATFORM_PATH . '/Ajax'); $view->setScriptPath(COMPLETE_PLATFORM_PATH . '/Ajax/Views'); $this->setView($view); if ('category' === $this->getRequest()->getParam('type')) { $buttons = $this->getDb() ->select() ->from('products') ->where('product_category_id = ?', $this->getRequest()->getParam('id')) ->query(Complete_Platform::FETCH_TYPE) ->fetchAll(); foreach ($buttons as $key => $button) { $button->data_type = 'product'; $button->data_id = $button->product_id; $button->button_name = $button->product_name; $buttons[$key] = $button; } $this->getView()->assign('type', 'products'); $this->getView()->assign('buttons', $buttons); die($this->getView()->render('Buttons.phtml')); } if ('product' === $this->getRequest()->getParam('type')) { $product = $this->getDb() ->select() ->from('products') ->where('product_id = ?', $this->getRequest()->getParam('id')) ->query(Complete_Platform::FETCH_TYPE) ->fetch(); foreach ($product as $key => $value) { $this->getView()->assign($key, $value); } die($this->getView()->render('TicketRow.phtml')); } }
buttons.phtml
<input type="hidden" id="data-type" value="<?php echo $this->type; ?>" />
<?php foreach ($this->buttons as $key => $button) { ?>
<div class="button <?php echo $button->data_type; ?>" data-type="<?php echo $button->data_type; ?>" data-id="<?php echo $button->data_id; ?>">
<?php echo $button->button_name; ?>
<?php if ('product' == $button->data_type) { ?>
<span class="label number"><?php echo $button->data_id; ?></span>
<?php } ?>
</div>
<?php } ?>
<input type="hidden" id="data-type" value=" <?php echo $this->type; ?>" /> <?php foreach ($this->buttons as $key => $button) { ?> <div class="button <?php echo $button->data_type; ?>" data-type=" <?php echo $button->data_type; ?>" data-id=" <?php echo $button->data_id; ?>"> <?php echo $button->button_name; ?> <?php if ('product' == $button->data_type) { ?> <span class="label number"> <?php echo $button->data_id; ?></span> <?php } ?> </div> <?php } ?>
Ik weet niet of ik goed zit, op de index (waar het probleem zit - de button niet werkt) zie ik verder geen van deze functies aangeroepen worden, dus wellicht staat dit er geheel buiten.
|