gamilix
(Gamilyd)
March 3, 2013, 7:49am
1
hi,
i follow the wiki How to use a Widget as an Action Provider
in my view i have ajax calls that call to the action.
I want to return the response as an output of renderPartial() function, but my controller is undefined.
$output = $this->getController()->renderPartial('_filterwithManufacturer', array(), true, true);
is there anyway to initiate the controller?
should i passed it as a parameter?
Thanks
seenivasan
(Chellamnivas)
March 3, 2013, 10:59am
2
Dear Friend
My conviction is that inside the view $this refers to the controller rather than action.
Then we have to make it like following.
$output = $this->renderPartial('_filterwithManufacturer', array(), true, true);
If we have doubt, we can verify that by calling the following in the view.
echo $this->id;
Regards.
gamilix
(Gamilyd)
March 3, 2013, 1:34pm
3
Hi,
Thanks for your reply, i guess that i didn’t explain my self clearly.
I have a widget: businessesSearch
class BusinessesSearch extends CWidget
{
public static function actions(){
return array(
// naming the action and pointing to the location
// where the external action class is
'buildAdditionalFilters'=>'ext.BusinessesSearch.actions.buildAdditionalFilters',
);
}
and an action - buildAdditionalFilters:
class buildAdditionalFilters extends CAction
{
public function run()
{
......
$output = $this->getController()->renderPartial('_filterwithManufacturer', array(), true, true);
echo '{ "filters" : "'. $output . '" }'; //JSON Syntax
return ;
}
}
and a controller which declares the action:
class BusinessesSearchController extends Controller
{
public function actions()
{
// return external action classes, e.g.:
return array(
'bs.'=>'ext.BusinessesSearch.BusinessesSearch',
);
}
}
So, in my action i am trying to renderPartial a view.
the $this (i think) refers to CAction, and from few examples that i saw the getController() function suppose to return the controller, but it null.
any ideas?
Thanks
Dear Fiend
I thought you are calling the following code
$output = $this->getController()->renderPartial();
inside the file _filterwithManufacturer.php. .
That caused confusion…
Let us have one example.
protected/components/NewAction.php
<?php
class NewAction extends CAction
{
public function run()
{
echo $this->controller->renderPartial("testAction");
}
}
?>
protected/components/NewWidget.php
<?php
class NewWidget extends CWidget
{
public static function actions()
{
return array(
'greet'=>'application.components.NewAction',
);
}
}
?>
TrialController.php
public function actions()
{
return array(
'test.'=>'application.components.NewWidget'
);
}
views/trial/testAction.php
<?php
echo "hello world";
echo "</br>";
echo $this->id;
echo "</br>";
echo $this->action->id;
?>
Now the following url
http://localhost/boost/index.php?r=trial/test.greet
outputs the following in browser window.
hello world
trial
test.greet
Ofcourse inside the CAction class, $this definetly refers to the action itself.
gamilix
(Gamilyd)
March 4, 2013, 6:57am
5
Thanks a lot for your detailed reply
the problem was that i didnt use the "run" function in the CAction, but added a new public function.
In this function the controller wasnt initialized.
Thanks!