小编use*_*056的帖子

Yii2中的Ajax + Controller Action

我是编程的新手,我正在尝试在用户输入数据并单击提交按钮时调用函数.我正在使用Yii2而且我不熟悉Ajax.我尝试开发一个函数,但我的控制器操作没有被调用.

这是我正在尝试的示例代码:

意见/ index.php文件:

<script>
    function myFunction()
    {
        $.ajax({
            url: '<?php echo Yii::$app->request->baseUrl. '/supermarkets/sample' ?>',
           type: 'post',
           data: {searchname: $("#searchname").val() , searchby:$("#searchby").val()},
           success: function (data) {
              alert(data);

           }

      });
    }
</script>

<?php
use yii\helpers\Html;
use yii\widgets\LinkPager;

?>
<h1>Supermarkets</h1>
<ul>

<select id="searchby">
    <option value="" disabled="disabled" selected="selected">Search by</option>
    <option value="Name">Name</option>
    <option value="Location">Location</option>
</select>

<input type="text" value ="" name="searchname", id="searchname">
<button onclick="myFunction()">Search</button>
<h3> </h3>
Run Code Online (Sandbox Code Playgroud)

控制器:

public function actionSample(){         
     echo "ok";
}
Run Code Online (Sandbox Code Playgroud)

我的问题是,当我点击搜索按钮时没有任何反应,当我尝试调试它时,调试器不运行代码!

javascript php ajax jquery yii2

15
推荐指数
1
解决办法
7万
查看次数

Yii2从DB登录(设置未知属性:app\models\User :: password_hash)

我希望Yii中的用户身份验证基于我的数据库中的用户表.这是我的用户模型:

<?php

namespace app\models;

use Yii;
use yii\base\NotSupportedException;
use yii\db\ActiveRecord;
use yii\helpers\Security;
use yii\web\IdentityInterface;


/**
 * This is the model class for table "user".
 *
 * @property integer $id
 * @property string $username
 * @property string $password
 * @property string $title
 */
class User extends \yii\db\ActiveRecord implements IdentityInterface
{


    public static function tableName()
    {
        return 'user';
    }



    /**
     * @inheritdoc
     */

    public function rules()
    {
        return [
            [['username', 'password'], 'required'],

            [['username', 'password'], 'string', 'max' => 100]           

        ];
    }



    /**
     * …
Run Code Online (Sandbox Code Playgroud)

authentication password-hash yii2 yii2-user

4
推荐指数
1
解决办法
1万
查看次数

找不到 Yii 类 CActiveDataProvider

我是 Yii 的新手,在运行小部件时出现此错误“未找到类 'app\controllers\CActiveDataProvider'”。

这是我的代码:

模型/industrial.php:

<?php

namespace app\models;

use yii\db\ActiveRecord;

class Industrial extends ActiveRecord
{
}
Run Code Online (Sandbox Code Playgroud)

控制器/工业控制器.php:

<?php

namespace app\controllers;

use yii\web\Controller;
use yii\data\Pagination;
use app\models\industrial;


class IndustrialController extends Controller
{


    public function actionIndex()
    {
        $dataProvider=new CActiveDataProvider('Industrial', array(

    'pagination'=>array(
        'pageSize'=>20,
    ),
));
        $query = industrial::find();

        $pagination = new Pagination([
            'defaultPageSize' => 20,
            'totalCount' => $query->count(),
        ]);

        $industrials = $query->orderBy('Company_Name')
            ->offset($pagination->offset)
            ->limit($pagination->limit)
            ->all();




        return $this->render('index', [
            'industrials' => $industrials,
            'pagination' => $pagination,
            'dataProvider'=>$dataProvider,
        ]);



}
}
Run Code Online (Sandbox Code Playgroud)

意见/工业/index.php:

<?php
use yii\helpers\Html; …
Run Code Online (Sandbox Code Playgroud)

php yii dataprovider cactivedataprovider

2
推荐指数
1
解决办法
5100
查看次数

Android计算百分比

我是android和Java的新手,我必须设计一个简单的应用程序来读取金额并在吐司中显示这个数量的10%.这是我的代码:

activity_main.xml中:

 <EditText
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:id="@+id/amount"
        android:hint="Bill amount in L.L"
        android:layout_marginTop="53dp"
        android:layout_below="@+id/text"
        android:layout_alignParentLeft="true"
        android:layout_alignParentStart="true"
        android:inputType="number"/>

    <Button
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:text="10%"
        android:id="@+id/button"
        android:layout_below="@+id/amount"
        android:layout_centerHorizontal="true"
        android:layout_marginTop="65dp"
        android:onClick="tenp"/>
Run Code Online (Sandbox Code Playgroud)

MainActivity.java:

 public void tenp(View view1) {

       EditText e = (EditText) findViewById(R.id.amount);


        double amount = Double.parseDouble(e.getText().toString());

        double res = (amount / 100.0f) * 10;

        Toast.makeText(getApplicationContext(), "" +res, Toast.LENGTH_SHORT).show();

    }
Run Code Online (Sandbox Code Playgroud)

当我运行我的应用程序并单击10%按钮时,应用程序将关闭.我不知道这里的错误是什么.请帮忙.

java android

2
推荐指数
1
解决办法
2万
查看次数

如何在 Yii 中添加搜索和过滤条件

我正在使用 Yii 框架开发数据库应用程序。我正在从 MySQL 数据库中读取表并将它们显示给用户。我需要用户能够过滤表中的字段或搜索某个值。

例如,我有一个名为“supermarkets”的表:

CREATE TABLE IF NOT EXISTS `supermarkets` (
  `Name` varchar(71) NOT NULL,
  `Location` varchar(191) DEFAULT NULL,
  `Telephone` varchar(68) DEFAULT NULL,
  `Fax` varchar(29) DEFAULT NULL,
  `Website` varchar(24) DEFAULT NULL
) ENGINE=InnoDB DEFAULT CHARSET=latin1;
Run Code Online (Sandbox Code Playgroud)

.../型号/超市:

<?php

namespace app\models;

use yii\db\ActiveRecord;

class Supermarkets extends ActiveRecord
{



}
Run Code Online (Sandbox Code Playgroud)

.../views/supermarkets/index.php:

<?php
use yii\helpers\Html;
use yii\widgets\LinkPager;
?>
<h1>Supermarkets</h1>
<ul>
<?php
$array = (array) $supermarkets;

function build_table($array){

    // start table

    $html = '<table class="altrowstable" id="alternatecolor">';

    // header row

    $html .= '<tr>';

    foreach($array[0] …
Run Code Online (Sandbox Code Playgroud)

php mysql search filter yii

1
推荐指数
1
解决办法
8160
查看次数