Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/257.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Php 科哈纳。。简单的功能需要帮助_Php_Kohana - Fatal编程技术网

Php 科哈纳。。简单的功能需要帮助

Php 科哈纳。。简单的功能需要帮助,php,kohana,Php,Kohana,我是科哈纳的新手。。 Guyz plz指出以下代码中的错误。。我无法运行它。。这是一个与数据库的简单连接。。我可以比较查询结果和psot项吗。。请更正 <?php defined('SYSPATH') or die('No direct script access.'); /** * Default Kohana controller. */ class index_Controller extends Controller { public function index() { $db

我是科哈纳的新手。。 Guyz plz指出以下代码中的错误。。我无法运行它。。这是一个与数据库的简单连接。。我可以比较查询结果和psot项吗。。请更正

<?php defined('SYSPATH') or die('No direct script access.');
/**
* Default Kohana controller.
*/
class index_Controller extends Controller {
public function index()
{
$db = new Database();
$index = new View('Index')
$db->connect();
name = $post['name'];
password = $post['password'];
$result = $db->query('name');
foreach($result as $row)
{
  if($row->Password === password)
  {
    echo "login Successful" ;
   }

        }
}

}
?> 

行:

$index=新视图('index')

结尾处缺少“;”。写:

$index=新视图('index')

线路:

name = $post['name'];
password = $post['password'];
变量名称前缺少
$
$post
应该是
$\u post
或者更好,使用Kohana
Arr::get()
(参见biakaveron的答案)

忠告:

而不是编写
defined('SYSPATH')或die('No direct script access')
在每个脚本文件的顶部,配置Apache以从Apache的“范围”中隐藏这些文件,或添加.htaccess以防止直接访问某些目录

public function index()
{
   $db = new Database();
   $index = new View('Index'); // unused var?
   //$db->connect();
   $name = Arr::get($_POST, 'name');
   $password = Arr::get($_POST, 'password');
   if ( ! $name OR !$password)
   {
      die('name and password required!');
   }
   $user = $db->select('*')   // use Query Builder!
           ->from('users')
           ->where('username', $name)
           ->get();
   if ( empty($user))
   {
      die('user '.$user.' not found!');
   }
   $user = current($user);
   if ($user['password'] == $password)
   {
       // correct password
   }
   else
   {
       die('wrong username/password combination!');
   }

}

它适用于Kohana v2.3.4(3.x有另一个控制器和方法名称约定)

它是什么Kohana版本?2.3.4?您遇到了什么错误?Kohana有一个内置系统,建议使用它。