I am trying to use ArrayHelper in Yii2 advanced template project and it says Class ArrayHelper not found. I added use yii\helpers\ArrayHelper and it works in controller. But this problem continue to happen when I use ArrayHelper in view file. How can I autoload these classes in Yii2.
make sure you add namespace in view file too.
//in view_file_name.php
use yii\helpers\ArrayHelper;
You Did not show the code . So i am not able to give you the exact answer:
But you ask that you want to use array helper in your view so try this:
it is working .
use app\models\User;
use yii\helpers\ArrayHelper;
//use app\models\user;
$user=User::find()->all();
//use yii\helpers\ArrayHelper;
$listData=ArrayHelper::map($user,'user_id','username');
echo '<pre>';
print_r($listData);
echo '</pre>';
for more details visit :Yii2 Docs
Related
I have observed that when I execute the function:
Yii::$app->request->sendFile() within a row with a gridView, instead of launching the file, it shows it embedded in the HTML.
Then if I remove the Pjax::begin() and Pjax::end() borders that enclose the GridView, Then download works.
How can I work with both functionalities without losing one of them?
This was discussed at Yii2 the solution for now is to use this method:
<?php Pjax::begin([
'id' => 'list',
'linkSelector' => '#list a:not([data-pjax=0])'
]); ?>
custom js or simple link to your action with download
pjax link
<?php Pjax::end(); ?>
It looks like this feature may be included in future releases.
In one of my "Elements" I'd like to use the Inflector class, but it always shows
Fatal error: Inflector class not found.
How do I include this class in cake way in my view files?
I tried to add use Cake\Utility and use Cake\Utility\Inflector, but neither of them helped.
Try this one
\Cake\Utility\Inflector::humanize('Inflector working in the view')
fully qualified namespace from anywhere like Model, View or Controller
Note: Do no forget to use "\" at the start!
You can just fully qualify the inflector class methods i.e. Cake\Utility\Inflector::method() e.g.
<?= Cake\Utility\Inflector::humanize('Inflector working in the view') ?>
OR
You can just create a custom helper class, use the Inflector class there and then call the custom helper method in your view.
I am not familiar with PHP Syntax. Now i added JSON Plugin to my wordpress website and activate it.
When i open url to get_recent_post , it's fine. JSON data are showing.
But when i open get_post , it's only showing
{"status":"error","error":"Include 'id' or 'slug' var in your request."}
So i don't know how to add post id to that URL.
here is the pic. Another get_page , gate_date_posts, etc... links are same showing error.
How can i do it?
To display a post's ID, simply use the following PHP code within the WordPress loop:
<?php the_ID(); ?>
To return the ID, use the following PHP code within the WordPress loop:
<?php get_the_ID; ?>
To get a post's id outside of the WordPress loop use the following PHP code:
<?php global $post; $post->ID ?>
Hope that helps you.
http://yoursite.com/api/get_posts/
with the s
If you use the WordPress link and click on it, you will be fine.
I have placed a codeigniter code and i want that code in html.Pls help me to do this.
<? echo anchor('login/signup', 'Create Account');?>
Not sure why you want that code (which generates an anchor when the HTML page is rendered - look at your browser page source)
But what that CI URL helper translates to is:
Create Account
I can only assume you maybe want to add attributes to it and don't know how?
For example, you could add an ID and/or class like so:
<? echo anchor('login/signup', 'Create Account', 'id="some-id" class="some-class"');?>
Just make sure you're loading that 'helper' in your controller, or set it to autoload in the config/autoload.php file (which makes the most sense for this type of helper, as it'll likely be used site wide).
For more info on the CI URL Helper, visit here:
http://ellislab.com/codeigniter%20/user-guide/helpers/url_helper.html
I am using Text::MultiMarkdown to create HTML files from MultiMarkdown documents.
I would like all links to open in a new tab.
Is there a way to configure this behavior using a CSS template, or directly in the MultiMarkdown document (without explicitly writing HTML around each link in the MultiMarkdown document)?
Definitely not in CSS - that is only concerned with the way the elements appear, not how they behave.
It should be possible to add <base target="_blank"> to the head of the HTML document (using XSLT), but that's on par with adding it to each link.
In HTML and/or JavaScript you can only initialize the opening of a new window. The user is in some UAs able to force the opening of a new window as a new tab instead. But you can not control this behaviour.
In theory, you could do this with CSS3: http://www.w3.org/TR/css3-hyperlinks/ - however no common browser ever implemented this. The reason might be that it is a common believe that the choice of when a new window or tab is opened should be left to the user alone.
You can't do this in CSS but you can use the source.
You could subclass Text::MultiMarkdown and provide your own implementation of _GenerateAnchor, something similar to this might work:
sub _GenerateAnchor {
my ($self, $whole_match, $link_text, $link_id, $url, $title, $attributes) = #_;
if($url
&& index($url, '#') != 0) {
$attributes = $attributes ? $attributes . ' target="_blank"' : 'target="_blank"';
}
return $self->SUPER::_GenerateAnchor($whole_match, $link_text, $link_id, $url, $title, $attributes);
}
This is a bit kludgey as _GenerateAnchor isn't part of the public interface. You'd also need to use the OO interface rather than just the markdown function.
You could also contact the Text::MultiMarkdown author and see if he'll add a flag for this sort of thing. Maybe you could provide a patch to get things started.
You can also use HTML::Parser and friends to parse the HTML that comes out of Text::MultiMarkdown and add the target attributes yourself.