Calling new controller from admin

Hello everyone.

I am trying to call a new controller from order_package_list.tpl file like this:

  <form class="js-oxValidate" name="fertig" action="index.php?force_admin_sid=siccb6fc2adu8mcuidsejolre3&stoken=4F66373A&cl=fertig&fnc=fertig_gepacht" method="post" role="form" novalidate="novalidate">
      [{$oViewConf->getHiddenSid()}]
      <input type="hidden" name="cl" value="fertig">
      <input type="hidden" name="fnc" value="fertig_gepacht">
      <input type="hidden" name="ordernr" value="[{ $order->oxorder__oxordernr->value}]">
      <input type="submit" value="Fertig gepackt!">
  </form>

This is how my controller looks like in application/controller/admin/fertig.php:
class fertig extends oxAdminDetails
{

/**
 * Executes parent method parent::render(), fetches order info from DB,
 * passes it to Smarty engine and returns name of template file.
 * "order_package.tpl"
 *
 * @return string
 */


public function fertig_gepacht(){

    // $fertig = oxNew('fertig');
    //$fertig -> update_order();



    $myConfig = $this->getConfig();
    parent::render();

    $aOrders = oxNew('oxlist');
    $aOrders->init('oxorder');
    $sSql = "select * from oxorder where oxorder.oxsenddate = '0000-00-00 00:00:00' and oxorder.oxshopid = '" .
        $myConfig->getShopId() . "' order by oxorder.oxorderdate asc limit 5000";
    $aOrders->selectString($sSql);

    $this->_aViewData['resultset'] = $aOrders;

    return "order_package.tpl";
}

}

Problem is that I am getting front page of the shop :confused:

check your exception log.
I’m not sure abould older oxid versions, but in new versions templates are only rendered if returned by the render() function, while other functions cause a redirect.
Basically, i think you are redirecting the user to controller “order_package.tpl” which does not exist.
It the exception message confirms that, you will have to add a proper render() function, like in all the other controllers.

I am running shop version 4.10 on localhost xampp. How can view exception logs?

I am new to oxid. I am trying to use the same function written in another admin controller, so order_package.tpl does exist.

I have changed order_package_list.tpl to

<form class="js-oxValidate" name="fertig" action="index.php?force_admin_sid=siccb6fc2adu8mcuidsejolre3&stoken=4F66373A&cl=fertig" method="post" role="form" novalidate="novalidate"

and fertig.php controller to:

class Fertig extends oxAdminDetails
{

/**
 * Executes parent method parent::render(), fetches order info from DB,
 * passes it to Smarty engine and returns name of template file.
 * "order_package.tpl"
 *
 * @return string
 */
public function render()
{


    $myConfig = $this->getConfig();
    parent::render();

    $aOrders = oxNew('oxlist');
    $aOrders->init('oxorder');
    $sSql = "select * from oxorder where oxorder.oxsenddate = '0000-00-00 00:00:00' and oxorder.oxshopid = '" .
        $myConfig->getShopId() . "' order by oxorder.oxorderdate asc limit 5000";
    $aOrders->selectString($sSql);

    $this->_aViewData['resultset'] = $aOrders;

    return "order_package.tpl";
}

}

But it is not going to render function now. I checked with debugger.

What will be the correct way to call the render function from tpl file?

Please read the Module Documentation Module resources — OXID eShop developer documentation 6.1.0 documentation

You have to make the controller known via a module.

I am using oxid version 4.10.2. Do i need to use module in this version aswell?

Not sure.

You can orientate yourself on my blog article series for the OXID eShop series 4.8, this comes closest to your version.

A lot has changed from Series 6 onwards.

You could have my articles translated into English.

My blog articles series Modulentwicklung | Professionelle Modulentwicklung and the source code GitHub - Indianer3c/bisQuestionAnswer: How to Module Development Tutorial for OXID eShop Community Edition Series 4.8 (2015)

You don’t need to call a render function. Variables are set in this method to get them in the View: $this->_aViewData[‘resultset’] = ;

Why do i need to use modules, if i can do some database queries by making new controllers and calling them?

Thanks for your reply.

I dont need get variable in view right now. I just want to pass a variable to module and update database value
Something like :
UPDATE oxorder SET OXFOLDER = ‘ORDERFOLDER_FINISHED’ WHERE OXORDERNR = current order nr;

For testing you don’t need a module. You can copy your file to

application/controllers/admin

and call it like the others in admin.

You can do this too. Then you have to use getRequestParameter(‘ordernr’); to work with

Thanks for your reply. It is very helpful.

My question is that since I am able to do what I want to without using module.
Then what is the need to create a module?

Download the demo:

In metadata.php add something like this:

'files' => array(
		'fertig' => 'modulfolder/modulename/controllers/admin/fertig.php'
		),

and copy your file in this folder.

Thank you for your answers. I will read more about module development.

1 Like

Good idea :wink:

1 Like

This topic was automatically closed 365 days after the last reply. New replies are no longer allowed.