serdelinho
13-04-2014, 23:53
Witam,
na początku witam wszystkich, jestem tu nowy :)
Mój problem jest następujący:
pisze w tym momencie komponent. Wydaje mi się, że wszystko jest ok, lecz gdy w panelu administratora (komponent ma działać tylko po tej stronie) gdy klikam przycisk, który odpowiada np. za edycje artykułu, wykonuje mi się task, czyli dodaje mi do adresu "view" i "layout" lecz w linku, który jest klikany jest podany także "id", który jest mi potrzebny po przejściu na stronę edycji. I tutaj pojawia się problem, gdyż nie dodaje mi tego atrybutu, co za tym idzie nie mogę pobrać wymaganych danych z bazy nie mając atrybutu ID. Prosiłbym o pomoc.
Niżej wrzucam cały kod źródłowy (nie jest kompletny, lecz na tym etapie to na czym mi zależy powinno działać)
Com_alleKolabo
com_alleKolabo/alleKolabo.php
<?php
defined('_JEXEC') or die;
jimport('joomla.application.component.controller') ;
$controller = JController::getInstance('alleKolabo');
$controller->execute(JRequest::getCmd('task'));
$controller->redirect();
com_alleKolabo/controller.php
<?phpdefined('_JEXEC') or die;
jimport('joomla.application.component.controller') ;
class alleKolaboController extends JController {
}
com_alleKolabo/controllers/product.php
<?phpdefined('_JEXEC') or die;
jimport('joomla.application.component.controllerfo rm');
class alleKolaboControllerProduct extends JControllerForm{
protected $view_list = 'products';
}
com_alleKolabo/controllers/products.php
<?phpdefined('_JEXEC') or die;
jimport('joomla.application.component.controllerad min');
class alleKolaboControllerProduct extends JControllerAdmin{
protected $text_prefix = 'COM_ALLEKOLABO_PRODUCT';
function getModel($name='Products', $prefix='alleKolaboModel', $config=array('ignore_request'=>TRUE)){
$model = parent::getModel($name, $prefix, $config);
return $model;
}
}
com_alleKolabo/models/product.php
<?phpdefined('_JEXEC') or die;
jimport('joomla.application.component.modeladmin') ;
class alleKolaboModelProduct extends JModelAdmin{
function getTable($type='Product', $prefix='alleKolaboTable', $config=array()){
return JTable::getInstance($type, $prefix, $config);
}
function getForm($data=array(), $loadData=TRUE){
$form = $this->loadForm();
return $form;
}
}
com_alleKolabo/models/products.php
<?phpdefined ('_JEXEC') or die;
jimport('joomla.application.component.modellist');
class alleKolaboModelProducts extends JModelList {
function __construct($config=array()){
if(empty($config['filter_fields'])){
$config['filter_fields'] = array(
'product_name',
'product_desc',
'product_in_stock',
'product_price'
);
}
parent::__construct($config);
}
function getItems(){
$items = parent::getItems();
foreach($items as &$item){
$item->url = 'index.php?option=com_allekolabo&task=product.edit &product_id='.$item->virtuemart_product_id;
}
return $items;
}
function getListQuery(){
$query = parent::getListQuery();
$query->select('a.virtuemart_product_id , product_in_stock , product_name , product_s_desc , product_desc , product_price');
$query->from('shop_virtuemart_products a
LEFT JOIN shop_virtuemart_products_pl_pl b ON a.virtuemart_product_id = b.virtuemart_product_id
LEFT JOIN shop_virtuemart_product_prices c ON a.virtuemart_product_id = c.virtuemart_product_id');
$dbo = $this->getDbo();
$search = $this->getState('filter.search');
if(!empty($search)){
$search = '%'.$dbo->escape($search, TRUE).'%';
$search_stmt = "(product_name LIKE '{$search}' OR product_desc LIKE '{$search}')";
$query->where($search_stmt);
}
$orderCol = $this->getState('list.ordering');
$orderDir = $this->getState('list.direction');
if($orderCol != ''){
$query->order($dbo->escape($orderCol.' '.$orderDir));
}
return $query;
}
protected function populateState($ordering=NULL, $direction=NULL){
$search = $this->getUserStateFromRequest($this->context.'filter.search', 'filter_search');
$this->setState('filter.search', $search);
parent::populateState($ordering, $direction);
}
}
com_alleKolabo/tables/product.php
<?phpdefined('_JEXEC') or die;
class alleKolaboTableProduct extends JTable{
public function __construct(&$dbo){
parent::__construct('#__virtuemart_products', 'virtuemart_product_id', $dbo);
}
}
com_alleKolabo/views/products/view.html.php
<?phpdefined ('_JEXEC') or die;
jimport('joomla.application.component.view');
class alleKolaboViewProducts extends JView {
protected $products;
protected $pagination;
protected $state;
function display($tmpl = NULL){
$this->products = $this->get('Items');
$this->pagination = $this->get('Pagination');
$this->state = $this->get('State');
$this->toolbar();
parent::display($tmpl);
}
function toolbar(){
JToolBarHelper::title(JText::_('COM_ALLEKOLABO_PRO DUCTS_HEADER'));
JToolBarHelper::custom( 'product.add', 'add_auction.png', 'icon-32-add_auction.png', 'COM_ALLEKOLABO_ADD_AUCTION', false, false );
}
}
com_alleKolabo/views/products/tmpl/default.php
<?php defined ('_JEXEC') or die;
$listOrder = $this->escape($this->state->get('list.ordering'));
$listDir = $this->escape($this->state->get('list.direction'));
?>
<form action="index.php?option=com_allekolabo&view=products" method="post" name="adminForm" id="adminForm">
<fieldset id="filter-bar">
<div class="filter-search fltlft">
<label for="filter-search"><?php echo JText::_('JSEARCH_FILTER_LABEL'); ?></label>
<input type="text" name="filter_search" id="filter_search" title="Wyszukaj" value="<?php echo $this->state->get('filter.search'); ?>" />
<button type="submit" class="btn"><?php echo JText::_('JSEARCH_FILTER_SUBMIT'); ?></button>
<button type="button" class="btn" onclick="document.id('filter_search').value=''; this.form.submit();"><?php echo JText::_('JSEARCH_FILTER_CLEAR'); ?></button>
</div>
</fieldset>
<table class="adminlist">
<thead>
<tr>
<th style="width: 1%">
<input type="checkbox" name="checkall-toggle" value="" onclick="checkAll(this)" />
</th>
<th>
<?php echo JHtml::_(
'grid.sort',
'COM_ALLEKOLABO_PRODUCTS_LIST_TITLE_LABEL',
'product_name',
$listDir,
$listOrder
); ?>
</th>
<th>
<?php echo JHtml::_(
'grid.sort',
'COM_ALLEKOLABO_PRODUCTS_LIST_DESC_LABEL',
'product_s_desc',
$listDir,
$listOrder
); ?>
</th>
<th>
<?php echo JHtml::_(
'grid.sort',
'COM_ALLEKOLABO_PRODUCTS_LIST_STOCK_LABEL',
'product_in_stock',
$listDir,
$listOrder
); ?>
</th>
<th>
<?php echo JHtml::_(
'grid.sort',
'COM_ALLEKOLABO_PRODUCTS_LIST_PRICE_LABEL',
'product_price',
$listDir,
$listOrder
); ?>
</th>
</tr>
</thead>
<tbody>
<?php foreach ($this->products as $i=>$product):?>
<tr class="row<?php echo $i%2; ?>">
<td class="center">
<?php echo JHtml::_('grid.id', $i, $product->virtuemart_product_id); ?>
</td>
<td class="center">
<a href="<?php echo $product->url; ?>"><?php echo $this->escape($product->product_name); ?></a>
</td>
<td class="center"><?php echo $this->escape($product->product_s_desc); ?></td>
<td class="center"><?php echo $this->escape($product->product_in_stock).' szt'; ?></td>
<td class="center"><?php echo round(($this->escape($product->product_price)),2).' zł'; ?></td>
</tr>
<?php endforeach;?>
</tbody>
<tfoot>
<tr>
<td colspan="3">
<?php echo $this->pagination->getListFooter(); ?>
</td>
</tr>
</tfoot>
</table>
<input type="hidden" name="filter_order" value="<?php echo $listOrder; ?>" />
<input type="hidden" name="filter_order_Dir" value="<?php echo $listDir; ?>" />
<input type="hidden" name="task" value="" />
<input type="hidden" name="boxchecked" value="0" />
<?php echo JHtml::_('form.token'); ?>
</form>
com_alleKolabo/views/product/view.html.php
<?phpdefined('_JEXEC') or die;
jimport('joomla.application.component.view');
class alleKolaboViewProduct extends JView {
protected $product;
function display($tmpl = NULL){
$this->product = $this->get('Item');
$this->toolbar();
parent::display($tmpl);
}
function toolbar(){
if($this->product->product_id){
JToolBarHelper::title_('COM_ALLEKOLABO_ADD_PRODUCT _TITLE');
}
JToolBarHelper::apply('product.apply', 'JTOOLBAR_APPLY');
JToolBarHelper::cancel('product.cancel');
}
}
com_alleKolabo/views/product/tmpl/edit.php
<?phpdefined('_JEXEC') or die; ?>
<form method="post" name="adminForm" class="form-validate" action="index.php?option=com_alleKolabo&product_id=<?php echo $this->product->virtuemart_product_id; ?>">
<input type="hidden" name="task" value="" />
<?php echo JHtml::_('form.token'); ?>
</form>
Dodaje także paczke ze wszystkimi plikami
7508
Liczę na waszą pomoc. Nic już mi do głowy nie przychodzi a to pewnie jakaś niewielka literówka.
Pozdrawiam i z góry dzięki!!
na początku witam wszystkich, jestem tu nowy :)
Mój problem jest następujący:
pisze w tym momencie komponent. Wydaje mi się, że wszystko jest ok, lecz gdy w panelu administratora (komponent ma działać tylko po tej stronie) gdy klikam przycisk, który odpowiada np. za edycje artykułu, wykonuje mi się task, czyli dodaje mi do adresu "view" i "layout" lecz w linku, który jest klikany jest podany także "id", który jest mi potrzebny po przejściu na stronę edycji. I tutaj pojawia się problem, gdyż nie dodaje mi tego atrybutu, co za tym idzie nie mogę pobrać wymaganych danych z bazy nie mając atrybutu ID. Prosiłbym o pomoc.
Niżej wrzucam cały kod źródłowy (nie jest kompletny, lecz na tym etapie to na czym mi zależy powinno działać)
Com_alleKolabo
com_alleKolabo/alleKolabo.php
<?php
defined('_JEXEC') or die;
jimport('joomla.application.component.controller') ;
$controller = JController::getInstance('alleKolabo');
$controller->execute(JRequest::getCmd('task'));
$controller->redirect();
com_alleKolabo/controller.php
<?phpdefined('_JEXEC') or die;
jimport('joomla.application.component.controller') ;
class alleKolaboController extends JController {
}
com_alleKolabo/controllers/product.php
<?phpdefined('_JEXEC') or die;
jimport('joomla.application.component.controllerfo rm');
class alleKolaboControllerProduct extends JControllerForm{
protected $view_list = 'products';
}
com_alleKolabo/controllers/products.php
<?phpdefined('_JEXEC') or die;
jimport('joomla.application.component.controllerad min');
class alleKolaboControllerProduct extends JControllerAdmin{
protected $text_prefix = 'COM_ALLEKOLABO_PRODUCT';
function getModel($name='Products', $prefix='alleKolaboModel', $config=array('ignore_request'=>TRUE)){
$model = parent::getModel($name, $prefix, $config);
return $model;
}
}
com_alleKolabo/models/product.php
<?phpdefined('_JEXEC') or die;
jimport('joomla.application.component.modeladmin') ;
class alleKolaboModelProduct extends JModelAdmin{
function getTable($type='Product', $prefix='alleKolaboTable', $config=array()){
return JTable::getInstance($type, $prefix, $config);
}
function getForm($data=array(), $loadData=TRUE){
$form = $this->loadForm();
return $form;
}
}
com_alleKolabo/models/products.php
<?phpdefined ('_JEXEC') or die;
jimport('joomla.application.component.modellist');
class alleKolaboModelProducts extends JModelList {
function __construct($config=array()){
if(empty($config['filter_fields'])){
$config['filter_fields'] = array(
'product_name',
'product_desc',
'product_in_stock',
'product_price'
);
}
parent::__construct($config);
}
function getItems(){
$items = parent::getItems();
foreach($items as &$item){
$item->url = 'index.php?option=com_allekolabo&task=product.edit &product_id='.$item->virtuemart_product_id;
}
return $items;
}
function getListQuery(){
$query = parent::getListQuery();
$query->select('a.virtuemart_product_id , product_in_stock , product_name , product_s_desc , product_desc , product_price');
$query->from('shop_virtuemart_products a
LEFT JOIN shop_virtuemart_products_pl_pl b ON a.virtuemart_product_id = b.virtuemart_product_id
LEFT JOIN shop_virtuemart_product_prices c ON a.virtuemart_product_id = c.virtuemart_product_id');
$dbo = $this->getDbo();
$search = $this->getState('filter.search');
if(!empty($search)){
$search = '%'.$dbo->escape($search, TRUE).'%';
$search_stmt = "(product_name LIKE '{$search}' OR product_desc LIKE '{$search}')";
$query->where($search_stmt);
}
$orderCol = $this->getState('list.ordering');
$orderDir = $this->getState('list.direction');
if($orderCol != ''){
$query->order($dbo->escape($orderCol.' '.$orderDir));
}
return $query;
}
protected function populateState($ordering=NULL, $direction=NULL){
$search = $this->getUserStateFromRequest($this->context.'filter.search', 'filter_search');
$this->setState('filter.search', $search);
parent::populateState($ordering, $direction);
}
}
com_alleKolabo/tables/product.php
<?phpdefined('_JEXEC') or die;
class alleKolaboTableProduct extends JTable{
public function __construct(&$dbo){
parent::__construct('#__virtuemart_products', 'virtuemart_product_id', $dbo);
}
}
com_alleKolabo/views/products/view.html.php
<?phpdefined ('_JEXEC') or die;
jimport('joomla.application.component.view');
class alleKolaboViewProducts extends JView {
protected $products;
protected $pagination;
protected $state;
function display($tmpl = NULL){
$this->products = $this->get('Items');
$this->pagination = $this->get('Pagination');
$this->state = $this->get('State');
$this->toolbar();
parent::display($tmpl);
}
function toolbar(){
JToolBarHelper::title(JText::_('COM_ALLEKOLABO_PRO DUCTS_HEADER'));
JToolBarHelper::custom( 'product.add', 'add_auction.png', 'icon-32-add_auction.png', 'COM_ALLEKOLABO_ADD_AUCTION', false, false );
}
}
com_alleKolabo/views/products/tmpl/default.php
<?php defined ('_JEXEC') or die;
$listOrder = $this->escape($this->state->get('list.ordering'));
$listDir = $this->escape($this->state->get('list.direction'));
?>
<form action="index.php?option=com_allekolabo&view=products" method="post" name="adminForm" id="adminForm">
<fieldset id="filter-bar">
<div class="filter-search fltlft">
<label for="filter-search"><?php echo JText::_('JSEARCH_FILTER_LABEL'); ?></label>
<input type="text" name="filter_search" id="filter_search" title="Wyszukaj" value="<?php echo $this->state->get('filter.search'); ?>" />
<button type="submit" class="btn"><?php echo JText::_('JSEARCH_FILTER_SUBMIT'); ?></button>
<button type="button" class="btn" onclick="document.id('filter_search').value=''; this.form.submit();"><?php echo JText::_('JSEARCH_FILTER_CLEAR'); ?></button>
</div>
</fieldset>
<table class="adminlist">
<thead>
<tr>
<th style="width: 1%">
<input type="checkbox" name="checkall-toggle" value="" onclick="checkAll(this)" />
</th>
<th>
<?php echo JHtml::_(
'grid.sort',
'COM_ALLEKOLABO_PRODUCTS_LIST_TITLE_LABEL',
'product_name',
$listDir,
$listOrder
); ?>
</th>
<th>
<?php echo JHtml::_(
'grid.sort',
'COM_ALLEKOLABO_PRODUCTS_LIST_DESC_LABEL',
'product_s_desc',
$listDir,
$listOrder
); ?>
</th>
<th>
<?php echo JHtml::_(
'grid.sort',
'COM_ALLEKOLABO_PRODUCTS_LIST_STOCK_LABEL',
'product_in_stock',
$listDir,
$listOrder
); ?>
</th>
<th>
<?php echo JHtml::_(
'grid.sort',
'COM_ALLEKOLABO_PRODUCTS_LIST_PRICE_LABEL',
'product_price',
$listDir,
$listOrder
); ?>
</th>
</tr>
</thead>
<tbody>
<?php foreach ($this->products as $i=>$product):?>
<tr class="row<?php echo $i%2; ?>">
<td class="center">
<?php echo JHtml::_('grid.id', $i, $product->virtuemart_product_id); ?>
</td>
<td class="center">
<a href="<?php echo $product->url; ?>"><?php echo $this->escape($product->product_name); ?></a>
</td>
<td class="center"><?php echo $this->escape($product->product_s_desc); ?></td>
<td class="center"><?php echo $this->escape($product->product_in_stock).' szt'; ?></td>
<td class="center"><?php echo round(($this->escape($product->product_price)),2).' zł'; ?></td>
</tr>
<?php endforeach;?>
</tbody>
<tfoot>
<tr>
<td colspan="3">
<?php echo $this->pagination->getListFooter(); ?>
</td>
</tr>
</tfoot>
</table>
<input type="hidden" name="filter_order" value="<?php echo $listOrder; ?>" />
<input type="hidden" name="filter_order_Dir" value="<?php echo $listDir; ?>" />
<input type="hidden" name="task" value="" />
<input type="hidden" name="boxchecked" value="0" />
<?php echo JHtml::_('form.token'); ?>
</form>
com_alleKolabo/views/product/view.html.php
<?phpdefined('_JEXEC') or die;
jimport('joomla.application.component.view');
class alleKolaboViewProduct extends JView {
protected $product;
function display($tmpl = NULL){
$this->product = $this->get('Item');
$this->toolbar();
parent::display($tmpl);
}
function toolbar(){
if($this->product->product_id){
JToolBarHelper::title_('COM_ALLEKOLABO_ADD_PRODUCT _TITLE');
}
JToolBarHelper::apply('product.apply', 'JTOOLBAR_APPLY');
JToolBarHelper::cancel('product.cancel');
}
}
com_alleKolabo/views/product/tmpl/edit.php
<?phpdefined('_JEXEC') or die; ?>
<form method="post" name="adminForm" class="form-validate" action="index.php?option=com_alleKolabo&product_id=<?php echo $this->product->virtuemart_product_id; ?>">
<input type="hidden" name="task" value="" />
<?php echo JHtml::_('form.token'); ?>
</form>
Dodaje także paczke ze wszystkimi plikami
7508
Liczę na waszą pomoc. Nic już mi do głowy nie przychodzi a to pewnie jakaś niewielka literówka.
Pozdrawiam i z góry dzięki!!