Have a column with this format "DC2Type:array" in symphony try to read data as array but receive a Null.
my function is:
public function getData()
{
return $this->data;
}
need some particular way or is another inconvenient different. Thank you.
check your data is set or not: example code
public $data ;
public function getData()
{
return $this->data;
}
public function setData($data)
{
return $this->data = $data;
}
Related
I am trying to retrieve a value from one action hook to be displayed in admin page.
public function hookActionProductCancel($params)
{
$this->response = "response";
}
public function hookDisplayAdminOrder($params) {
$this->context->smarty->assign('response', $this->response);
return $this->display(__FILE__, 'views/templates/admin/response.tpl');
}
I am not receiving the value "response" in response.tpl. Probably a small issue but I am not getting it right at the moment.
Any guidance is truly appreciated. Thank you.
You should just store the response to cookie and clear it before displaying it.
public function hookActionProductCancel($params)
{
// code
$this->context->cookie->mymodule_response = "response";
$this->context->cookie->write();
}
public function hookDisplayAdminOrder($params)
{
// if no response stored in cookie do nothing
if (!$this->context->cookie->mymodule_response) {
return false;
}
// assign response from cookie to smarty then clear response from cookie
$this->context->smarty->assign('response', $this->context->cookie->mymodule_response);
unset($this->context->cookie->mymodule_response);
return $this->display(__FILE__, 'views/templates/admin/response.tpl');
}
You are forgetting to use this
public function hookActionProductCancel($params)
{
..... codes .....
$this->response = "response";
}
public function hookDisplayAdminOrder($params)
{
$this->context->smarty->assign('response', $this->response);
return $this->display(__FILE__, 'views/templates/admin/response.tpl');
}
I'm trying to return two methods at once in the find function
public function find($id)
{
return AddRepository::findOrFail($id) &&
AddMeRepository::findOrFail($id);
}
public function find($id)
{
var result = [];
result['addRepository'] = AddRepository::findOrFail($id);
result['addMeRepository'] =AddMeRepository::findOrFail($id);
return result;
}
public static function find($id)
{
return array(AddRepository::findOrFail($id) ,AddMeRepository::findOrFail($id));
}
when you call method
list($add,$addme)=YourClass::find($id);
you can use $add and $addme variables.
Okay the issue is something like this
I have a function in AController
public function index()
{
$store = Store::(query)(to)(rows)->first();
return view('store.index', compact('store'));
}
Now in the same controller I have another function
public function abc()
{
return view('store.abc');
}
Now to this function I also want to send the compact('store') to the view abc I can just add the query again in the abc() function but that would be lazy and make performance issues. Is there a way that I can access $store object in other functions too?
If I understand you correctly you want to access the same query from two places. So extract getting stores to another method like
private function store()
{
$minutes = 10; // set here
return Cache::remember('users', $minutes, function () {
return Store::(query)(to)(rows)->first();
});
}
Additionally I have cached the query. So it get executed once at a defiened time.
Then access it from other two methods like,
public function index()
{
$store = $this->store();
return view('store.index', compact('store'));
}
public function abc()
{
$store = $this->store();
return view('store.abc', compact('store'));
}
class StoreController extends Controller
{
public function index()
{
return view('admin.store',['data' => $this->getSetting()]);
}
public function getStoreData()
{
//get your data here, for example
$data = Store::where('status',1)->first();
//get all data
//$data = Store::all();
return ($data);
}
}
Try the following. Not testing but it should work for you.
class AController
{
public function getStore()
{
$store = Store::(query)(to)(rows)->first();
return compact('store');
}
public function index()
{
return view('store.index', $this->getStore());
}
public function abc()
{
return view('store.abc', $this->getStore());
}
}
I am having the following class:
class StuffDoer{
public function __construct(Dep1 $dep, Dep2 $dep2, array $array){
$this->dep = $dep;
$this->dep2 = $dep2;
$this->array = $array;
}
public function genericDoStuff($param){
// Do stuff here...
}
public function doStuffForMark(){
return $this->genericDoStuff('Mark');
}
public function doStuffForTim(){
return $this->genericDoStuff('Tim');
}
public function doStuffForAlice(){
return $this->genericDoStuff('Alice');
}
}
After some months, I am asked to make the method genericDoStuff($param), along with all the methods that depend on it, use an extra parameter in a single part of the application. Instead of changing the signature on every single method that depends on genericDoStuff, I ended up with the following:
class StuffDoer{
public function __construct(Dep1 $dep, Dep2 $dep2, array $array){
$this->dep = $dep;
$this->dep2 = $dep2;
$this->array = $array;
}
public function forParameter($param){
$self = clone $this;
$this->param = $param;
return $self;
}
public function genericDoStuff($param){
if($this->param !== null){
// Do stuff by taking param into account
} else {
// Do stuff stuffdoer does
}
}
public function doStuffForMark(){
return $this->genericDoStuff('Mark');
}
public function doStuffForTim(){
return $this->genericDoStuff('Tim');
}
public function doStuffForAlice(){
return $this->genericDoStuff('Alice');
}
}
That way, I am able to do this in the single point of the application:
$myStuffDoer = $serviceContainer->get('stuff_doer');
$myStuffDoer->forParameter('AAAARGHITBURNSGODHELPME')->doStuffForMark();
// Future usages of $myStuffDoer are unaffected by this!
So my question is this: Is this considered a bad practice for any reason?
class Test
{
public $data = array();
public function addData($data = array())
{
array_merge($data, $this->data);
return $this;
}
public function showData()
{
print_r($this->data);
}
}
$test = new Test;
$test->addData(array("halo", "zaki"))->showData();
i tried to merging 2 array, but it doesn't work, maybe someone can explain to me?
array_merge does not modify the arrays passed to it, but rather returns the result.
Try this:
public function addData($data = array())
{
$this->data = array_merge($data, $this->data);
return $this;
}
You forgot to assign the resulting array to member variable $data. It should be,
$this->data = array_merge($data, $this->data);