I am working in wordpress and using buddypress theme. In my php file i want to set value of a buddy press functions into an array parameter like following
PLUGIN_METHOD( array( 'Para1' => 'Value1', 'Para2' => bp_activity_user_link()));
But i am unable to set value of function's into array.
Please suggest me right way.
Thanks in advance!
That function echos the result and returns void, so it won't get passed to the array. Use this function:
bp_get_activity_user_link();
Ok, last try :). It's possible your version of BP doesn't have that function. You can try this:
ob_start();
bp_activity_user_link();
$link_out = ob_get_contents();
ob_end_clean();
PLUGIN_METHOD( array( 'Para1' => 'Value1', 'Para2' => $link_out));
PLUGIN_METHOD( array( 'Para1' => 'Value1', 'Para2' => bp_activity_user_link(); ) );
^
You just have to fix the parse error by removing your ; after the nested function call and that's it
PLUGIN_METHOD( array( 'Para1' => 'Value1', 'Para2' => bp_activity_user_link()));
Related
I'm trying to pass data about the page state (navbar links having active class when you are in that exact page), page title. I do so with an indexed array $pageInfo, however I am getting a syntax error and doen't know where?
Also do you think this is a good method or should I use view->share() instead?
public function clases()
{
$pageInfo[] =
(
'page_title' => 'Clases',
'menu_active' => 'CLases',
'sub_menu_active' => '',
);
return view('clases.list', compact('pageInfo'));
}
public function domicilio()
{
$pageInfo[] =
(
'page_title' => 'Clases a domicilio',
'menu_active' => 'Clases',
'sub_menu_active' => 'Clases a domicilio',
);
return view('clases.domicilio', compact('pageInfo'));
I suggest you read PHP basic syntax.
Basically you want to do this:
$pageInfo =
[
'page_title' => 'Clases',
'menu_active' => 'CLases',
'sub_menu_active' => '',
];
Arrays have a syntax of [key => val, ...] in PHP, you're using () as it seems.
Also $someArray[] = someValue, will append the someValue to an existing array, in your case that would create another, unwanted level of your array.
And last, you're not ending the domicilio() function. But I'll assume you just didn't paste it in (you should add } at the end, if that's not the case).
Here's my code:
<?php
use WHMCS\View\Menu\Item as MenuItem;
add_hook('ClientAreaPrimarySidebar', 1, function(MenuItem $primarySidebar)
{
if (!is_null($primarySidebar->getChild('Service Details Actions'))) {
$primarySidebar->getChild('Service Details Actions')
->addChild('Check', array(
'label' => 'Checker',
'uri' => 'http://example.com/check/'.print_r($vars['params']['domain']).'-check',
'order' => '3',
));
}
});
I am wanting the uri to link to here (assuming $domain = testdomain.com):
http://example.com/check/testdomain.com-check
Instead, it is showing this right now:
http://example.com/check/1-check
This is the specific line that I guess I'm having trouble with:
'uri' => 'http://example.com/check/'.print_r($vars['params']['domain']).'-check',
What am I doing wrong here?
The call to print_r() is unnecessary. Assuming that the string "testdomain.com" is stored in $vars['params']['domain'], then you simply need to concatenate the variable with the string like this:
'uri' => 'http://example.com/check/'.$vars['params']['domain'].'-check',
The function print_r() prints readable information about the given variable. Typically it is only used for debugging.
I know this type of question has been asked a number of times. I have spent several hours reading and trying the offered solutions - but none appear to work for my situation.
I need to send a SOAP request to an API that can contain an element that repeats like so:
<operationNumbers>
<operationNumber>1234</operationNumber>
<operationNumber>1235</operationNumber>
<operationNumber>1236</operationNumber>
<operationNumber>1237</operationNumber>
</operationNumbers>
I did read that perhaps I could do this:
$buildRequest = Array(
'myheader' => Array(
'date' => MY_DATE,
'id' => Array(
'client' => CLIENT,
'clientRef' => MYREF
)
),
'operationNumbers' => Array (
Array('operationNumber' => '1234'),
Array('operationNumber' => '1235')
)
);
$request = $client->__soapCall( 'getMultiOpDets', array($buildRequest) );
Sadly this does not work and results in 'invalid request', if I send in a single operation number eg:
...
'operationNumbers' => Array (
'operationNumber' => '1234'
)
...
The request is successful. I've tried soapVars/soapParams but cannot get it working using this approach. Any hints/tips/help appreciated.
So, I solved it.
$operationNumbersArray = array('1234','1235');
...
'operationNumbers' => array(
'operationNumber' => $operationNumbersArray
)
During my testing and fiddling about, I had inadvertently removed another value that was mandatory. The API did not give warning of it's omission (sadly).
Here is the code I use:
$wsdl = 'https://your.api/path?wsdl';
$client = new SoapClient($wsdl);
$multipleSearchValues = [1, 2, 3, 4];
$queryData = ['yourFieldName' => $multipleSearchValues];
$results = $client->YourApiMethod($queryData);
print_r($results);
I am trying to convert post data into a format that would allow me to pass it right into my collection. For example: When I print_r on the $_POST I get this form data:
Array
(
[Name] => Steve
[Email] => Steve#mail.com
[submit] => Submit
)
I am wondering how i can convert this to an acceptable object to insert into mongodb collection using php similar to:
$Record = array(
'Name' => 'Steve',
'Email' => 'Steve#mail.com',
'submit' => 'Submit'
);
$Collection->insert($Record);
I am thinking a loop of the above array with some additional formatting but I can't seem to figure it out. I have also tried json_encode but keep getting the same error "Call to a member function insert() on a non-object in..." saying that its not a proper object. Thank you for any help.
No need to encode anything, it's just PHP native and expects an array. Let the driver do the work for you:
$Collection->insert( $_POST );
As it is the two should be equivalant:
$rec = array(
'Name' => 'Steve',
'Email' => 'Steve#mail.com',
'submit' => 'Submit'
);
print_r ($rec);
I want to be able to add multiple PregReplace filters on a single Zend Form element.
I can add one PregReplace filter using the code below:
$word = new Zend_Form_Element_Text('word');
$word->addFilter('PregReplace', array(
'match' => '/bob/',
'replace' => 'john'
));
$this->addElement($word);
I've tried
$word = new Zend_Form_Element_Text('word');
$word->addFilter('PregReplace', array(
'match' => '/bob/',
'replace' => 'john'
));
$word->addFilter('PregReplace', array(
'match' => '/sam/',
'replace' => 'dave'
));
$this->addElement($word);
but this just meant only the second filter worked.
How do I add multiple PregReplace filters?
The problem you're facing is that the second filter will override the first one in the filters stack ($this->_filters) defined in Zend_Form_Element.
As David mentioned in the question comments, the filters stack use filter names as index ($this->_filters[$name] = $filter;) this is the reason why the second filter override the first one.
In order to resolve this problem, you can use a custom filter as follows:
$element->addFilter('callback', function($v) { return preg_replace(array('/bob/', '/sam/'),array('john', 'dave'), $v); });
This is done using an inline function(), in case you're not using PHP version 5.3 or higher, you can set your callback as follows to make it work:
$element->addFilter('callback', array('callback' => array($this, 'funcName')));
And add under your init() method in your form:
function funcName($v) {
return preg_replace(array('/bob/', '/sam/'), array('john', 'dave'), $v);
}
At last, if you want to use only the PregReplace filter, unlike Marcin's answer (the syntax is incorrect), you can still do it this way:
$element->addFilter('pregReplace', array(
array('match' => array('/bob/', '/sam/'),
'replace' => array('john', 'dave')
)));
That should do the trick ;)
Since PregReplace uses php's preg_replace function, I guess something like this would be possible (preg_replace can accepts arrays of patterns and array of corresponding replacement strings):
$word = new Zend_Form_Element_Text('word');
$word->addFilter('PregReplace', array(
'match' => array('/bob/', '/sam/'),
'replace' => array('john' , dave)
));
$this->addElement($word);
I haven't tested it though. Hope it will work.
I was unable to get the previous example to work with 'PregReplace'. I switched instead to calling it with new Zend_Filter_PregReplace(). It now works for me.
$word->addFilter(new Zend_Filter_PregReplace(array(
'match' => array('/bob/', '/sam/'),
'replace'=> array('john', 'dave'))
));
I was looking for same-response does not have a usable version
$word->addFilter(new Zend_Filter_PregReplace(new Zend_Config(array(
'match'=>array('/bob/', '/sam/'),
'replace'=>array('john', 'dave')
))));