In the following code (codeigniter documentation), how can i put an <a href=""> on a specific field? Is it possible?
$this->load->library('table');
$query = $this->db->query('SELECT * FROM my_table');
echo $this->table->generate($query);
Thanks a lot.
The solution is to do a foreach on your dataset and then amend the element using the anchor function which is an HTML helper within CI. Something like this:
foreach ($data as $=>$row){
$data[$k]['field'] = anchor($row['URL'],$row['DisplayText']);
}
Related
I have Zend_Form with button type element. i don't how to use onclick type from zend_form.
Index.phtml
Search
Zend_Form
$Search = new Zend_Form_Element_Submit('Search');
$Search->setAttrib('ID', 'searchbutton');
$Search->setDecorators(array('ViewHelper'));
Here using this zend form how to perform the onclick action using search button.could you please any one help on this?
Thanks for advice!
Hey you would have to do something like this
$Search = new Zend_Form_Element_Submit('Search');
$Search->setAttrib('ID', 'searchbutton');
$Search->setDecorators(array('ViewHelper'));
$form = new Zend_Form('FormExample');
$form->setAction('destination.php');
$form->setMethod('POST');
$form->addElement($Search);
$form->setView(new Zend_View());
print($form);
If you have other elements than the $Search you just have to addElements as an array, like this:
$form->addElements([$Search,$Element1, $Element2]);
I'm having an issue displaying information returned from a custom class defined within a plugin's files, when using a shortcode. I'll write up some mock files that showcase my issue.
/wp-content/plugins/my-plugin/classes/my_class.php
<?php
class People {
public $api_url = "https://www.external-service.com/api";
private $api_key;
function __construct($key = null) {
if $(key) {
$this->api_key = $key;
}
function get_response() {
$path = $this->api_url . "?my_api_token=" . $this->api_key;
}
}
?>
/wp-content/plugins/my-plugin/my-plugin.php
<?php
/**
* all of the wordpress plugin comments
* ...
*/
require "myplg_options.php";
require "myplg_shortcodes.php";
The options page and menu is generated from myplg_options; it is functioning correctly (including using get_option to retrieve the saved option (in this case, the api key).
/wp-content/plugins/my-plugin/myplg_shortcodes.php
<?php
require "classes/my_class.php";
$options = get_option('myplg_settings');
$myplg = new People($options['myplg_api_key']);
$response = $myplg->get_response();
function myplg_list_result(){
echo "the shortcode is working!";
var_dump($options, $myplg, $respnose);
}
add_shortcode('myplg_list', 'myplg_list_result');
?>
Testing externally from wordpress, the class works and everything is fine and dandy. The plugin's option page sets and retains the single option perfectly; the shortcode actually registers and is usable from within a WordPress page/portfolio/etc.
The issue I'm having is that using var_dump, all three of those variables are dumped as NULL.
After doing some homework, I was able to determine that moving the three variable declarations inside the shortcode makes it work. It would seem to me, however, that doing that is not the best workflow, as I'd need to re-grab the option, instantiate a new class, and call the class' function for every shortcode.
Is there a way around this?
As mentioned in the comment it's because variables are function scoped. You may be better off using a Closure.
<?php
require "classes/my_class.php";
$options = get_option('myplg_settings');
$myplg = new People($options['myplg_api_key']);
$response = $myplg->get_response();
add_shortcode('myplg_list', function() use ($options, $response, $myplg) {
echo "the shortcode is working!";
var_dump($options, $myplg, $respnose);
});
I need to run in my zend project, inside a controller something like:
<?php for($i=1; $i<10; $i++){
$this->view->someVariable.$i = $someClassName->someFunction();
} ?>
But it doesn't work. I tried to declare $this->view->someVariable, but it doesn't work any way . Any ideas?
$this->view->someVariable.$i is an expression not a variable so you cant assign a value to it. If $this->view->someVariable is an array you can assign values to its elements like,
<?php
for ($i=1; $i<10; $i++){
$this->view->someVariable[$i] = $someClassName->someFunction();
}
?>
Maybe you need curly braces:
$this->view->{$this->view->someVariable . $i} = $someClassName->function();
although I can't help but wonder what you're trying to achieve. Have you dumped the return value of $someClassName->function()?
I use symfony 1.4 and I use Zend Lucene search like in Jobbet And I need to make Search Results Highlighting, I read this , but I do not understend how it make in my case with symfony(
$ highlightedHTML = $ query-> highlightMatches ($sourceHTML);
What is $sourceHTML? And is it all makes by only one row?
upd:
$ highlightedHTML = $ query-> highlightMatches ($sourceHTML);
It works in my model, but how it implement in my view?
I do not now , if it is right , but it is work :)
Just in view:
$query = Zend_Search_Lucene_Search_QueryParser::parse($queryStr);
$highlightedHTML = $query->highlightMatches($sourceHTML);
In my case for example:
echo $query->highlightMatches($ad->getCompany())
You need to store this highlighted HTML in your model. Or make a function that is accessible from the view. For example:
<?php
class Model {
private $content;
public function getContent(){
return $this->content;
}
public function getContentHighlighted(){
// Search term, usually in $_GET or $_POST
$term = $_GET['searchterm'];
// Parse query
$query = Zend_Search_Lucene_Search_QueryParser::parse($term);
// Return highlighted
return $query->highlightMatches($this->getContent());
}
}
?>
In your view (like in this case: Twig) you use:
<h1>The content</h1>
{{model.getContentHighlighted}}
I'm fairly new to jQuery, and think I might be making something harder than it needs to be. I've got a jQuery variable that is just an unordered list. It was declared this way:
var $list = $('#activityList'); // activityList is ID of <ul>
I'm trying to select all <li> elements within that list using the variable I've created:
$items = $('#' + $list.attr('id') + ' > li');
Does anyone know if there's a different syntax to achieve the same thing without having to break the variable down to it's id attribute?
Thanks.
Clarification: I used simplified code for the purposes of asking the question, but I do want to make use of the jQuery variable "$list" within the selector, rather than hardcoding the ID.
$items = $('li', $list);
That should do what you are looking for.
$("#activitylist > li") would work, as > traverses content. You can also use, with $list as a JQuery object:
$list.find("li") or $list.children("li") to find the list items as well. children would be more efficient if you are only looking for immediate children.
Try this:
var items = $('#activityList > li');
Maybe I'm misunderstanding, but what's wrong with...
var $items = $('#activityList > li');