Jump to content

Set Var In Controller To Use It Globbaly


Blesta Addons

Recommended Posts

You can set data to the structure with

$this->structure->set("var", "value");

as long as your plugin controller is extending AppController.

 

Plugins are loaded after the client_main template has been displayed, so you wouldn't be able to set data there.

Link to comment
Share on other sites

  • 1 year later...

related to this question , we want to set a var via plugin to use it in structure.pdt . is possible ?

Yes.

 

 

we have tried to sue the preaction event to set the var , but is not working .

 

What have you done?

 

 

how to achieve this ?

 

Your plugin controller:

class MyController extends MyPluginController {
    public function preAction() {
        parent::preAction();

        $this->structure->set('my_var', 'my_value');

        ...
    }

    ...
}

structure.pdt:

echo $this->Html->ifSet($my_var);

The variable will only be displayed in the structure if your plugin controller has been loaded.

Link to comment
Share on other sites

[/code]
The variable will only be displayed in the structure if your plugin controller has been loaded.


this is our probleme . we need to use this var in any other controller like the base_uri var .

i have tested all this in the preAction event without result
 

$this->my_test ="kkkk" ;
$this->structure->my_test = "4654564";
$this->view->my_test = "31313";
$this->structure->set("my_test", "46789");
$this->set("my_test", "kkkk");
Link to comment
Share on other sites

The variable you set is not available on pages where the plugin is not loaded to call one of its controller actions. Your plugin is simply not called on most pages, so it never sets the variable to the structure.

 

Have you tried tying into the Appcontroller.structure event?

 

the structure event will inject a html code in the header or the body .

 

what i want is to inject a var (string or array) to the structure .

 

let say i want my plugin to collect some data from database and send it as a var to use is globally in my structure .

 

and normally the preAction event is called in all the pages loaded ? why is not setting the vars ?

Link to comment
Share on other sites

Have you tried setting the event to return an array of key/value pairs, where the key is the variable name, and the value is the variable's value?

 

no success , i have tried .

return array ("my_test" => "126" );

it would be wonderfull if the preAction can send return vars to the structure.pdt .

 

this feature can help alot of developpers/designer to add a  smarty ideas to blesta .

Link to comment
Share on other sites

It looks like you should be able to set variables to the structure from the Appcontroller.structure event, although I neither wrote the event nor tested this behavior. What are you setting for your event exactly?

 

the Appcontroller.structure event is just sent a output (html/javascripts) to the structure . no way to set a var for using in the template .

 

the Appcontroller.preAction event is called before any other controller , so it can be adjusted to set var for using in template structure.pdt .

 

i appreciate your effort and help if you can test them and give me the final result, so if not possible is not worth to lose time in something that can't be handled now by blesta . 

 

just to explain what i want to do .

 

let say i want to collect total invoices (open, closed, draft) in a var array() , then i want to send this var to the structure.pdt to use it in the header or any place .

 

can this be achieved via Appcontroller.structure event or Appcontroller.preaction event ?

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...
×
×
  • Create New...