I use gii to generate a extension in yii2.0, here is the code
namespace ms\editor;
/**
* This is just an example.
*/
class AutoloadExample extends \yii\base\Widget
{
public function run()
{
return "Hello!";
}
}
when I want to use it in my view file,
use ms\editor\AutoloadExample;
...
<?= AutoloadExample::widget();?>
I use yii2 baisic template, and I put the "ms" folder in "vendor" folder, but it just tell me class ms\editor\AutoloadExample not found, what should I to make yii2 to find the class?is there something like "components"or "extension" folder in yii1.1? can you help me?
Your widget should inherit the CWidget class and place the widget in components.
public class AutoloadExample extends CWidget
{
public function run() { }
}
You can then run the widget in your view like this;
$this->widget('application.components.AutoloadExample', array('your variables'));
Would you try one such? for example create a file in "app/frontend/widgets/"
File Name : Deneme.php
<?php
namespace frontend\widgets;
class Deneme
{
static function yazdir () {
echo 'asd';
}
}
To use;
use frontend\widgets\Deneme;
Deneme::yazdir();